Skip Headers

# Client

Previous

Next

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.

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();