jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1174845 - /jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
Date Fri, 23 Sep 2011 15:44:38 GMT
Author: mduerig
Date: Fri Sep 23 15:44:37 2011
New Revision: 1174845

URL: http://svn.apache.org/viewvc?rev=1174845&view=rev
Log:
Microkernel based Jackrabbit prototype (WIP)
waiting for change polling to terminate may result in deadlocks. Remove unnecessary tight
locking

Modified:
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java?rev=1174845&r1=1174844&r2=1174845&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
Fri Sep 23 15:44:37 2011
@@ -102,7 +102,6 @@ import java.util.Map;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Future;
-import java.util.concurrent.Semaphore;
 
 /**
  * {@code WorkspaceManager}...
@@ -525,7 +524,7 @@ public final class WorkspaceManager impl
     public synchronized void dispose() {
         try {
             if (changeFeed != null) {
-                changeFeed.cancel();
+                changeFeed.shutdown();
             }
             hierarchyManager.dispose();
             if (subscription != null) {
@@ -972,8 +971,7 @@ public final class WorkspaceManager impl
      */
     private final class ChangePolling implements Callable<Object> {
         private final ExecutorService changePollingExecutor;
-        private volatile Future<Object> result;             // Used to cancel change
polling
-        private final Semaphore running = new Semaphore(1); // Used to determine that change
polling terminated
+        private volatile Future<Object> result;
 
         public ChangePolling(ExecutorService changePollingExecutor) {
             this.changePollingExecutor = changePollingExecutor;
@@ -983,56 +981,40 @@ public final class WorkspaceManager impl
 
         @Override
         public Object call() throws Exception {
-            try {
-                if (running.availablePermits() > 0) {
-                    running.acquire();
-                }
-                
-                InternalEventListener[] internalEventListeners;
-                Subscription subscription;
-                synchronized (listeners) {
+            InternalEventListener[] internalEventListeners;
+            Subscription subscription;
+            synchronized (listeners) {
+                subscription = WorkspaceManager.this.subscription;
+                while (subscription == null) {
+                    listeners.wait();
                     subscription = WorkspaceManager.this.subscription;
-                    while (subscription == null) {
-                        listeners.wait();
-                        subscription = WorkspaceManager.this.subscription;
-                    }
-                    internalEventListeners = listeners.toArray(new InternalEventListener[listeners.size()]);
                 }
+                internalEventListeners = listeners.toArray(new InternalEventListener[listeners.size()]);
+            }
 
-                EventBundle[] bundles = null;
-                try {
-                    bundles = service.getEvents(subscription, pollTimeout);
-                } catch (UnsupportedRepositoryOperationException e) {
-                    log.error("SPI implementation does not support observation", e);
-                    running.release();
-                    return null;
-                } catch (RepositoryException e) {
-                    log.error("Workspace=" + sessionInfo.getWorkspaceName() + ": Exception
while retrieving event bundles", e);
-                }
+            EventBundle[] bundles = null;
+            try {
+                bundles = service.getEvents(subscription, pollTimeout);
+            } catch (UnsupportedRepositoryOperationException e) {
+                log.error("SPI implementation does not support observation", e);
+                return null;
+            } catch (RepositoryException e) {
+                log.error("Workspace=" + sessionInfo.getWorkspaceName() + ": Exception while
retrieving event bundles", e);
+            }
 
-                if (!Thread.interrupted() && bundles != null && bundles.length
> 0) {
-                    onEventReceived(bundles, internalEventListeners);
-                }
+            if (!Thread.interrupted() && bundles != null && bundles.length
> 0) {
+                onEventReceived(bundles, internalEventListeners);
+            }
 
-                synchronized (this) {
-                    if (result != null) {
-                        result = changePollingExecutor.submit(this);
-                        return null;
-                    }
-                    else {
-                        // terminate
-                        running.release();
-                        return null;
-                    }
+            synchronized (this) {
+                if (result != null) {
+                    result = changePollingExecutor.submit(this);
                 }
             }
-            catch (InterruptedException e) {
-                running.release();
-                throw e;
-            }
+            return null;
         }
 
-        public void cancel() throws InterruptedException {
+        public void shutdown() {
             Future<Object> result;
             synchronized (this) {
                 result = this.result;
@@ -1041,8 +1023,6 @@ public final class WorkspaceManager impl
 
             if (result != null) {
                 result.cancel(true);
-                running.acquire();  // wait for change polling to terminate
-                running.release();
             }
         }
     }



Mime
View raw message