This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.event.dea-1.1.0 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-event-dea.git
commit 9fe4fe69e5f89db56ba312710f4ac921c9c96c9d Author: Carsten Ziegeler <[email protected]> AuthorDate: Thu Sep 22 13:33:05 2016 +0000 SLING-5996 : DistributedEventSender should move to new ResourceChangeListener API git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/dea@1761965 13f79535-47bb-0310-9956-ffa450edef68 --- pom.xml | 28 ++++++--------- .../event/dea/impl/DistributedEventAdminImpl.java | 40 +++++++++------------- .../event/dea/impl/DistributedEventReceiver.java | 4 +-- .../event/dea/impl/DistributedEventSender.java | 38 ++++++++++---------- .../org/apache/sling/event/dea/package-info.java | 3 +- .../dea/impl/DistributingEventHandlerTest.java | 6 +++- 6 files changed, 55 insertions(+), 64 deletions(-) diff --git a/pom.xml b/pom.xml index 83d3675..c2d9718 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ <parent> <groupId>org.apache.sling</groupId> <artifactId>sling</artifactId> - <version>26</version> + <version>28</version> <relativePath /> </parent> @@ -46,10 +46,6 @@ <plugins> <plugin> <groupId>org.apache.felix</groupId> - <artifactId>maven-scr-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <extensions>true</extensions> </plugin> @@ -70,28 +66,24 @@ </reporting> <dependencies> <dependency> - <groupId>org.apache.felix</groupId> - <artifactId>org.apache.felix.scr.annotations</artifactId> - </dependency> - <dependency> <groupId>org.apache.sling</groupId> <artifactId>org.apache.sling.discovery.api</artifactId> <version>1.0.0</version> <scope>provided</scope> </dependency> <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.service.event</artifactId> + <version>1.3.1</version> + <scope>provided</scope> </dependency> <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.core</artifactId> - <version>4.2.0</version> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> </dependency> <dependency> <groupId>org.osgi</groupId> - <artifactId>org.osgi.compendium</artifactId> - <version>4.2.0</version> + <artifactId>osgi.core</artifactId> </dependency> <dependency> <groupId>org.apache.sling</groupId> @@ -108,7 +100,7 @@ <dependency> <groupId>org.apache.sling</groupId> <artifactId>org.apache.sling.api</artifactId> - <version>2.4.0</version> + <version>2.11.0</version> <scope>provided</scope> </dependency> <!-- Testing --> @@ -125,7 +117,7 @@ <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-all</artifactId> - <version>1.9.5</version> + <version>1.10.19</version> <scope>test</scope> </dependency> <dependency> diff --git a/src/main/java/org/apache/sling/event/dea/impl/DistributedEventAdminImpl.java b/src/main/java/org/apache/sling/event/dea/impl/DistributedEventAdminImpl.java index df128b4..27a811c 100644 --- a/src/main/java/org/apache/sling/event/dea/impl/DistributedEventAdminImpl.java +++ b/src/main/java/org/apache/sling/event/dea/impl/DistributedEventAdminImpl.java @@ -18,17 +18,13 @@ */ package org.apache.sling.event.dea.impl; -import java.util.Map; - -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Deactivate; -import org.apache.felix.scr.annotations.Property; -import org.apache.felix.scr.annotations.Reference; import org.apache.sling.api.resource.ResourceResolverFactory; -import org.apache.sling.commons.osgi.PropertiesUtil; import org.apache.sling.settings.SlingSettingsService; import org.osgi.framework.BundleContext; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.component.annotations.Reference; import org.osgi.service.event.EventAdmin; /** @@ -38,6 +34,14 @@ import org.osgi.service.event.EventAdmin; @Component(name="org.apache.sling.event.impl.DistributingEventHandler") public class DistributedEventAdminImpl { + public @interface Config { + + /** The path where all jobs are stored. */ + String repository_path() default DEFAULT_REPOSITORY_PATH; + + int cleanup_period() default DEFAULT_CLEANUP_PERIOD; + } + public static final String RESOURCE_TYPE_FOLDER = "sling:Folder"; public static final String RESOURCE_TYPE_EVENT = "sling/distributed/event"; @@ -54,16 +58,9 @@ public class DistributedEventAdminImpl { /** Default repository path. */ public static final String DEFAULT_REPOSITORY_PATH = "/var/eventing/distribution"; - /** The path where all jobs are stored. */ - @Property(value=DEFAULT_REPOSITORY_PATH) - private static final String CONFIG_PROPERTY_REPOSITORY_PATH = "repository.path"; - /** Default clean up time is 15 minutes. */ private static final int DEFAULT_CLEANUP_PERIOD = 15; - @Property(intValue=DEFAULT_CLEANUP_PERIOD) - private static final String CONFIG_PROPERTY_CLEANUP_PERIOD = "cleanup.period"; - /** The local receiver of distributed events .*/ private DistributedEventReceiver receiver; @@ -71,19 +68,16 @@ public class DistributedEventAdminImpl { private DistributedEventSender sender; @Activate - protected void activate(final BundleContext bundleContext, final Map<String, Object> props) { - final int cleanupPeriod = PropertiesUtil.toInteger(props.get(CONFIG_PROPERTY_CLEANUP_PERIOD), DEFAULT_CLEANUP_PERIOD); - final String rootPath = PropertiesUtil.toString(props.get( - CONFIG_PROPERTY_REPOSITORY_PATH), DEFAULT_REPOSITORY_PATH); - final String ownRootPath = rootPath.concat("/").concat(settings.getSlingId()); + protected void activate(final BundleContext bundleContext, final Config props) { + final String ownRootPath = props.repository_path().concat("/").concat(settings.getSlingId()); this.receiver = new DistributedEventReceiver(bundleContext, - rootPath, + props.repository_path(), ownRootPath, - cleanupPeriod, + props.cleanup_period(), this.resourceResolverFactory, this.settings); this.sender = new DistributedEventSender(bundleContext, - rootPath, + props.repository_path(), ownRootPath, this.resourceResolverFactory, this.eventAdmin); } diff --git a/src/main/java/org/apache/sling/event/dea/impl/DistributedEventReceiver.java b/src/main/java/org/apache/sling/event/dea/impl/DistributedEventReceiver.java index 995a0a9..7635f81 100644 --- a/src/main/java/org/apache/sling/event/dea/impl/DistributedEventReceiver.java +++ b/src/main/java/org/apache/sling/event/dea/impl/DistributedEventReceiver.java @@ -97,7 +97,7 @@ public class DistributedEventReceiver private volatile Set<String> instances; /** The service registration. */ - private volatile ServiceRegistration serviceRegistration; + private volatile ServiceRegistration<?> serviceRegistration; public DistributedEventReceiver(final BundleContext bundleContext, final String rootPath, @@ -127,7 +127,7 @@ public class DistributedEventReceiver props.put("scheduler.period", 1800L); props.put("scheduler.concurrent", Boolean.FALSE); - final ServiceRegistration reg = + final ServiceRegistration<?> reg = bundleContext.registerService(new String[] {EventHandler.class.getName(), Runnable.class.getName(), TopologyEventListener.class.getName()}, diff --git a/src/main/java/org/apache/sling/event/dea/impl/DistributedEventSender.java b/src/main/java/org/apache/sling/event/dea/impl/DistributedEventSender.java index 1cf81ec..e277bf9 100644 --- a/src/main/java/org/apache/sling/event/dea/impl/DistributedEventSender.java +++ b/src/main/java/org/apache/sling/event/dea/impl/DistributedEventSender.java @@ -25,12 +25,14 @@ import java.util.Map; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; -import org.apache.sling.api.SlingConstants; import org.apache.sling.api.resource.LoginException; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceResolver; import org.apache.sling.api.resource.ResourceResolverFactory; import org.apache.sling.api.resource.ValueMap; +import org.apache.sling.api.resource.observation.ExternalResourceChangeListener; +import org.apache.sling.api.resource.observation.ResourceChange; +import org.apache.sling.api.resource.observation.ResourceChangeListener; import org.apache.sling.event.dea.DEAConstants; import org.osgi.framework.BundleContext; import org.osgi.framework.Constants; @@ -38,7 +40,6 @@ import org.osgi.framework.ServiceRegistration; import org.osgi.service.event.Event; import org.osgi.service.event.EventAdmin; import org.osgi.service.event.EventConstants; -import org.osgi.service.event.EventHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,7 +53,7 @@ import org.slf4j.LoggerFactory; * <p> */ public class DistributedEventSender - implements EventHandler { + implements ResourceChangeListener, ExternalResourceChangeListener { /** Default logger. */ private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -69,7 +70,7 @@ public class DistributedEventSender private final String ownRootPathWithSlash; - private volatile ServiceRegistration serviceRegistration; + private volatile ServiceRegistration<ResourceChangeListener> serviceRegistration; public DistributedEventSender(final BundleContext bundleContext, final String rootPath, @@ -89,12 +90,12 @@ public class DistributedEventSender props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation"); // listen for all resource added OSGi events in the DEA area - props.put(EventConstants.EVENT_TOPIC, SlingConstants.TOPIC_RESOURCE_ADDED); - props.put(EventConstants.EVENT_FILTER, "(path=" + rootPath + "/*)"); + props.put(ResourceChangeListener.CHANGES, ResourceChange.ChangeType.ADDED.name()); + props.put(ResourceChangeListener.PATHS, rootPath); - final ServiceRegistration reg = - bundleContext.registerService(new String[] {EventHandler.class.getName()}, - DistributedEventSender.this, props); + final ServiceRegistration<ResourceChangeListener> reg = + bundleContext.registerService(ResourceChangeListener.class, + DistributedEventSender.this, props); DistributedEventSender.this.serviceRegistration = reg; @@ -218,17 +219,18 @@ public class DistributedEventSender } /** - * @see org.osgi.service.event.EventHandler#handleEvent(org.osgi.service.event.Event) + * @see org.apache.sling.api.resource.observation.ResourceChangeListener#onChange(java.util.List) */ @Override - public void handleEvent(final Event event) { - final String path = (String) event.getProperty(SlingConstants.PROPERTY_PATH); - if ( !path.startsWith(this.ownRootPathWithSlash) ) { - try { - this.queue.put(path); - } catch (final InterruptedException ex) { - this.ignoreException(ex); - Thread.currentThread().interrupt(); + public void onChange(final List<ResourceChange> changes) { + for(final ResourceChange c : changes) { + if ( !c.getPath().startsWith(this.ownRootPathWithSlash) ) { + try { + this.queue.put(c.getPath()); + } catch (final InterruptedException ex) { + this.ignoreException(ex); + Thread.currentThread().interrupt(); + } } } } diff --git a/src/main/java/org/apache/sling/event/dea/package-info.java b/src/main/java/org/apache/sling/event/dea/package-info.java index 9495421..8e790d4 100644 --- a/src/main/java/org/apache/sling/event/dea/package-info.java +++ b/src/main/java/org/apache/sling/event/dea/package-info.java @@ -17,8 +17,7 @@ * under the License. */ -@Version("1.0.0") [email protected]("1.0.0") package org.apache.sling.event.dea; -import aQute.bnd.annotation.Version; diff --git a/src/test/java/org/apache/sling/event/dea/impl/DistributingEventHandlerTest.java b/src/test/java/org/apache/sling/event/dea/impl/DistributingEventHandlerTest.java index 3547300..2b7293e 100644 --- a/src/test/java/org/apache/sling/event/dea/impl/DistributingEventHandlerTest.java +++ b/src/test/java/org/apache/sling/event/dea/impl/DistributingEventHandlerTest.java @@ -30,6 +30,8 @@ import java.util.List; import org.apache.sling.api.SlingConstants; import org.apache.sling.api.resource.ResourceResolver; import org.apache.sling.api.resource.ResourceResolverFactory; +import org.apache.sling.api.resource.observation.ResourceChange; +import org.apache.sling.api.resource.observation.ResourceChange.ChangeType; import org.apache.sling.event.dea.DEAConstants; import org.apache.sling.settings.SlingSettingsService; import org.apache.sling.testing.resourceresolver.MockResourceResolverFactory; @@ -77,7 +79,9 @@ public class DistributingEventHandlerTest { public void postEvent(final Event event) { final String topic = event.getTopic(); if ( topic.equals(SlingConstants.TOPIC_RESOURCE_ADDED) ) { - sender.handleEvent(event); + final ResourceChange change = new ResourceChange(ChangeType.ADDED, + (String)event.getProperty(SlingConstants.PROPERTY_PATH), false, null, null, null); + sender.onChange(Collections.singletonList(change)); } else if ( topic.startsWith(TOPIC_PREFIX) ) { events.add(event); } -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
