jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r512987 - /jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
Date Wed, 28 Feb 2007 21:34:45 GMT
Author: mreutegg
Date: Wed Feb 28 13:34:44 2007
New Revision: 512987

URL: http://svn.apache.org/viewvc?view=rev&rev=512987
Log:
Polling thread should only get events if there are listeners.

Modified:
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java?view=diff&rev=512987&r1=512986&r2=512987
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
Wed Feb 28 13:34:44 2007
@@ -109,7 +109,6 @@
 import java.util.Set;
 import java.util.HashSet;
 import java.util.Map;
-import java.util.Collections;
 import java.io.InputStream;
 
 import EDU.oswego.cs.dl.util.concurrent.Sync;
@@ -149,7 +148,7 @@
      * List of event listener that are set on this WorkspaceManager to get
      * notifications about local and external changes.
      */
-    private final Set listeners = Collections.synchronizedSet(new HashSet());
+    private final Set listeners = new HashSet();
 
     public WorkspaceManager(RepositoryService service, SessionInfo sessionInfo,
                             CacheBehaviour cacheBehaviour, int pollTimeout)
@@ -287,7 +286,10 @@
      * @param listener the new listener.
      */
     public void addEventListener(InternalEventListener listener) {
-        listeners.add(listener);
+        synchronized (listeners) {
+            listeners.add(listener);
+            listeners.notify();
+        }
     }
 
     /**
@@ -295,7 +297,9 @@
      * @param listener
      */
     public void removeEventListener(InternalEventListener listener) {
-        listeners.remove(listener);
+        synchronized (listeners) {
+            listeners.remove(listener);
+        }
     }
 
     /**
@@ -627,7 +631,10 @@
         }
         try {
             // notify listener
-            InternalEventListener[] lstnrs = (InternalEventListener[]) listeners.toArray(new
InternalEventListener[listeners.size()]);
+            InternalEventListener[] lstnrs;
+            synchronized (listeners) {
+                lstnrs = (InternalEventListener[]) listeners.toArray(new InternalEventListener[listeners.size()]);
+            }
             for (int i = 0; i < eventBundles.length; i++) {
                 for (int j = 0; j < lstnrs.length; j++) {
                     lstnrs[j].onEvent(eventBundles[i]);
@@ -987,7 +994,13 @@
                 try {
                     // get filters from listeners
                     List filters = new ArrayList();
-                    InternalEventListener[] iel = (InternalEventListener[]) listeners.toArray(new
InternalEventListener[0]);
+                    InternalEventListener[] iel;
+                    synchronized (listeners) {
+                        while (listeners.isEmpty()) {
+                            listeners.wait();
+                        }
+                        iel = (InternalEventListener[]) listeners.toArray(new InternalEventListener[0]);
+                    }
                     for (int i = 0; i < iel.length; i++) {
                         filters.addAll(iel[i].getEventFilters());
                     }



Mime
View raw message