Search in sources :

Example 1 with ServerAdapterFactory

use of org.apache.jackrabbit.rmi.server.ServerAdapterFactory in project jackrabbit by apache.

the class RepositoryStubImpl method getRepository.

@Override
public synchronized Repository getRepository() throws RepositoryStubException {
    if (repository == null) {
        try {
            Repository repo = super.getRepository();
            principal = findKnownPrincipal(repo);
            RemoteAdapterFactory raf = new ServerAdapterFactory();
            remote = raf.getRemoteRepository(repo);
            // Make sure that the remote reference survives serialization
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(buffer);
            oos.writeObject(RemoteObject.toStub(remote));
            oos.close();
            ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
            LocalAdapterFactory laf = new ClientAdapterFactory();
            repository = laf.getRepository((RemoteRepository) ois.readObject());
        } catch (Exception e) {
            throw new RepositoryStubException(e);
        }
    }
    return repository;
}
Also used : Repository(javax.jcr.Repository) RemoteRepository(org.apache.jackrabbit.rmi.remote.RemoteRepository) ByteArrayInputStream(java.io.ByteArrayInputStream) RemoteRepository(org.apache.jackrabbit.rmi.remote.RemoteRepository) RepositoryStubException(org.apache.jackrabbit.test.RepositoryStubException) RemoteAdapterFactory(org.apache.jackrabbit.rmi.server.RemoteAdapterFactory) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ClientAdapterFactory(org.apache.jackrabbit.rmi.client.ClientAdapterFactory) ObjectOutputStream(java.io.ObjectOutputStream) LocalAdapterFactory(org.apache.jackrabbit.rmi.client.LocalAdapterFactory) ServerAdapterFactory(org.apache.jackrabbit.rmi.server.ServerAdapterFactory) RepositoryStubException(org.apache.jackrabbit.test.RepositoryStubException) RepositoryException(javax.jcr.RepositoryException) ObjectInputStream(java.io.ObjectInputStream)

Example 2 with ServerAdapterFactory

use of org.apache.jackrabbit.rmi.server.ServerAdapterFactory in project jackrabbit by apache.

the class JCRServer method start.

public void start() throws Exception {
    if (this.localAddress == null) {
        throw new IllegalStateException("local repository address is null");
    }
    if (this.remoteAddress == null) {
        throw new IllegalStateException("remote repository address is null");
    }
    // local repository
    InitialContext localContext = createInitialContext(localEnvironment);
    localRepository = (Repository) localContext.lookup(this.localAddress);
    if (localRepository == null) {
        throw new IllegalArgumentException("local repository not found at " + this.localAddress);
    }
    // remote repository
    InitialContext remoteContext = createInitialContext(remoteEnvironment);
    RemoteAdapterFactory factory = new ServerAdapterFactory();
    remote = factory.getRemoteRepository(localRepository);
    // bind remote server
    remoteContext.bind(this.remoteAddress, remote);
}
Also used : RemoteAdapterFactory(org.apache.jackrabbit.rmi.server.RemoteAdapterFactory) ServerAdapterFactory(org.apache.jackrabbit.rmi.server.ServerAdapterFactory) InitialContext(javax.naming.InitialContext)

Aggregations

RemoteAdapterFactory (org.apache.jackrabbit.rmi.server.RemoteAdapterFactory)2 ServerAdapterFactory (org.apache.jackrabbit.rmi.server.ServerAdapterFactory)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 Repository (javax.jcr.Repository)1 RepositoryException (javax.jcr.RepositoryException)1 InitialContext (javax.naming.InitialContext)1 ClientAdapterFactory (org.apache.jackrabbit.rmi.client.ClientAdapterFactory)1 LocalAdapterFactory (org.apache.jackrabbit.rmi.client.LocalAdapterFactory)1 RemoteRepository (org.apache.jackrabbit.rmi.remote.RemoteRepository)1 RepositoryStubException (org.apache.jackrabbit.test.RepositoryStubException)1