use of org.eclipse.persistence.sessions.remote.rmi.RMIServerSessionManagerDispatcher in project eclipselink by eclipse-ee4j.
the class EntityManagerSetupImpl method updateRemote.
/**
* Checks for partitioning properties.
*/
protected void updateRemote(Map m, ClassLoader loader) {
String protocol = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.REMOTE_PROTOCOL, m, this.session);
String serverName = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.REMOTE_SERVER_NAME, m, this.session);
if (serverName == null) {
// Configure as client.
if (protocol != null) {
RemoteConnection connection = null;
if (protocol.equalsIgnoreCase(RemoteProtocol.RMI)) {
String url = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.REMOTE_URL, m, this.session);
if (url == null) {
throw EntityManagerSetupException.missingProperty(PersistenceUnitProperties.REMOTE_URL);
}
try {
connection = new RMIConnection(((RMIServerSessionManager) Naming.lookup(url)).createRemoteSessionController());
} catch (Exception exception) {
throw ValidationException.invalidValueForProperty(url, PersistenceUnitProperties.REMOTE_URL, exception);
}
} else {
try {
Class<? extends RemoteConnection> cls = findClassForProperty(protocol, PersistenceUnitProperties.REMOTE_PROTOCOL, loader);
Constructor<? extends RemoteConnection> constructor = cls.getConstructor();
connection = constructor.newInstance();
} catch (Exception exception) {
throw ValidationException.invalidValueForProperty(protocol, PersistenceUnitProperties.REMOTE_PROTOCOL, exception);
}
}
RemoteSession remoteSession = new RemoteSession();
remoteSession.setIsMetadataRemote(false);
remoteSession.setProject(this.session.getProject());
remoteSession.setProfiler(this.session.getProfiler());
remoteSession.setSessionLog(this.session.getSessionLog());
remoteSession.setEventManager(this.session.getEventManager());
remoteSession.setQueries(this.session.getQueries());
remoteSession.setProperties(this.session.getProperties());
remoteSession.setName(this.session.getName());
remoteSession.setRemoteConnection(connection);
this.session = remoteSession;
}
} else {
// Configure as server.
if (protocol.equalsIgnoreCase(RemoteProtocol.RMI)) {
RMIServerSessionManager manager = null;
// Make sure RMI registry is started.
try {
java.rmi.registry.LocateRegistry.createRegistry(1099);
} catch (Exception exception) {
System.out.println("Security violation " + exception.toString());
}
// Create local instance of the factory
try {
manager = new RMIServerSessionManagerDispatcher(session);
} catch (RemoteException exception) {
throw ValidationException.invalidValueForProperty(serverName, PersistenceUnitProperties.REMOTE_SERVER_NAME, exception);
}
// Put the local instance into the Registry
try {
Naming.unbind(serverName);
} catch (Exception exception) {
// Ignore.
}
// Put the local instance into the Registry
try {
Naming.rebind(serverName, manager);
} catch (Exception exception) {
throw ValidationException.invalidValueForProperty(serverName, PersistenceUnitProperties.REMOTE_SERVER_NAME, exception);
}
}
}
}
Aggregations