Author: cziegeler
Date: Tue Sep 20 10:06:21 2016
New Revision: 1761546

URL: http://svn.apache.org/viewvc?rev=1761546&view=rev
Log:
SLING-5998 : NewJobSender should move to new ResourceChangeListener API

Modified:
    sling/trunk/bundles/extensions/event/pom.xml
    
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/notifications/NewJobSender.java
    
sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/it/AbstractJobHandlingTest.java

Modified: sling/trunk/bundles/extensions/event/pom.xml
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/pom.xml?rev=1761546&r1=1761545&r2=1761546&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/pom.xml (original)
+++ sling/trunk/bundles/extensions/event/pom.xml Tue Sep 20 10:06:21 2016
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.apache.sling</groupId>
         <artifactId>sling</artifactId>
-        <version>26</version>
+        <version>28</version>
         <relativePath />
     </parent>
 
@@ -202,10 +202,6 @@
     </profiles>
     <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>
@@ -242,7 +238,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>
         <dependency>
@@ -264,9 +260,15 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
+               <groupId>org.apache.sling</groupId>
+               <artifactId>org.apache.sling.discovery.commons</artifactId>
+               <version>1.0.12</version>
+               <scope>provided</scope>
+        </dependency>
+        <dependency>
             <groupId>org.apache.jackrabbit</groupId>
             <artifactId>jackrabbit-jcr-commons</artifactId>
-            <version>2.2.4</version>
+            <version>2.11.2</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
@@ -278,7 +280,7 @@
       <!-- Webconsole -->
         <dependency>
             <groupId>javax.servlet</groupId>
-            <artifactId>servlet-api</artifactId>
+            <artifactId>javax.servlet-api</artifactId>
         </dependency>
       <!-- Testing -->
         <dependency>
@@ -332,6 +334,13 @@
         </dependency>
 
         <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-cm</artifactId>
