Search in sources :

Example 1 with AbstractClientExecutor

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) {
            }
        }
    }
}
Also used : ActionRequest(com.axway.ats.agent.core.action.ActionRequest) RemoteExecutor(com.axway.ats.agent.webapp.client.executors.RemoteExecutor) AbstractClientExecutor(com.axway.ats.agent.webapp.client.executors.AbstractClientExecutor) LocalExecutor(com.axway.ats.agent.webapp.client.executors.LocalExecutor) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Aggregations

ActionRequest (com.axway.ats.agent.core.action.ActionRequest)1 AbstractClientExecutor (com.axway.ats.agent.webapp.client.executors.AbstractClientExecutor)1 LocalExecutor (com.axway.ats.agent.webapp.client.executors.LocalExecutor)1 RemoteExecutor (com.axway.ats.agent.webapp.client.executors.RemoteExecutor)1 PublicAtsApi (com.axway.ats.common.PublicAtsApi)1