use of com.axway.ats.agent.webapp.client.executors.AbstractClientExecutor in project ats-framework by Axway.
the class AgentConfigurationClient method isComponentLoaded.
/**
* Tells if an Agent component is loaded, so its actions can be called.
* This method will wait for the specified timeout period until the wanted condition is met.
*
* @param componentName the name of the component
* @param timeout maximum timeout (in seconds) to wait for the component to be loaded.
* @return whether it is available
*/
@PublicAtsApi
public boolean isComponentLoaded(String componentName, int timeout) throws AgentException {
// construct an action request
ActionRequest actionRequest = new ActionRequest(componentName, "fake action name", new Object[] {});
AbstractClientExecutor executor;
if (atsAgent.equals(LOCAL_JVM)) {
executor = new LocalExecutor();
} else {
executor = new RemoteExecutor(atsAgent, false);
}
long startTimestamp = System.currentTimeMillis();
while (true) {
if (executor.isComponentLoaded(actionRequest)) {
// it is loaded
return true;
} else if (System.currentTimeMillis() - startTimestamp > timeout * 1000) {
// not loaded for the whole timeout
return false;
} else {
// not loaded, but we will check again
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
}
}
Aggregations