jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1368425 - in /jackrabbit/oak/trunk: oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/osgi/ oak-jcr/src/main/java/org/a...
Date Thu, 02 Aug 2012 11:46:37 GMT
Author: jukka
Date: Thu Aug  2 11:46:37 2012
New Revision: 1368425

URL: http://svn.apache.org/viewvc?rev=1368425&view=rev
Log:
OAK-144: Implement observation

Use a thread pool for executing background tasks.
This solves a problem with the Timer canceling itself if a listener was added and removed
before any other listeners.

Removed:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/LazyValue.java
Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessor.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ObservationManagerImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/osgi/Activator.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/AbstractRepositoryTest.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/OakRepositoryStub.java
    jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java
    jackrabbit/oak/trunk/oak-sling/src/main/java/org/apache/jackrabbit/oak/sling/Activator.java
    jackrabbit/oak/trunk/oak-sling/src/main/java/org/apache/jackrabbit/oak/sling/SlingRepositoryImpl.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java?rev=1368425&r1=1368424&r2=1368425&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java
Thu Aug  2 11:46:37 2012
@@ -16,7 +16,10 @@
  */
 package org.apache.jackrabbit.oak.jcr;
 
-import java.util.Timer;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
 
 import javax.jcr.Credentials;
 import javax.jcr.Repository;
@@ -29,7 +32,6 @@ import org.apache.jackrabbit.commons.Sim
 import org.apache.jackrabbit.oak.api.ContentRepository;
 import org.apache.jackrabbit.oak.api.ContentSession;
 import org.apache.jackrabbit.oak.core.ContentRepositoryImpl;
-import org.apache.jackrabbit.oak.jcr.util.LazyValue;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -46,23 +48,24 @@ public class RepositoryImpl implements R
     private final Descriptors descriptors = new Descriptors(new SimpleValueFactory());
     private final ContentRepository contentRepository;
 
-    private final LazyValue<Timer> observationTimer = new LazyValue<Timer>()
{
-        @Override
-        protected Timer create() {
-            return new Timer("Observation", true);
-        }
-    };
+    private final ScheduledExecutorService executor;
 
