jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r202500 - in /incubator/jackrabbit/trunk/contrib/jcr-rmi/src: java/org/apache/jackrabbit/rmi/client/ java/org/apache/jackrabbit/rmi/observation/ test/org/apache/jackrabbit/test/rmi/
Date Thu, 30 Jun 2005 07:34:11 GMT
Author: jukka
Date: Thu Jun 30 00:34:09 2005
New Revision: 202500

URL: http://svn.apache.org/viewcvs?rev=202500&view=rev
Log:
JCR-RMI: Patch contributed by Felix Meschberger: "And here we go with another patch :-) It
contains an optimization in the ClientSession, which now contains its own live flag which
is consulted by the isLive() method in addition to the remote session. The second fix concerns
the ClientEventPoller, which continues polling even though the session has already been logged
out. The fix is to check the live status with the session and terminating the poll cycle if
not alive anymore."
Also modified the unit tests accordingly.

Modified:
    incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/client/ClientAdapterFactory.java
    incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/client/ClientObservationManager.java
    incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/client/ClientSession.java
    incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/client/ClientWorkspace.java
    incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/client/LocalAdapterFactory.java
    incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/observation/ClientEventPoll.java
    incubator/jackrabbit/trunk/contrib/jcr-rmi/src/test/org/apache/jackrabbit/test/rmi/RemoteAdapterTest.java

Modified: incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/client/ClientAdapterFactory.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/client/ClientAdapterFactory.java?rev=202500&r1=202499&r2=202500&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/client/ClientAdapterFactory.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/client/ClientAdapterFactory.java
Thu Jun 30 00:34:09 2005
@@ -105,11 +105,11 @@
      *
      * {@inheritDoc}
      */
