You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2015/10/30 09:29:11 UTC
svn commit: r1711425 - in /sling/trunk/bundles/jcr/resource/src:
main/java/org/apache/sling/jcr/resource/internal/
main/java/org/apache/sling/jcr/resource/internal/helper/jcr/
test/java/org/apache/sling/jcr/resource/internal/
Author: cziegeler
Date: Fri Oct 30 08:29:11 2015
New Revision: 1711425
URL: http://svn.apache.org/viewvc?rev=1711425&view=rev
Log:
SLING-2784 : JcrResourceListener might deliver wrong remove events
Modified:
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceListener.java
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/OakResourceListener.java
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/ObservationListenerSupport.java
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceListenerScalabilityTest.java
sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/SynchronousJcrResourceListener.java
sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/SynchronousOakResourceListener.java
Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceListener.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceListener.java?rev=1711425&r1=1711424&r2=1711425&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceListener.java (original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceListener.java Fri Oct 30 08:29:11 2015
@@ -102,6 +102,7 @@ public class JcrResourceListener impleme
this.osgiEventQueue = new LinkedBlockingQueue<Map<String,Object>>();
final Thread oeqt = new Thread(new Runnable() {
+ @Override
public void run() {
processOsgiEventQueue();
}
@@ -112,6 +113,7 @@ public class JcrResourceListener impleme
/**
* Dispose this listener.
*/
+ @Override
public void close() throws IOException {
// unregister from observations
try {
@@ -130,6 +132,7 @@ public class JcrResourceListener impleme
/**
* @see javax.jcr.observation.EventListener#onEvent(javax.jcr.observation.EventIterator)
*/
+ @Override
public void onEvent(final EventIterator events) {
// if the event admin is currently not available, we just skip this
final EventAdmin localEA = this.support.getEventAdmin();
@@ -295,7 +298,7 @@ public class JcrResourceListener impleme
final ChangedAttributes changedAttributes) {
final String resourcePath = pathMapper.mapJCRPathToResourcePath(path);
- if ( resourcePath != null ) {
+ if ( resourcePath != null && !this.support.isExcluded(resourcePath)) {
if (changedAttributes != null) {
changedAttributes.mergeAttributesInto(properties);
}
Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/OakResourceListener.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/OakResourceListener.java?rev=1711425&r1=1711424&r2=1711425&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/OakResourceListener.java (original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/OakResourceListener.java Fri Oct 30 08:29:11 2015
@@ -265,7 +265,7 @@ public class OakResourceListener extends
if ( sendEvent ) {
final String resourcePath = pathMapper.mapJCRPathToResourcePath(changes.get(SlingConstants.PROPERTY_PATH).toString());
- if ( resourcePath != null ) {
+ if ( resourcePath != null && !this.support.isExcluded(resourcePath)) {
changes.put(SlingConstants.PROPERTY_PATH, resourcePath);
localEa.sendEvent(new org.osgi.service.event.Event(topic, new EventProperties(changes)));
Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/ObservationListenerSupport.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/ObservationListenerSupport.java?rev=1711425&r1=1711424&r2=1711425&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/ObservationListenerSupport.java (original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/ObservationListenerSupport.java Fri Oct 30 08:29:11 2015
@@ -26,6 +26,7 @@ import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.apache.sling.api.resource.LoginException;
+import org.apache.sling.api.resource.PathSet;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.jcr.api.SlingRepository;
@@ -58,12 +59,17 @@ public class ObservationListenerSupport
private final Session session;
- public ObservationListenerSupport(final BundleContext bundleContext, final SlingRepository repository)
+ private final PathSet excludedPaths;
+
+ public ObservationListenerSupport(final BundleContext bundleContext,
+ final SlingRepository repository,
+ final PathSet excludedPaths)
throws RepositoryException {
this.bundleContext = bundleContext;
this.eventAdminTracker = new ServiceTracker(bundleContext, EventAdmin.class.getName(), null);
this.eventAdminTracker.open();
+ this.excludedPaths = excludedPaths;
this.session = repository.loginAdministrative(null);
}
@@ -86,6 +92,10 @@ public class ObservationListenerSupport
this.session.logout();
}
+ public boolean isExcluded(final String path) {
+ return this.excludedPaths != null && this.excludedPaths.matches(path) != null;
+ }
+
public Session getSession() {
return this.session;
}
Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java?rev=1711425&r1=1711424&r2=1711425&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java (original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java Fri Oct 30 08:29:11 2015
@@ -160,7 +160,6 @@ public class JcrResourceProvider extends
this.optimizeForOak = PropertiesUtil.toBoolean(context.getProperties().get(PROPERTY_OPTIMIZE_FOR_OAK), DEFAULT_OPTIMIZE_FOR_OAK);
this.root = PropertiesUtil.toString(context.getProperties().get(ResourceProvider.PROPERTY_ROOT), "/");
this.bundleCtx = context.getBundleContext();
- registerLegacyListener();
HelperData helperData = new HelperData(dynamicClassLoaderManager.getDynamicClassLoader(), pathMapper);
this.stateFactory = new JcrProviderStateFactory(repositoryReference, repository, helperData);
@@ -171,6 +170,19 @@ public class JcrResourceProvider extends
unregisterLegacyListener();
}
+
+ @Override
+ public void activate(final ProviderContext ctx) {
+ super.activate(ctx);
+ registerLegacyListener();
+ }
+
+ @Override
+ public void deactivate() {
+ unregisterLegacyListener();
+ super.deactivate();
+ }
+
@SuppressWarnings("unused")
private void bindRepository(final ServiceReference ref) {
this.repositoryReference = ref;
@@ -201,7 +213,7 @@ public class JcrResourceProvider extends
ObservationListenerSupport support = null;
boolean closeSupport = true;
try {
- support = new ObservationListenerSupport(bundleCtx, repository);
+ support = new ObservationListenerSupport(bundleCtx, repository, this.getProviderContext().getExcludedPaths());
if (isOak) {
try {
this.listener = new OakResourceListener(root, support, bundleCtx, executor, pathMapper, observationQueueLength);
Modified: sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceListenerScalabilityTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceListenerScalabilityTest.java?rev=1711425&r1=1711424&r2=1711425&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceListenerScalabilityTest.java (original)
+++ sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceListenerScalabilityTest.java Fri Oct 30 08:29:11 2015
@@ -65,7 +65,7 @@ public class JcrResourceListenerScalabil
when(bundleContext.getServiceReferences(anyString(), anyString())).thenReturn(serviceRefs);
when(bundleContext.getService(serviceRef)).thenReturn(eventAdmin);
- jcrResourceListener = new JcrResourceListener("/", new ObservationListenerSupport(bundleContext, repository), new PathMapperImpl());
+ jcrResourceListener = new JcrResourceListener("/", new ObservationListenerSupport(bundleContext, repository, null), new PathMapperImpl());
Event event = mock(MockEvent.class);
events = mock(EventIterator.class);
@@ -84,6 +84,7 @@ public class JcrResourceListenerScalabil
private abstract static class MockEvent implements Event {
int count;
+ @Override
public String getPath() throws RepositoryException {
return "path-" + count++;
}
Modified: sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/SynchronousJcrResourceListener.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/SynchronousJcrResourceListener.java?rev=1711425&r1=1711424&r2=1711425&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/SynchronousJcrResourceListener.java (original)
+++ sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/SynchronousJcrResourceListener.java Fri Oct 30 08:29:11 2015
@@ -20,8 +20,6 @@ import java.io.IOException;
import javax.jcr.RepositoryException;
-import junitx.util.PrivateAccessor;
-
import org.apache.jackrabbit.core.observation.SynchronousEventListener;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.ResourceResolver;
@@ -29,6 +27,8 @@ import org.apache.sling.jcr.api.SlingRep
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
+import junitx.util.PrivateAccessor;
+
/**
* This class is used to ensure that events are handled during the test.
*
@@ -44,7 +44,7 @@ public class SynchronousJcrResourceListe
final ResourceResolver resolver,
final ServiceTracker tracker)
throws LoginException, RepositoryException, NoSuchFieldException {
- super("/", new ObservationListenerSupport(bundleContext, repo), new PathMapperImpl());
+ super("/", new ObservationListenerSupport(bundleContext, repo, null), new PathMapperImpl());
PrivateAccessor.setField(this.support, "resourceResolver", resolver);
PrivateAccessor.setField(this.support, "eventAdminTracker", tracker);
}
Modified: sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/SynchronousOakResourceListener.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/SynchronousOakResourceListener.java?rev=1711425&r1=1711424&r2=1711425&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/SynchronousOakResourceListener.java (original)
+++ sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/SynchronousOakResourceListener.java Fri Oct 30 08:29:11 2015
@@ -21,14 +21,14 @@ import java.util.concurrent.Executor;
import javax.jcr.RepositoryException;
-import junitx.util.PrivateAccessor;
-
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.jcr.api.SlingRepository;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
+import junitx.util.PrivateAccessor;
+
/**
* This class is used to ensure that events are handled during the test.
*
@@ -45,7 +45,7 @@ public class SynchronousOakResourceListe
final ServiceTracker tracker,
final Executor executor)
throws LoginException, RepositoryException, NoSuchFieldException {
- super("/", new ObservationListenerSupport(bundleContext, repo), bundleContext, executor, new PathMapperImpl(), 1000);
+ super("/", new ObservationListenerSupport(bundleContext, repo, null), bundleContext, executor, new PathMapperImpl(), 1000);
PrivateAccessor.setField(this.support, "resourceResolver", resolver);
PrivateAccessor.setField(this.support, "eventAdminTracker", tracker);
}