+            <version>${exam.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
             <groupId>org.ops4j.pax.url</groupId>
             <artifactId>pax-url-aether</artifactId>
             <version>${url.version}</version>
@@ -350,11 +359,5 @@
             <version>1</version>
             <scope>test</scope>
         </dependency>
-        <dependency>
-               <groupId>org.apache.sling</groupId>
-               <artifactId>org.apache.sling.discovery.commons</artifactId>
-               <version>1.0.12</version>
-               <scope>provided</scope>
-        </dependency>
     </dependencies>
 </project>

Modified: 
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/notifications/NewJobSender.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/notifications/NewJobSender.java?rev=1761546&r1=1761545&r2=1761546&view=diff
==============================================================================
--- 
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/notifications/NewJobSender.java
 (original)
+++ 
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/notifications/NewJobSender.java
 Tue Sep 20 10:06:21 2016
@@ -20,12 +20,16 @@ package org.apache.sling.event.impl.jobs
 
 import java.util.Dictionary;
 import java.util.Hashtable;
+import java.util.List;
 
 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.Reference;
-import org.apache.sling.api.SlingConstants;
+import 
org.apache.sling.api.resource.observation.ExternalResourceChangeListener;
+import org.apache.sling.api.resource.observation.ResourceChange;
+import org.apache.sling.api.resource.observation.ResourceChange.ChangeType;
+import org.apache.sling.api.resource.observation.ResourceChangeListener;
 import org.apache.sling.event.impl.jobs.config.JobManagerConfiguration;
 import org.apache.sling.event.jobs.Job;
 import org.apache.sling.event.jobs.NotificationConstants;
@@ -34,8 +38,6 @@ import org.osgi.framework.Constants;
 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;
 
@@ -44,7 +46,7 @@ import org.slf4j.LoggerFactory;
  * created event.
  */
 @Component
-public class NewJobSender implements EventHandler {
+public class NewJobSender implements ResourceChangeListener, 
ExternalResourceChangeListener {
 
     /** Logger. */
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
@@ -58,7 +60,7 @@ public class NewJobSender implements Eve
     private EventAdmin eventAdmin;
 
     /** Service registration for the event handler. */
-    private volatile ServiceRegistration eventHandlerRegistration;
+    private volatile ServiceRegistration<ResourceChangeListener> 
listenerRegistration;
 
     /**
      * Activate this component.
@@ -69,11 +71,10 @@ public class NewJobSender implements Eve
         final Dictionary<String, Object> properties = new Hashtable<String, 
Object>();
         properties.put(Constants.SERVICE_DESCRIPTION, "Apache Sling Job Topic 
Manager Event Handler");
         properties.put(Constants.SERVICE_VENDOR, "The Apache Software 
Foundation");
-        properties.put(EventConstants.EVENT_TOPIC, 
SlingConstants.TOPIC_RESOURCE_ADDED);
-        properties.put(EventConstants.EVENT_FILTER,
-                "(" + SlingConstants.PROPERTY_PATH + "=" +
-                      this.configuration.getLocalJobsPath() + "/*)");
-        this.eventHandlerRegistration = 
bundleContext.registerService(EventHandler.class.getName(), this, properties);
+        properties.put(ResourceChangeListener.CHANGES, 
ChangeType.ADDED.toString());
+        properties.put(ResourceChangeListener.PATHS, 
this.configuration.getLocalJobsPath());
+
+        this.listenerRegistration = 
bundleContext.registerService(ResourceChangeListener.class, this, properties);
     }
 
     /**
@@ -82,31 +83,32 @@ public class NewJobSender implements Eve
      */
     @Deactivate
     protected void deactivate() {
-        if ( this.eventHandlerRegistration != null ) {
-            this.eventHandlerRegistration.unregister();
-            this.eventHandlerRegistration = null;
+        if ( this.listenerRegistration != null ) {
+            this.listenerRegistration.unregister();
+            this.listenerRegistration = null;
         }
     }
 
     @Override
-    public void handleEvent(final Event event) {
-        logger.debug("Received event {}", event);
-        final String path = (String) 
event.getProperty(SlingConstants.PROPERTY_PATH);
-        if ( this.configuration.isLocalJob(path) ) {
-            // get topic and id from path
-            final int topicStart = 
this.configuration.getLocalJobsPath().length() + 1;
-            final int topicEnd = path.indexOf('/', topicStart);
-            if ( topicEnd != -1 ) {
-                final String topic = path.substring(topicStart, 
topicEnd).replace('.', '/');
+       public void onChange(final List<ResourceChange> resourceChanges) {
+       for(final ResourceChange resourceChange : resourceChanges) {
+               logger.debug("Received event {}", resourceChange);
+
+               final String path = resourceChange.getPath();
+
+               final int topicStart = 
this.configuration.getLocalJobsPath().length() + 1;
+               final int topicEnd = path.indexOf('/', topicStart);
+               if ( topicEnd != -1 ) {
+                       final String topic = path.substring(topicStart, 
topicEnd).replace('.', '/');
                 final String jobId = path.substring(topicEnd + 1);
 
                 if ( path.indexOf("_", topicEnd + 1) != -1 ) {
-                    // only job id and topic are guaranteed
-                    final Dictionary<String, Object> properties = new 
Hashtable<String, Object>();
-                    
properties.put(NotificationConstants.NOTIFICATION_PROPERTY_JOB_ID, jobId);
+                       // only job id and topic are guaranteed
+                       final Dictionary<String, Object> properties = new 
Hashtable<String, Object>();
+                       
properties.put(NotificationConstants.NOTIFICATION_PROPERTY_JOB_ID, jobId);
                     
properties.put(NotificationConstants.NOTIFICATION_PROPERTY_JOB_TOPIC, topic);
 
-                    // we also set internally the queue name
+                 // we also set internally the queue name
                     final String queueName = 
this.configuration.getQueueConfigurationManager().getQueueInfo(topic).queueName;
                     properties.put(Job.PROPERTY_JOB_QUEUE_NAME, queueName);
 
@@ -114,8 +116,8 @@ public class NewJobSender implements Eve
                     // as this is send within handling an event, we do sync 
call
                     this.eventAdmin.sendEvent(jobEvent);
                 }
-            }
-        }
-    }
+               }
+       }
 
+       }
 }

Modified: 
sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/it/AbstractJobHandlingTest.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/it/AbstractJobHandlingTest.java?rev=1761546&r1=1761545&r2=1761546&view=diff
==============================================================================
--- 
sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/it/AbstractJobHandlingTest.java
 (original)
+++ 
sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/it/AbstractJobHandlingTest.java
 Tue Sep 20 10:06:21 2016
@@ -49,6 +49,7 @@ import org.apache.sling.event.jobs.consu
 import org.ops4j.pax.exam.Configuration;
 import org.ops4j.pax.exam.CoreOptions;
 import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.cm.ConfigurationAdminOptions;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
@@ -97,8 +98,14 @@ public abstract class AbstractJobHandlin
 
         String localRepo = System.getProperty("maven.repo.local", "");
 
+        final String jackrabbitVersion = "2.13.1";
+        final String oakVersion = "1.5.7";
+
+        final String slingHome = new File(buildDir + File.separatorChar + 
"sling_" + System.currentTimeMillis()).getAbsolutePath();
+
         return options(
-                frameworkProperty("sling.home").value(new File(buildDir + 
File.separatorChar + "sling_" + System.currentTimeMillis()).getAbsolutePath()),
+                frameworkProperty("sling.home").value(slingHome),
+                frameworkProperty("repository.home").value(slingHome + 
File.separatorChar + "repository"),
                 when( localRepo.length() > 0 ).useOptions(
                         
systemProperty("org.ops4j.pax.url.mvn.localRepository").value(localRepo)
                 ),
@@ -106,6 +113,57 @@ public abstract class AbstractJobHandlin
                         
systemProperty(PORT_CONFIG).value(System.getProperty(PORT_CONFIG))),
                 systemProperty("pax.exam.osgi.unresolved.fail").value("true"),
 
+                
ConfigurationAdminOptions.newConfiguration("org.apache.felix.jaas.ConfigurationSpi")
+                    .create(true)
+                    .put("jaas.defaultRealmName", "jackrabbit.oak")
+                    .put("jaas.configProviderName", "FelixJaasProvider")
+                    .asOption(),
+                
ConfigurationAdminOptions.factoryConfiguration("org.apache.felix.jaas.Configuration.factory")
+                    .create(true)
+                    .put("jaas.controlFlag", "optional")
+                    .put("jaas.classname", 
"org.apache.jackrabbit.oak.spi.security.authentication.GuestLoginModule")
+                    .put("jaas.ranking", 300)
+                    .asOption(),
+                
ConfigurationAdminOptions.factoryConfiguration("org.apache.felix.jaas.Configuration.factory")
+                    .create(true)
+                    .put("jaas.controlFlag", "required")
+                    .put("jaas.classname", 
"org.apache.jackrabbit.oak.security.authentication.user.LoginModuleImpl")
+                    .asOption(),
+                
ConfigurationAdminOptions.factoryConfiguration("org.apache.felix.jaas.Configuration.factory")
+                    .create(true)
+                    .put("jaas.controlFlag", "sufficient")
+                    .put("jaas.classname", 
"org.apache.jackrabbit.oak.security.authentication.token.TokenLoginModule")
+                    .put("jaas.ranking", 200)
+                    .asOption(),
+                
ConfigurationAdminOptions.newConfiguration("org.apache.jackrabbit.oak.security.authentication.AuthenticationConfigurationImpl")
+                    .create(true)
+                    
.put("org.apache.jackrabbit.oak.authentication.configSpiName", 
"FelixJaasProvider")
+                    .asOption(),
+                
ConfigurationAdminOptions.newConfiguration("org.apache.jackrabbit.oak.security.user.UserConfigurationImpl")
+                    .create(true)
+                    .put("groupsPath", "/home/groups")
+                    .put("usersPath", "/home/users")
+                    .put("defaultPath", "1")
+                    .put("importBehavior", "besteffort")
+                    .asOption(),
+                
ConfigurationAdminOptions.newConfiguration("org.apache.jackrabbit.oak.security.user.RandomAuthorizableNodeName")
+                    .create(true)
+                    .put("enabledActions", new String[] 
{"org.apache.jackrabbit.oak.spi.security.user.action.AccessControlAction"})
+                    .put("userPrivilegeNames", new String[] {"jcr:all"})
+                    .put("groupPrivilegeNames", new String[] {"jcr:read"})
+                    .asOption(),
+                
ConfigurationAdminOptions.newConfiguration("org.apache.jackrabbit.oak.spi.security.user.action.DefaultAuthorizableActionProvider")
+                    .create(true)
+                    .put("length", 21)
+                    .asOption(),
+                
ConfigurationAdminOptions.newConfiguration("org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStoreService")
+                    .create(true)
+                    .put("name", "Default NodeStore")
+                    .asOption(),
+                
ConfigurationAdminOptions.newConfiguration("org.apache.sling.resourceresolver.impl.observation.OsgiObservationBridge")
+                    .create(true)
+                    .put("enabled", true)
+                    .asOption(),
                 // logging
                 systemProperty("pax.exam.logging").value("none"),
                 mavenBundle("org.apache.sling", 
"org.apache.sling.commons.log", "4.0.6"),
@@ -129,9 +187,10 @@ public abstract class AbstractJobHandlin
 
                 // infrastructure
                 mavenBundle("org.apache.felix", 
"org.apache.felix.http.servlet-api", "1.1.2"),
+                mavenBundle("org.apache.felix", "org.apache.felix.http.jetty", 
"3.1.6"),
                 mavenBundle("org.apache.felix", "org.apache.felix.eventadmin", 
"1.4.4"),
-                mavenBundle("org.apache.felix", "org.apache.felix.scr", 
"2.0.2"),
-                mavenBundle("org.apache.felix", 
"org.apache.felix.configadmin", "1.8.8"),
+                mavenBundle("org.apache.felix", "org.apache.felix.scr", 
"2.0.4"),
+                mavenBundle("org.apache.felix", 
"org.apache.felix.configadmin", "1.8.10"),
                 mavenBundle("org.apache.felix", "org.apache.felix.inventory", 
"1.0.4"),
                 mavenBundle("org.apache.felix", "org.apache.felix.metatype", 
"1.1.2"),
 
@@ -146,33 +205,45 @@ public abstract class AbstractJobHandlin
 
                 mavenBundle("org.apache.sling", "org.apache.sling.auth.core", 
"1.3.12"),
                 mavenBundle("org.apache.sling", 
"org.apache.sling.discovery.api", "1.0.2"),
+                mavenBundle("org.apache.sling", 
"org.apache.sling.discovery.commons", "1.0.12"),
                 mavenBundle("org.apache.sling", 
"org.apache.sling.discovery.standalone", "1.0.2"),
 
-                mavenBundle("org.apache.sling", "org.apache.sling.api", 
"2.9.0"),
-                mavenBundle("org.apache.sling", 
"org.apache.sling.resourceresolver", "1.2.6"),
+                mavenBundle("org.apache.sling", "org.apache.sling.api", 
"2.14.2"),
+                mavenBundle("org.apache.sling", 
"org.apache.sling.resourceresolver", "1.4.18"),
                 mavenBundle("org.apache.sling", "org.apache.sling.adapter", 
"2.1.2"),
-                mavenBundle("org.apache.sling", 
"org.apache.sling.jcr.resource", "2.5.6"),
+                mavenBundle("org.apache.sling", 
"org.apache.sling.jcr.resource", "2.8.0"),
                 mavenBundle("org.apache.sling", 
"org.apache.sling.jcr.classloader", "3.2.2"),
                 mavenBundle("org.apache.sling", 
"org.apache.sling.jcr.contentloader", "2.1.8"),
-                mavenBundle("org.apache.sling", "org.apache.sling.engine", 
"2.3.6"),
+                mavenBundle("org.apache.sling", "org.apache.sling.engine", 
"2.6.2"),
                 mavenBundle("org.apache.sling", 
"org.apache.sling.serviceusermapper", "1.2.2"),
 
                 mavenBundle("org.apache.sling", 
"org.apache.sling.jcr.jcr-wrapper", "2.0.0"),
-                mavenBundle("org.apache.sling", "org.apache.sling.jcr.api", 
"2.3.0"),
-                mavenBundle("org.apache.sling", "org.apache.sling.jcr.base", 
"2.3.0"),
-                mavenBundle("org.apache.jackrabbit", "jackrabbit-api", 
"2.10.1"),
-                mavenBundle("org.apache.jackrabbit", "jackrabbit-jcr-commons", 
"2.10.1"),
-                mavenBundle("org.apache.jackrabbit", "jackrabbit-spi", 
"2.10.1"),
-                mavenBundle("org.apache.jackrabbit", "jackrabbit-spi-commons", 
"2.10.1"),
-                mavenBundle("org.apache.jackrabbit", "jackrabbit-jcr-rmi", 
"2.10.1"),
-                mavenBundle("org.apache.derby", "derby", "10.5.3.0_1"),
-                mavenBundle("org.apache.sling", 
"org.apache.sling.jcr.jackrabbit.server", "2.3.0"),
+                mavenBundle("org.apache.sling", "org.apache.sling.jcr.api", 
"2.4.0"),
+                mavenBundle("org.apache.sling", "org.apache.sling.jcr.base", 
"2.4.0"),
+
+                mavenBundle("com.google.guava", "guava", "15.0"),
+                mavenBundle("org.apache.jackrabbit", "jackrabbit-api", 
jackrabbitVersion),
+                mavenBundle("org.apache.jackrabbit", "jackrabbit-jcr-commons", 
jackrabbitVersion),
+                mavenBundle("org.apache.jackrabbit", "jackrabbit-spi", 
jackrabbitVersion),
+                mavenBundle("org.apache.jackrabbit", "jackrabbit-spi-commons", 
jackrabbitVersion),
+                mavenBundle("org.apache.jackrabbit", "jackrabbit-jcr-rmi", 
jackrabbitVersion),
+
+                mavenBundle("org.apache.felix", "org.apache.felix.jaas", 
"0.0.4"),
+
+                mavenBundle("org.apache.jackrabbit", "oak-core", oakVersion),
+                mavenBundle("org.apache.jackrabbit", "oak-commons", 
oakVersion),
+                mavenBundle("org.apache.jackrabbit", "oak-lucene", oakVersion),
+                mavenBundle("org.apache.jackrabbit", "oak-blob", oakVersion),
+                mavenBundle("org.apache.jackrabbit", "oak-jcr", oakVersion),
+
+                mavenBundle("org.apache.jackrabbit", "oak-segment", 
oakVersion),
+
+                mavenBundle("org.apache.sling", 
"org.apache.sling.jcr.oak.server", "1.1.0"),
 
                 mavenBundle("org.apache.sling", 
"org.apache.sling.testing.tools", "1.0.6"),
                 mavenBundle("org.apache.httpcomponents", "httpcore-osgi", 
"4.1.2"),
                 mavenBundle("org.apache.httpcomponents", "httpclient-osgi", 
"4.1.2"),
 
-                mavenBundle("org.apache.sling", 
"org.apache.sling.discovery.commons", "1.0.12"),
 
                 // SLING-5560: delaying start of the sling.event bundle to
                 // ensure the parameter 'startup.delay' is properly set to 1sec
@@ -212,7 +283,7 @@ public abstract class AbstractJobHandlin
             // ignore
         }
     }
-    
+
     public void setup() throws IOException {
         // set load delay to 3 sec
         final org.osgi.service.cm.Configuration c2 = 
this.configAdmin.getConfiguration("org.apache.sling.event.impl.jobs.jcr.PersistenceHandler",
 null);
@@ -221,7 +292,7 @@ public abstract class AbstractJobHandlin
         // and startup.delay to 1sec - otherwise default of 30sec breaks tests!
         p2.put(JobManagerConfiguration.PROPERTY_STARTUP_DELAY, 1L);
         c2.update(p2);
-        
+
         // SLING-5560 : since the above (re)config is now applied, we're safe
         // to go ahead and start the sling.event bundle.
         // this time, the JobManagerConfiguration will be activated


Reply via email to