Apache Jackrabbit : HowtoSpi2Rmi

Context

The image below is a good picture of where spi2rmi fits in. It was taken from the jackrabbit-spi link below.

http://jackrabbit.apache.org/jackrabbit-spi.data/jackrabbit-spi-overview.gif

I could not find much documentation on getting it setup.
Here is what I've found so far:

Notes from Angela

the spi-rmi is currently still in the sandbox, since we didn't spent time on optimization yet.

if you are looking for an example setup, you may start with the 'getRepository()' method defined with http://svn.apache.org/repos/asf/jackrabbit/sandbox/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/JCR2SPI2JCROverRMIRepositoryStub.java

the jcr2spi code can be found at http://svn.apache.org/repos/asf/jackrabbit/trunk/jackrabbit-jcr2spi

the rmi-spi code http://svn.apache.org/repos/asf/jackrabbit/sandbox/spi/spi-rmi

the spi2jcr code http://svn.apache.org/repos/asf/jackrabbit/trunk/jackrabbit-spi2jcr

minimal intro as follows:

  • jcr2spi-Repository takes a RepositoryConfig
  • the most important part of the configuration is the RepositoryService
  • RepositoryService is the main interface defined by the SPI.

running the setup you mention, you need to create a RepositoryConfig
that returns the ClientRepositoryService of spi-rmi which itself was created with a remote RepositoryService wrapping whatever spi implementation.

Known Issues

You might have to deal with this issue: https://issues.apache.org/jira/browse/JCR-1653

If you use the patch there you have to make sure it is applied to the code running on the server and on the client.

Setup a spi server

Use the SPIServer class in jackrabbit-test-client

The only code I could find which setups up an SPI server was in the spi-contrib testing project: https://svn.apache.org/repos/asf/jackrabbit/sandbox/spi/client (even though the folder name is "client" the maven artifactId is jackrabbit-test-client

This project has a class org.apache.jackrabbit.jcr2spi.SPIServer which starts up the SPI RMI Server

Use patch on jackrabbit-webapp

Another option is to try using this patch: jackrabbit-webapp-SPIServer-1.patch It should be applied to the jackrabbit-webapp project. It adds a SPIServerStartServlet, which adds the
ServerRepositoryService to the webapps RMI registry. It should wrap the existing repository started up by the webapp normally. You have to add a reference to your WEB-INF/web.xml:

    <servlet>
        <servlet-name>SPIServerStartup</servlet-name>
        <description>
            Starts up an SPI RMI server.   
        </description>
        <servlet-class>org.apache.jackrabbit.j2ee.SPIServerStartupServlet</servlet-class>
        <load-on-startup>6</load-on-startup>
    </servlet>

It doesn't pay attention to all the config options used by the rest of webapp so you might have to tweak it.

I haven't submitted an issue with this patch because jackrabbit-webapp should be not be depending on the jars that SPI Server requires. One way to get around this is to make another project inside of sandbox/spi that depends on jackrabbit-webapp and creates this servlet. Then people can copy it and its deps into the webapp.

Setup a spi rmi client

This code was duplicated from org.apache.jackrabbit.jcr2spi.JCR2SPIOverRMIRepositoryStub which is located in https://svn.apache.org/repos/asf/jackrabbit/sandbox/spi/client (jackrabbit-test-client) That code uses a AbstractRepositoryConfig instead which is defined in jackrabbit-test-client. This code fully implements RepositoryConfig so it doesn't need to depend on jackrabbit-test-client.

Registry registry = LocateRegistry.getRegistry("localhost", Registry.REGISTRY_PORT);
RemoteRepositoryService remoteRepoService =
  (RemoteRepositoryService) registry.lookup("jackrabbit.spi-server");
			
final RepositoryService localRepoService = new ClientRepositoryService(remoteRepoService);

Repository repo = RepositoryImpl.create(new RepositoryConfig(){
  public RepositoryService getRepositoryService() {
    return localRepoService;
  }

  public String getDefaultWorkspaceName() {
    return null;
  }

  public CacheBehaviour getCacheBehaviour() {
    return CacheBehaviour.INVALIDATE;
  }
            	
});

Attachments: