jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r896149 - /jackrabbit/commons/jcr-rmi/trunk/src/test/java/org/apache/jackrabbit/rmi/RepositoryStubImpl.java
Date Tue, 05 Jan 2010 17:50:42 GMT
Author: jukka
Date: Tue Jan  5 17:50:42 2010
New Revision: 896149

URL: http://svn.apache.org/viewvc?rev=896149&view=rev
Log:
JCRRMI-26: JSR-283 support

Keep a reference to the remote object to prevent it from being garbage-collected.

Modified:
    jackrabbit/commons/jcr-rmi/trunk/src/test/java/org/apache/jackrabbit/rmi/RepositoryStubImpl.java

Modified: jackrabbit/commons/jcr-rmi/trunk/src/test/java/org/apache/jackrabbit/rmi/RepositoryStubImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/jcr-rmi/trunk/src/test/java/org/apache/jackrabbit/rmi/RepositoryStubImpl.java?rev=896149&r1=896148&r2=896149&view=diff
==============================================================================
--- jackrabbit/commons/jcr-rmi/trunk/src/test/java/org/apache/jackrabbit/rmi/RepositoryStubImpl.java
(original)
+++ jackrabbit/commons/jcr-rmi/trunk/src/test/java/org/apache/jackrabbit/rmi/RepositoryStubImpl.java
Tue Jan  5 17:50:42 2010
@@ -35,31 +35,38 @@
 
 public class RepositoryStubImpl extends JackrabbitRepositoryStub {
 
+    private RemoteRepository remote;
+
+    private Repository repository;
+
     public RepositoryStubImpl(Properties env) {
         super(env);
     }
 
     @Override
-    public Repository getRepository() throws RepositoryStubException {
-        try {
-            Repository repository = super.getRepository();
-
-            RemoteAdapterFactory raf = new JackrabbitServerAdapterFactory();
-            RemoteRepository remote = raf.getRemoteRepository(repository);
-
-            // 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 JackrabbitClientAdapterFactory();
-            return laf.getRepository((RemoteRepository) ois.readObject());
-        } catch (Exception e) {
-            throw new RepositoryStubException(e.getMessage());
+    public synchronized Repository getRepository()
+            throws RepositoryStubException {
+        if (repository == null) {
+            try {
+                RemoteAdapterFactory raf = new JackrabbitServerAdapterFactory();
+                remote = raf.getRemoteRepository(super.getRepository());
+
+                // 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 JackrabbitClientAdapterFactory();
+                repository =
+                    laf.getRepository((RemoteRepository) ois.readObject());
+            } catch (Exception e) {
+                throw new RepositoryStubException(e.getMessage());
+            }
         }
+        return repository;
     }
 
 }



Mime
View raw message