Package org.apache.jackrabbit.rmi.server

Server implementation of the transparent JCR-RMI layer.

See: Description

Package org.apache.jackrabbit.rmi.server Description

Server implementation of the transparent JCR-RMI layer.

This package contains the default server implementation of the transparent JCR-RMI layer. The classes in this package can be used to make a local JCR repository available as an RMI service. In addition, this package offers a straightforward mechanism for extending or modifying the behaviour of the server layer.

The contents of this package is designed using two design patterns, Factory and Adapter. All the remotely accessible ServerObject subclasses implement the Adapter pattern to adapt a local JCR interface to the corresponding remote JCR-RMI interface. The Factory pattern is used to centralize the creation and configuration of all adapter instances.

Setting up a JCR-RMI server

Setting up the server part of the JCR-RMI layer is quite straightforward. After instantiating a local JCR repository you need to wrap it into a remote adapter and create an RMI binding for the repository. A variation of the following code is usually all that is needed in addition to the standard RMI setup (starting rmiregistry, etc.):

    Repository repository = ...; // The local repository
    String name = ...; // The RMI URL for the repository
    
    RemoteAdapterFactory factory = new ServerAdapterFactory();
    RemoteRepository remote = factory.getRemoteRepository(repository);
    Naming.bind(name, remote);  // Make the RMI binding using java.rmi.Naming

Extending the JCR-RMI server

The Factory pattern used by this package makes it easy to extend the behaviour of the JCR-RMI server. Such changes in behaviour or policy can be implemented by modifying or replacing the default ServerAdapterFactory used in the example above.

The following example code adds transparent logging of all session logins and logouts:

    Repository repository = ...; // The local repository
    String name = ...; // The RMI URL for the repository
    
    RemoteAdapterFactory factory = new ServerAdapterFactory() {
        public RemoteSession getRemoteSession(Session session)
                throws RemoteException {
            System.out.println("LOGIN: " + session.getUserId());
            return new ServerSession(session, this) {
                public void logout() {
                    System.out.println("LOGOUT: " + session.getUserId());
                    super.logout();
                }
            };
        }
    };

    RemoteRepository remote = factory.getRemoteRepository(repository);
    Naming.bind(name, remote);  // Make the RMI binding using java.rmi.Naming

Copyright © 2004-2012 The Apache Software Foundation. All Rights Reserved.