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;
}
}
Aggregations