-    public RepositoryImpl(ContentRepository contentRepository) {
+    public RepositoryImpl(
+            ContentRepository contentRepository,
+            ScheduledExecutorService executor) {
         this.contentRepository = contentRepository;
+        this.executor = executor;
     }
 
     /**
      * Utility constructor that creates a new in-memory repository for use
-     * mostly in test cases.
+     * mostly in test cases. The executor service is initialized with an
+     * empty thread pool, so things like observation won't work by default.
+     * Use the other constructor with a properly managed executor service
+     * if such features are needed.
      */
     public RepositoryImpl() {
-        this(new ContentRepositoryImpl());
+        this(new ContentRepositoryImpl(), Executors.newScheduledThreadPool(0));
     }
 
     //---------------------------------------------------------< Repository >---
@@ -131,7 +134,7 @@ public class RepositoryImpl implements R
         // TODO: needs complete refactoring
         try {
             ContentSession contentSession = contentRepository.login(credentials, workspaceName);
-            return new SessionDelegate(this, observationTimer, contentSession, false).getSession();
+            return new SessionDelegate(this, executor, contentSession, false).getSession();
         } catch (LoginException e) {
             throw new javax.jcr.LoginException(e.getMessage());
         }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java?rev=1368425&r1=1368424&r2=1368425&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
Thu Aug  2 11:46:37 2012
@@ -20,7 +20,8 @@ import java.io.IOException;
 import java.text.ParseException;
 import java.util.Collections;
 import java.util.Map;
-import java.util.Timer;
+import java.util.concurrent.ScheduledExecutorService;
+
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.jcr.ItemExistsException;
@@ -51,7 +52,6 @@ import org.apache.jackrabbit.oak.api.Tre
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.core.DefaultConflictHandler;
 import org.apache.jackrabbit.oak.jcr.observation.ObservationManagerImpl;
-import org.apache.jackrabbit.oak.jcr.util.LazyValue;
 import org.apache.jackrabbit.oak.jcr.value.ValueFactoryImpl;
 import org.apache.jackrabbit.oak.namepath.AbstractNameMapper;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
@@ -65,7 +65,7 @@ public class SessionDelegate {
 
     private final NamePathMapper namePathMapper = new NamePathMapperImpl(new SessionNameMapper());
     private final Repository repository;
-    private final LazyValue<Timer> observationTimer;
+    private final ScheduledExecutorService executor;
     private final ContentSession contentSession;
     private final ValueFactoryImpl valueFactory;
     private final Workspace workspace;
@@ -78,13 +78,15 @@ public class SessionDelegate {
     private boolean isAlive = true;
     private int sessionOpCount;
 
-    SessionDelegate(Repository repository, LazyValue<Timer> observationTimer, ContentSession
contentSession,
-            boolean autoRefresh) throws RepositoryException {
+    SessionDelegate(
+            Repository repository, ScheduledExecutorService executor,
+            ContentSession contentSession, boolean autoRefresh)
+            throws RepositoryException {
         assert repository != null;
         assert contentSession != null;
 
         this.repository = repository;
-        this.observationTimer = observationTimer;
+        this.executor = executor;
         this.contentSession = contentSession;
         this.valueFactory = new ValueFactoryImpl(contentSession.getCoreValueFactory(), namePathMapper);
         this.workspace = new WorkspaceImpl(this);
@@ -431,7 +433,7 @@ public class SessionDelegate {
     @Nonnull
     public ObservationManager getObservationManager() {
         if (observationManager == null) {
-            observationManager = new ObservationManagerImpl(this, observationTimer);
+            observationManager = new ObservationManagerImpl(this, executor);
         }
         return observationManager;
     }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessor.java?rev=1368425&r1=1368424&r2=1368425&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessor.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessor.java
Thu Aug  2 11:46:37 2012
@@ -19,14 +19,11 @@ package org.apache.jackrabbit.oak.jcr.ob
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
-import java.util.TimerTask;
 import java.util.concurrent.atomic.AtomicReference;
 
 import javax.jcr.observation.Event;
 import javax.jcr.observation.EventListener;
 
-import com.google.common.base.Function;
-import com.google.common.collect.Iterators;
 import org.apache.jackrabbit.commons.iterator.EventIteratorAdapter;
 import org.apache.jackrabbit.oak.api.ChangeExtractor;
 import org.apache.jackrabbit.oak.api.PropertyState;
@@ -37,15 +34,17 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.apache.jackrabbit.oak.spi.state.NodeStateDiff;
 import org.apache.jackrabbit.oak.spi.state.NodeStateUtils;
 
-class ChangeProcessor extends TimerTask {
+import com.google.common.base.Function;
+import com.google.common.collect.Iterators;
+
+class ChangeProcessor implements Runnable {
+
     private final ObservationManagerImpl observationManager;
     private final NamePathMapper namePathMapper;
     private final ChangeExtractor changeExtractor;
     private final EventListener listener;
     private final AtomicReference<ChangeFilter> filterRef;
 
-    private volatile boolean stopped;
-
     public ChangeProcessor(ObservationManagerImpl observationManager, EventListener listener,
ChangeFilter filter) {
         this.observationManager = observationManager;
         this.namePathMapper = observationManager.getNamePathMapper();
@@ -58,11 +57,6 @@ class ChangeProcessor extends TimerTask 
         filterRef.set(filter);
     }
 
-    public void stop() {
-        cancel();
-        stopped = true;
-    }
-
     @Override
     public void run() {
         EventGeneratingNodeStateDiff diff = new EventGeneratingNodeStateDiff();
@@ -106,7 +100,7 @@ class ChangeProcessor extends TimerTask 
 
         @Override
         public void propertyAdded(PropertyState after) {
-            if (!stopped && filterRef.get().include(Event.PROPERTY_ADDED, jcrPath(),
associatedParentNode)) {
+            if (filterRef.get().include(Event.PROPERTY_ADDED, jcrPath(), associatedParentNode))
{
                 Event event = generatePropertyEvent(Event.PROPERTY_ADDED, path, after);
                 events.add(Iterators.singletonIterator(event));
             }
@@ -114,7 +108,7 @@ class ChangeProcessor extends TimerTask 
 
         @Override
         public void propertyChanged(PropertyState before, PropertyState after) {
-            if (!stopped && filterRef.get().include(Event.PROPERTY_CHANGED, jcrPath(),
associatedParentNode)) {
+            if (filterRef.get().include(Event.PROPERTY_CHANGED, jcrPath(), associatedParentNode))
{
                 Event event = generatePropertyEvent(Event.PROPERTY_CHANGED, path, after);
                 events.add(Iterators.singletonIterator(event));
             }
@@ -122,7 +116,7 @@ class ChangeProcessor extends TimerTask 
 
         @Override
         public void propertyDeleted(PropertyState before) {
-            if (!stopped && filterRef.get().include(Event.PROPERTY_REMOVED, jcrPath(),
associatedParentNode)) {
+            if (filterRef.get().include(Event.PROPERTY_REMOVED, jcrPath(), associatedParentNode))
{
                 Event event = generatePropertyEvent(Event.PROPERTY_REMOVED, path, before);
                 events.add(Iterators.singletonIterator(event));
             }
@@ -133,7 +127,7 @@ class ChangeProcessor extends TimerTask 
             if (NodeStateUtils.isHidden(name)) {
                 return;
             }
-            if (!stopped && filterRef.get().includeChildren(jcrPath())) {
+            if (filterRef.get().includeChildren(jcrPath())) {
                 Iterator<Event> events = generateNodeEvents(Event.NODE_ADDED, path,
name, after);
                 this.events.add(events);
                 if (++childNodeCount > PURGE_LIMIT) {
@@ -147,7 +141,7 @@ class ChangeProcessor extends TimerTask 
             if (NodeStateUtils.isHidden(name)) {
                 return;
             }
-            if (!stopped && filterRef.get().includeChildren(jcrPath())) {
+            if (filterRef.get().includeChildren(jcrPath())) {
                 Iterator<Event> events = generateNodeEvents(Event.NODE_REMOVED, path,
name, before);
                 this.events.add(events);
             }
@@ -158,7 +152,7 @@ class ChangeProcessor extends TimerTask 
             if (NodeStateUtils.isHidden(name)) {
                 return;
             }
-            if (!stopped && filterRef.get().includeChildren(jcrPath())) {
+            if (filterRef.get().includeChildren(jcrPath())) {
                 EventGeneratingNodeStateDiff diff = new EventGeneratingNodeStateDiff(
                         PathUtils.concat(path, name), events, after);
                 after.compareAgainstBaseState(before, diff);
@@ -208,7 +202,7 @@ class ChangeProcessor extends TimerTask 
                 propertyEvents = Iterators.emptyIterator();
             }
 
-            Iterator<Event> childNodeEvents = !stopped && filter.includeChildren(jcrPath)
+            Iterator<Event> childNodeEvents = filter.includeChildren(jcrPath)
                     ? Iterators.concat(generateChildEvents(eventType, path, node))
                     : Iterators.<Event>emptyIterator();
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ObservationManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ObservationManagerImpl.java?rev=1368425&r1=1368424&r2=1368425&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ObservationManagerImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ObservationManagerImpl.java
Thu Aug  2 11:46:37 2012
@@ -18,7 +18,9 @@ package org.apache.jackrabbit.oak.jcr.ob
 
 import java.util.HashMap;
 import java.util.Map;
-import java.util.Timer;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.jcr.RepositoryException;
@@ -31,25 +33,38 @@ import javax.jcr.observation.Observation
 import org.apache.jackrabbit.commons.iterator.EventListenerIteratorAdapter;
 import org.apache.jackrabbit.oak.api.ChangeExtractor;
 import org.apache.jackrabbit.oak.jcr.SessionDelegate;
-import org.apache.jackrabbit.oak.jcr.util.LazyValue;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 
 public class ObservationManagerImpl implements ObservationManager {
+
     private final SessionDelegate sessionDelegate;
+
+    private final ScheduledExecutorService executor;
+
+    private ScheduledFuture<?> future = null;
+
     private final Map<EventListener, ChangeProcessor> processors =
             new HashMap<EventListener, ChangeProcessor>();
 
-    private final LazyValue<Timer> timer;
     private final AtomicBoolean hasEvents = new AtomicBoolean(false);
 
-    public ObservationManagerImpl(SessionDelegate sessionDelegate, LazyValue<Timer>
timer) {
+    public ObservationManagerImpl(
+            SessionDelegate sessionDelegate,
+            ScheduledExecutorService executor) {
         this.sessionDelegate = sessionDelegate;
-        this.timer = timer;
+        this.executor = executor;
     }
 
-    public void dispose() {
+    private synchronized void sendEvents() {
         for (ChangeProcessor processor : processors.values()) {
-            processor.stop();
+            processor.run();
+        }
+    }
+
+    public synchronized void dispose() {
+        if (future != null) {
+            future.cancel(false);
+            future = null;
         }
     }
 
@@ -63,28 +78,37 @@ public class ObservationManagerImpl impl
     }
 
     @Override
-    public void addEventListener(EventListener listener, int eventTypes, String absPath,
-            boolean isDeep, String[] uuid, String[] nodeTypeName, boolean noLocal)
-            throws RepositoryException {
+    public synchronized void addEventListener(
+            EventListener listener, int eventTypes, String absPath,
+            boolean isDeep, String[] uuid, String[] nodeTypeName,
+            boolean noLocal) throws RepositoryException {
+        if (future == null) {
+            future = executor.scheduleWithFixedDelay(new Runnable() {
+                @Override
+                public void run() {
+                    sendEvents();
+                }
+            }, 100, 1000, TimeUnit.MILLISECONDS);
+        }
 
+        ChangeFilter filter = new ChangeFilter(
+                eventTypes, absPath, isDeep, uuid, nodeTypeName, noLocal);
         ChangeProcessor processor = processors.get(listener);
         if (processor == null) {
-            ChangeFilter filter = new ChangeFilter(eventTypes, absPath, isDeep, uuid, nodeTypeName,
noLocal);
-            ChangeProcessor changeProcessor = new ChangeProcessor(this, listener, filter);
-            processors.put(listener, changeProcessor);
-            timer.get().schedule(changeProcessor, 100, 1000);
-        }
-        else {
-            ChangeFilter filter = new ChangeFilter(eventTypes, absPath, isDeep, uuid, nodeTypeName,
noLocal);
+            processor = new ChangeProcessor(this, listener, filter);
+            processors.put(listener, processor);
+        } else {
             processor.setFilter(filter);
         }
     }
 
     @Override
-    public void removeEventListener(EventListener listener) throws RepositoryException {
-        ChangeProcessor processor = processors.remove(listener);
-        if (processor != null) {
-            processor.stop();
+    public synchronized void removeEventListener(EventListener listener) {
+        processors.remove(listener);
+
+        if (processors.isEmpty()) {
+            future.cancel(false);
+            future = null;
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/osgi/Activator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/osgi/Activator.java?rev=1368425&r1=1368424&r2=1368425&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/osgi/Activator.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/osgi/Activator.java
Thu Aug  2 11:46:37 2012
@@ -19,6 +19,8 @@ package org.apache.jackrabbit.oak.jcr.os
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
 
 import javax.jcr.Repository;
 
@@ -35,6 +37,8 @@ public class Activator implements Bundle
 
     private BundleContext context;
 
+    private ScheduledExecutorService executor;
+
     private ServiceTracker tracker;
 
     private final Map<ServiceReference, ServiceRegistration> services =
@@ -45,6 +49,7 @@ public class Activator implements Bundle
     @Override
     public void start(BundleContext bundleContext) throws Exception {
         context = bundleContext;
+        executor = Executors.newScheduledThreadPool(1);
         tracker = new ServiceTracker(
                 context, ContentRepository.class.getName(), this);
         tracker.open();
@@ -52,7 +57,8 @@ public class Activator implements Bundle
 
     @Override
     public void stop(BundleContext bundleContext) throws Exception {
-        tracker.open();
+        tracker.close();
+        executor.shutdown();
     }
 
     //--------------------------------------------< ServiceTrackerCustomizer >--
@@ -64,7 +70,7 @@ public class Activator implements Bundle
             ContentRepository repository = (ContentRepository) service;
             services.put(reference, context.registerService(
                     Repository.class.getName(),
-                    new RepositoryImpl(repository),
+                    new RepositoryImpl(repository, executor),
                     new Properties()));
             return service;
         } else {

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/AbstractRepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/AbstractRepositoryTest.java?rev=1368425&r1=1368424&r2=1368425&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/AbstractRepositoryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/AbstractRepositoryTest.java
Thu Aug  2 11:46:37 2012
@@ -16,6 +16,10 @@
  */
 package org.apache.jackrabbit.oak.jcr;
 
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+
+import org.apache.jackrabbit.oak.core.ContentRepositoryImpl;
 import org.junit.After;
 
 import javax.jcr.GuestCredentials;
@@ -33,6 +37,9 @@ import javax.jcr.Session;
  * this instance and clean up the repository when done.
  */
 public abstract class AbstractRepositoryTest {
+
+    private ScheduledExecutorService executor = null;
+
     private Repository repository = null;
     private Session session = null;
 
@@ -45,11 +52,18 @@ public abstract class AbstractRepository
         }
         // release repository field
         repository = null;
+
+        if (executor != null) {
+            executor.shutdown();
+            executor = null;
+        }
     }
 
     protected Repository getRepository() throws RepositoryException {
         if (repository == null) {
-            repository = new RepositoryImpl();
+            executor = Executors.newScheduledThreadPool(1);
+            repository =
+                    new RepositoryImpl(new ContentRepositoryImpl(), executor);
         }
         return repository;
     }

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/OakRepositoryStub.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/OakRepositoryStub.java?rev=1368425&r1=1368424&r2=1368425&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/OakRepositoryStub.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/OakRepositoryStub.java
Thu Aug  2 11:46:37 2012
@@ -19,6 +19,7 @@ package org.apache.jackrabbit.oak.jcr;
 import java.io.IOException;
 import java.security.Principal;
 import java.util.Properties;
+import java.util.concurrent.Executors;
 
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
@@ -48,7 +49,7 @@ public class OakRepositoryStub extends R
 
         MicroKernel microkernel = new MicroKernelImpl("target/mk-tck-" + System.currentTimeMillis());
         ContentRepository contentRepository = new ContentRepositoryImpl(microkernel, null,
null);
-        repository = new RepositoryImpl(contentRepository);
+        repository = new RepositoryImpl(contentRepository, Executors.newScheduledThreadPool(1));
 
         Session session = repository.login(superuser);
         try {

Modified: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java?rev=1368425&r1=1368424&r2=1368425&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java (original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java Thu
Aug  2 11:46:37 2012
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.oak.run;
 
 import java.io.InputStream;
 import java.util.Properties;
+import java.util.concurrent.Executors;
 
 import javax.jcr.Repository;
 import javax.servlet.Servlet;
@@ -137,7 +138,8 @@ public class Main {
                     new ServletHolder(new OakServlet(repository));
             context.addServlet(oak, path + "/*");
 
-            final Repository jcrRepository = new RepositoryImpl(repository);
+            final Repository jcrRepository = new RepositoryImpl(
+                    repository, Executors.newScheduledThreadPool(1));
 
             ServletHolder webdav =
                     new ServletHolder(new SimpleWebdavServlet() {

Modified: jackrabbit/oak/trunk/oak-sling/src/main/java/org/apache/jackrabbit/oak/sling/Activator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-sling/src/main/java/org/apache/jackrabbit/oak/sling/Activator.java?rev=1368425&r1=1368424&r2=1368425&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-sling/src/main/java/org/apache/jackrabbit/oak/sling/Activator.java
(original)
+++ jackrabbit/oak/trunk/oak-sling/src/main/java/org/apache/jackrabbit/oak/sling/Activator.java
Thu Aug  2 11:46:37 2012
@@ -19,6 +19,8 @@ package org.apache.jackrabbit.oak.sling;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
 
 import javax.jcr.Repository;
 
@@ -35,6 +37,8 @@ public class Activator implements Bundle
 
     private BundleContext context;
 
+    private ScheduledExecutorService executor;
+
     private ServiceTracker tracker;
 
     private final Map<ServiceReference, ServiceRegistration> jcrRepositories =
@@ -48,6 +52,7 @@ public class Activator implements Bundle
     @Override
     public void start(BundleContext bundleContext) throws Exception {
         context = bundleContext;
+        executor = Executors.newScheduledThreadPool(1);
         tracker = new ServiceTracker(
                 context, ContentRepository.class.getName(), this);
         tracker.open();
@@ -55,7 +60,8 @@ public class Activator implements Bundle
 
     @Override
     public void stop(BundleContext bundleContext) throws Exception {
-        tracker.open();
+        tracker.close();
+        executor.shutdown();
     }
 
     //--------------------------------------------< ServiceTrackerCustomizer >--
@@ -64,8 +70,8 @@ public class Activator implements Bundle
     public Object addingService(ServiceReference reference) {
         Object service = context.getService(reference);
         if (service instanceof ContentRepository) {
-            SlingRepository repository =
-                    new SlingRepositoryImpl((ContentRepository) service);
+            SlingRepository repository = new SlingRepositoryImpl(
+                    (ContentRepository) service, executor);
             jcrRepositories.put(reference, context.registerService(
                     Repository.class.getName(),
                     repository, new Properties()));

Modified: jackrabbit/oak/trunk/oak-sling/src/main/java/org/apache/jackrabbit/oak/sling/SlingRepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-sling/src/main/java/org/apache/jackrabbit/oak/sling/SlingRepositoryImpl.java?rev=1368425&r1=1368424&r2=1368425&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-sling/src/main/java/org/apache/jackrabbit/oak/sling/SlingRepositoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-sling/src/main/java/org/apache/jackrabbit/oak/sling/SlingRepositoryImpl.java
Thu Aug  2 11:46:37 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.oak.sling;
 
+import java.util.concurrent.ScheduledExecutorService;
+
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
@@ -26,8 +28,9 @@ import org.apache.sling.jcr.api.SlingRep
 public class SlingRepositoryImpl
         extends RepositoryImpl implements SlingRepository {
 
-    public SlingRepositoryImpl(ContentRepository repository) {
-        super(repository);
+    public SlingRepositoryImpl(
+            ContentRepository repository, ScheduledExecutorService executor) {
+        super(repository, executor);
     }
 
     @Override



Mime
View raw message