Search in sources :

Example 1 with NotBoundException

use of org.objectweb.proactive.core.exceptions.NotBoundException in project scheduling by ow2-proactive.

the class Connection method waitAndConnect.

/**
 * Connects to the service with a specified timeout value. A timeout of
 * zero is interpreted as an infinite timeout. The connection will then
 * block until established or an error occurs.
 *
 * @param url the url on which to connect
 * @param timeout the maximum amount of time to wait if it cannot connect
 * @return the authentication if connection succeed
 * @throws Exception if something wrong append
 */
public T waitAndConnect(String url, long timeout) throws Exception {
    T authentication = null;
    long leftTime = timeout == 0 ? Long.MAX_VALUE : timeout;
    try {
        // obtaining authentication active object
        while (leftTime > 0) {
            long startTime = System.currentTimeMillis();
            try {
                authentication = lookupAuthentication(url);
                if (authentication == null) {
                    // simulating an exception during lookup
                    throw new Exception(ERROR_CANNOT_LOOKUP_AUTH);
                }
                // success
                break;
            } catch (NotBoundException e) {
                // expected NotBoundException is not printed in the log
                leftTime = sleepOrThrow(startTime, leftTime, e);
            } catch (IOException e) {
                leftTime = sleepOrThrow(startTime, leftTime, e);
            } catch (Exception e) {
                // unexpected Exception
                logger.error("", e);
                leftTime = sleepOrThrow(startTime, leftTime, e);
            }
        }
        // waiting until scheduling is initialized
        while (leftTime > 0) {
            long startTime = System.currentTimeMillis();
            BooleanWrapper future = authentication.isActivated();
            try {
                PAFuture.waitFor(future, leftTime);
            } catch (ProActiveTimeoutException e) {
                String errorMessage = "The ProActive server can not send a reply to the Node (usually due to a firewall). Please check the server logs for more information.";
                logger.error(errorMessage, e);
                throw new ProActiveRuntimeException(errorMessage, e);
            }
            if (authentication.isActivated().getBooleanValue()) {
                // success
                break;
            } else {
                leftTime = sleepOrThrow(startTime, leftTime, new Exception(ERROR_NOT_ACTIVATED));
            }
        }
    } catch (InterruptedException e) {
        throw new Exception(ERROR_CONNECTION_INTERRUPTED);
    }
    // TODO two cycles has the same pattern => the code can be unified
    return authentication;
}
Also used : ProActiveTimeoutException(org.objectweb.proactive.core.ProActiveTimeoutException) BooleanWrapper(org.objectweb.proactive.core.util.wrapper.BooleanWrapper) NotBoundException(org.objectweb.proactive.core.exceptions.NotBoundException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ProActiveRuntimeException(org.objectweb.proactive.core.ProActiveRuntimeException) UnknownHostException(java.net.UnknownHostException) NotBoundException(org.objectweb.proactive.core.exceptions.NotBoundException) ProActiveTimeoutException(org.objectweb.proactive.core.ProActiveTimeoutException) ProActiveRuntimeException(org.objectweb.proactive.core.ProActiveRuntimeException)

Aggregations

IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1 ProActiveRuntimeException (org.objectweb.proactive.core.ProActiveRuntimeException)1 ProActiveTimeoutException (org.objectweb.proactive.core.ProActiveTimeoutException)1 NotBoundException (org.objectweb.proactive.core.exceptions.NotBoundException)1 BooleanWrapper (org.objectweb.proactive.core.util.wrapper.BooleanWrapper)1