Oracle TopLink Developer's Guide 10g Release 3 (10.1.3) B13593-01 |
|
![]() Previous |
![]() Next |
Remote sessions are acquired through a remote connection to their server-side session. Remote sessions are acquired through Java code on the remote client. The server-side session must also be registered with an oracle.toplink.remote.ejb.RemoteSessionController
and accessible from the RMI naming service.
You create remote sessions entirely in Java code (see "Using Java").
Example 76-7 and Example 76-8 demonstrate how to create a remote TopLink session on a client that communicates with a remote session controller on a server that uses RMI. After creating the connection, the client application uses the remote session as it does with any other TopLink session.
Example 76-7 shows the code you add to your application's RMI service (MyRMIServerManagerImpl
) to create and return an instance of an RMIRemoteSessionController
to the client. The controller sits between the remote client and the local TopLink session.
The RMIRemoteSessionController
you create on the server is based on a TopLink server session. You create and configure this server session as described in "Creating a Server Session" and "Configuring Server Sessions".
Example 76-7 Server Creating RMIRemoteSessionController for Client
RMIRemoteSessionController controller = null; try { // Create instance of RMIRemoteSessionControllerDispatcher which implements // RMIRemoteSessionController. The constructor takes a TopLink session as a parameter controller = new RMIRemoteSessionControllerDispatcher (localTopLinkSession); } catch (RemoteException exception) { System.out.println("Error in invocation " + exception.toString()); } return controller;
The client-side code gets a reference to the application's RMI service (in this example it is called MyRMIServerManager
) and uses this code to get the RMIRemoteSessionController
running on the server. The reference to the session controller is then used to create the RMIConnection
from which it acquires a remote session.
Example 76-8 Client Acquiring RMIRemoteSessionController from Server
MyRMIServerManager serverManager = null; // Set the client security manager try { System.setSecurityManager(new MyRMISecurityManager()); } catch(Exception exception) { System.out.println("Security violation " + exception.toString()); } // Get the remote factory object from the Registry try { serverManager = (MyRMIServerManager) Naming.lookup("SERVER-MANAGER"); } catch (Exception exception) { System.out.println("Lookup failed " + exception.toString()); } // Start RMIRemoteSession on the server and create an RMIConnection RMIConnection rmiConnection = null; try { rmiConnection = new RMIConnection( serverManager.createRemoteSessionController() ); } catch (RemoteException exception) { System.out.println("Error in invocation " + exception.toString()); } // Create a remote session which we can use as a normal TopLink session Session session = rmiConnection.createRemoteSession();