Search in sources :

Example 6 with ProActiveException

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

the class ROServerImpl method close.

/**
 * Closes this server.
 *
 * @throws IOException if the close operation failed
 */
public synchronized void close() throws IOException {
    // First close the server
    IOException serverException = null;
    try {
        this.internalCloseRemoteObject(this.roe);
    } catch (ProActiveException e) {
        serverException = JMXProviderUtils.newIOException("Unable to close the server " + this.roe.getURL(), e);
    }
    // Even if the server was not closed properly
    // try to close all the connections
    IOException connectionCloseException = null;
    for (final Entry<String, WeakReference<RemoteObjectExposer<ROConnection>>> entry : this.connections.entrySet()) {
        String connectionId = entry.getKey();
        WeakReference<RemoteObjectExposer<ROConnection>> weakReference = entry.getValue();
        RemoteObjectExposer<ROConnection> roe = weakReference.get();
        if (roe == null) {
            this.connections.remove(connectionId);
        } else {
            try {
                this.internalCloseRemoteObject(roe);
            } catch (ProActiveException e) {
                if (connectionCloseException == null) {
                    connectionCloseException = JMXProviderUtils.newIOException("Unable to close the connection " + connectionId, e);
                }
            }
        }
    }
    // were closed (at least attempted)
    if (serverException != null) {
        throw serverException;
    }
    // If there was an exception when closing the connections re-throw it now (the first one)
    if (connectionCloseException != null) {
        throw connectionCloseException;
    }
}
Also used : WeakReference(java.lang.ref.WeakReference) RemoteObjectExposer(org.objectweb.proactive.core.remoteobject.RemoteObjectExposer) IOException(java.io.IOException) ProActiveException(org.objectweb.proactive.core.ProActiveException)

Aggregations

ProActiveException (org.objectweb.proactive.core.ProActiveException)6 IOException (java.io.IOException)3 URI (java.net.URI)2 Throwables.getStackTraceAsString (com.google.common.base.Throwables.getStackTraceAsString)1 File (java.io.File)1 WeakReference (java.lang.ref.WeakReference)1 MalformedURLException (java.net.MalformedURLException)1 SocketException (java.net.SocketException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 UnknownHostException (java.net.UnknownHostException)1 AlreadyBoundException (java.rmi.AlreadyBoundException)1 KeyException (java.security.KeyException)1 MBeanServer (javax.management.MBeanServer)1 LoginException (javax.security.auth.login.LoginException)1 ParseException (org.apache.commons.cli.ParseException)1 ActiveObjectCreationException (org.objectweb.proactive.ActiveObjectCreationException)1 ProActiveRuntimeException (org.objectweb.proactive.core.ProActiveRuntimeException)1 StubObject (org.objectweb.proactive.core.mop.StubObject)1 NodeException (org.objectweb.proactive.core.node.NodeException)1