-    public ObservationManager getObservationManager(
+    public ObservationManager getObservationManager(Workspace workspace,
             RemoteObservationManager remote) {
-        return new ClientObservationManager(remote);
+        return new ClientObservationManager(workspace, remote);
     }
-
+    
     /**
      * Creates and returns a
      * {@link ClientNamespaceRegistry ClientClientNamespaceRegistry} instance.

Modified: incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/client/ClientObservationManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/client/ClientObservationManager.java?rev=202500&r1=202499&r2=202500&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/client/ClientObservationManager.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/client/ClientObservationManager.java
Thu Jun 30 00:34:09 2005
@@ -19,6 +19,7 @@
 import java.rmi.RemoteException;
 
 import javax.jcr.RepositoryException;
+import javax.jcr.Workspace;
 import javax.jcr.observation.EventListener;
 import javax.jcr.observation.EventListenerIterator;
 import javax.jcr.observation.ObservationManager;
@@ -51,7 +52,10 @@
 
     /** The remote observation manager */
     private final RemoteObservationManager remote;
-
+    
+    /** The <code>Workspace</code> to which this observation manager belongs.
*/
+    private final Workspace workspace;
+    
     /** The ClientEventPoll class internally used for event dispatching */
     private ClientEventPoll poller;
 
@@ -61,10 +65,14 @@
      *
      * @param remote The {@link RemoteObservationManager} backing this
      *      client-side observation manager.
+     * @param workspace The <code>Workspace</code> instance to which this
+     *      observation manager belongs.
      */
-    public ClientObservationManager(RemoteObservationManager remote) {
+    public ClientObservationManager(Workspace workspace,
+            RemoteObservationManager remote) {
         super(null);
         this.remote = remote;
+        this.workspace = workspace;
     }
 
     /** {@inheritDoc} */
@@ -108,7 +116,7 @@
      */
     private synchronized ClientEventPoll getClientEventPoll() {
         if (poller == null) {
-            poller = new ClientEventPoll(remote);
+            poller = new ClientEventPoll(remote, workspace.getSession());
             poller.start();
         }
         return poller;

Modified: incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/client/ClientSession.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/client/ClientSession.java?rev=202500&r1=202499&r2=202500&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/client/ClientSession.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/client/ClientSession.java
Thu Jun 30 00:34:09 2005
@@ -62,6 +62,14 @@
     /** The current repository. */
     private Repository repository;
 
+    /**
+     * Flag indicating whether the session is to be considered live of not.
+     * This flag is initially set to <code>true</code> and reset to
+     * <code>false</code> by the {@link #logout()} method. The {@link #isLive()}
+     * method first checks this flag before asking the remote session.
+     */
+    private boolean live = true;
+    
     /** The adapted remote session. */
     private RemoteSession remote;
 
@@ -300,10 +308,19 @@
 
     /** {@inheritDoc} */
     public void logout() {
+        
+        // ignore if we are not alive any more.
+        if (!isLive()) {
+            return;
+        }
+        
         try {
             remote.logout();
         } catch (RemoteException ex) {
             throw new RemoteRuntimeException(ex);
+        } finally {
+            // mark "dead"
+            live = false;
         }
     }
 
@@ -445,7 +462,7 @@
      */
     public boolean isLive() {
         try {
-            return remote.isLive();
+            return live && remote.isLive();
         } catch (RemoteException e) {
             throw new RemoteRuntimeException(e);
         }

Modified: incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/client/ClientWorkspace.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/client/ClientWorkspace.java?rev=202500&r1=202499&r2=202500&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/client/ClientWorkspace.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/client/ClientWorkspace.java
Thu Jun 30 00:34:09 2005
@@ -164,7 +164,7 @@
             try {
                 observationManager =
                     getFactory().
-                        getObservationManager(remote.getObservationManager());
+                        getObservationManager(this, remote.getObservationManager());
             } catch (RemoteException ex) {
                 throw new RemoteRepositoryException(ex);
             }

Modified: incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/client/LocalAdapterFactory.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/client/LocalAdapterFactory.java?rev=202500&r1=202499&r2=202500&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/client/LocalAdapterFactory.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/client/LocalAdapterFactory.java
Thu Jun 30 00:34:09 2005
@@ -109,10 +109,12 @@
      * Factory method for creating a local adapter for a remote observation
      * manager.
      *
+     * @param workspace current workspace
      * @param remote remote observation manager
      * @return local observation manager adapter
      */
-    ObservationManager getObservationManager(RemoteObservationManager remote);
+    ObservationManager getObservationManager(Workspace workspace,
+        RemoteObservationManager remote);
 
     /**
      * Factory method for creating a local adapter for a remote namespace

Modified: incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/observation/ClientEventPoll.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/observation/ClientEventPoll.java?rev=202500&r1=202499&r2=202500&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/observation/ClientEventPoll.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/observation/ClientEventPoll.java
Thu Jun 30 00:34:09 2005
@@ -20,6 +20,7 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.jcr.Session;
 import javax.jcr.observation.Event;
 import javax.jcr.observation.EventIterator;
 import javax.jcr.observation.EventListener;
@@ -70,7 +71,13 @@
 
     /** The {@link RemoteObservationManager} called for the new events. */
     private final RemoteObservationManager remote;
-
+    
+    /**
+     * The <code>Session</code> checked by the {@link #run} method whether it
+     * is still alive or the thread should terminate.
+     */
+    private final Session session;
+    
     /** The map of locally registered listeners indexed by the unique identifier */
     private Map listenerMap = new HashMap();
 
@@ -89,18 +96,25 @@
      *
      * @param remote The remote observation manager which is asked for new
      *      events. This must not be <code>null</code>.
-     *
-     * @throws NullPointerException if <code>remote</code> is <code>null</code>.
+     * @param session The <code>Session</code> which is asked whether it is
+     *      alive by the {@link #run()} method. This must not be <code>null</code>.
+     * 
+     * @throws NullPointerException if <code>remote</code> or <code>session</code>
+     *      is <code>null</code>.
      */
-    public ClientEventPoll(RemoteObservationManager remote)
-            throws NullPointerException {
+    public ClientEventPoll(RemoteObservationManager remote, Session session) {
         super(THREAD_NAME);
-
-        // check remote and assign
+        
+        // check remote and session
         if (remote == null) {
             throw new NullPointerException("remote");
         }
+        if (session == null) {
+            throw new NullPointerException("session");
+        }
+        
         this.remote = remote;
+        this.session = session;
     }
 
     /**
@@ -165,7 +179,7 @@
      * event listeners. This is how this method works:
      * <ol>
      * <li>Continue with next step if {@link #terminate()} has not been called
-     * yet.
+     * yet and the session is still alive.
      * <li>Call the {@link RemoteObservationManager#getNextEvent(long)} method
      * waiting for a specified time (5 seconds).
      * <li>If no event was received in the specified time go back to step #1.
@@ -178,7 +192,7 @@
      * </ol>
      */
     public void run() {
-        while (running) {
+        while (running && session.isLive()) {
             try {
                 // ask for an event waiting at most POLL_TIMEOUT milliseconds
                 RemoteEventCollection remoteEvent = remote.getNextEvent(POLL_TIMEOUT);

Modified: incubator/jackrabbit/trunk/contrib/jcr-rmi/src/test/org/apache/jackrabbit/test/rmi/RemoteAdapterTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-rmi/src/test/org/apache/jackrabbit/test/rmi/RemoteAdapterTest.java?rev=202500&r1=202499&r2=202500&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-rmi/src/test/org/apache/jackrabbit/test/rmi/RemoteAdapterTest.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-rmi/src/test/org/apache/jackrabbit/test/rmi/RemoteAdapterTest.java
Thu Jun 30 00:34:09 2005
@@ -218,6 +218,8 @@
         ignoreMethod("exportSystemView");        // multiple methods
         ignoreMethod("exportDocumentView");      // multiple method
         ignoreMethod("getValueFactory");         // implemented locally
+        ignoreMethod("logout");                  // local live flag
+        ignoreMethod("isLive");                  // local live flag
 
         Session session = (Session) mock;
         RemoteSession remote = remoteFactory.getRemoteSession(session);



Mime
View raw message