use of org.objectweb.proactive.core.remoteobject.RemoteObjectExposer in project scheduling by ow2-proactive.
the class ROServerImpl method newClient.
/**
* Returns a new ROConnection.
*
* @return a RO Connection that will enables remote calls onto the remote
* MBean Server
*/
public synchronized ROConnection newClient(final Object credentials) throws IOException {
if (this.mbeanServer == null) {
throw new IllegalStateException("Not attached to an MBean server");
}
// Authenticate to get the subject
Subject subject = null;
final JMXAuthenticator authenticator = (JMXAuthenticator) this.env.get(JMXConnectorServer.AUTHENTICATOR);
if (authenticator != null) {
try {
subject = authenticator.authenticate(credentials);
} catch (SecurityException e) {
LOGGER.warn("Authentication failed", e);
throw e;
}
}
final int num = ++ROServerImpl.connectionNumber;
// Create the id of the connection
final String connectionId = ROServerImpl.createConnectionID(subject, num);
try {
final ROConnection connection = new ROConnection(this.mbeanServer, connectionId, this, subject, this.context);
// Create a remote object exposer for this object
final RemoteObjectExposer<ROConnection> roe = new RemoteObjectExposer<>(ROConnection.class.getName(), connection);
// Use a weak reference and put it in the hash map
this.connections.put(connectionId, new WeakReference<>(roe));
// Get the default base uri for all remote objects
final URI baseURI = JMXProviderUtils.getBaseURI();
// Generate the uri (default base uri + class simple name + connection number)
final URI uri = URIBuilder.buildURI(baseURI, ROConnection.class.getSimpleName() + num);
// Bind under the correct uri
return PARemoteObject.bind(roe, uri);
} catch (Exception e) {
final String message = "Unable to create the client connection " + connectionId;
LOGGER.error(message, e);
throw JMXProviderUtils.newIOException(message, e);
}
}
use of org.objectweb.proactive.core.remoteobject.RemoteObjectExposer 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