Hi Jukka,

Thanks alot. 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.

Thanks and Regards
Felix

Jukka Zitting schrieb:

Hi,

Felix Meschberger wrote:

Next try. Hope this now makes it. Sorry for the overhead.


Thanks, committed.

BR,

Jukka Zitting

Index: src/java/org/apache/jackrabbit/rmi/observation/ClientEventPoll.java
===================================================================
--- src/java/org/apache/jackrabbit/rmi/observation/ClientEventPoll.java 
(Revision 191885)
+++ src/java/org/apache/jackrabbit/rmi/observation/ClientEventPoll.java 
(Arbeitskopie)
@@ -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 [EMAIL PROTECTED] RemoteObservationManager} called for the new 
events. */
     private final RemoteObservationManager remote;
-
+    
+    /**
+     * The <code>Session</code> checked by the [EMAIL PROTECTED] #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 [EMAIL PROTECTED] #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 [EMAIL PROTECTED] #terminate()} has not 
been called
-     * yet.
+     * yet and the session is still alive.
      * <li>Call the [EMAIL PROTECTED] 
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);
Index: src/java/org/apache/jackrabbit/rmi/client/ClientAdapterFactory.java
===================================================================
--- src/java/org/apache/jackrabbit/rmi/client/ClientAdapterFactory.java 
(Revision 191885)
+++ src/java/org/apache/jackrabbit/rmi/client/ClientAdapterFactory.java 
(Arbeitskopie)
@@ -105,11 +105,11 @@
      *
      * [EMAIL PROTECTED]
      */
-    public ObservationManager getObservationManager(
+    public ObservationManager getObservationManager(Workspace workspace,
             RemoteObservationManager remote) {
-        return new ClientObservationManager(remote);
+        return new ClientObservationManager(workspace, remote);
     }
-
+    
     /**
      * Creates and returns a
      * [EMAIL PROTECTED] ClientNamespaceRegistry 
ClientClientNamespaceRegistry} instance.
Index: src/java/org/apache/jackrabbit/rmi/client/ClientSession.java
===================================================================
--- src/java/org/apache/jackrabbit/rmi/client/ClientSession.java        
(Revision 191885)
+++ src/java/org/apache/jackrabbit/rmi/client/ClientSession.java        
(Arbeitskopie)
@@ -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 [EMAIL PROTECTED] #logout()} method. The 
[EMAIL PROTECTED] #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 @@
 
     /** [EMAIL PROTECTED] */
     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);
         }
Index: src/java/org/apache/jackrabbit/rmi/client/LocalAdapterFactory.java
===================================================================
--- src/java/org/apache/jackrabbit/rmi/client/LocalAdapterFactory.java  
(Revision 191885)
+++ src/java/org/apache/jackrabbit/rmi/client/LocalAdapterFactory.java  
(Arbeitskopie)
@@ -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
Index: src/java/org/apache/jackrabbit/rmi/client/ClientObservationManager.java
===================================================================
--- src/java/org/apache/jackrabbit/rmi/client/ClientObservationManager.java     
(Revision 191885)
+++ src/java/org/apache/jackrabbit/rmi/client/ClientObservationManager.java     
(Arbeitskopie)
@@ -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 [EMAIL PROTECTED] 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;
     }
 
     /** [EMAIL PROTECTED] */
@@ -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;
Index: src/java/org/apache/jackrabbit/rmi/client/ClientWorkspace.java
===================================================================
--- src/java/org/apache/jackrabbit/rmi/client/ClientWorkspace.java      
(Revision 191885)
+++ src/java/org/apache/jackrabbit/rmi/client/ClientWorkspace.java      
(Arbeitskopie)
@@ -164,7 +164,7 @@
             try {
                 observationManager =
                     getFactory().
-                        getObservationManager(remote.getObservationManager());
+                        getObservationManager(this, 
remote.getObservationManager());
             } catch (RemoteException ex) {
                 throw new RemoteRepositoryException(ex);
             }

Reply via email to