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 2014/10/15 09:18:18 UTC

svn commit: r1631960 - in /sling/trunk/bundles/extensions/event/src: main/java/org/apache/sling/event/impl/jobs/ main/java/org/apache/sling/event/impl/jobs/console/ main/java/org/apache/sling/event/impl/topology/ test/java/org/apache/sling/event/impl/j...

Author: cziegeler
Date: Wed Oct 15 07:18:17 2014
New Revision: 1631960

URL: http://svn.apache.org/r1631960
Log:
SLING-4048 : Avoid keeping jobs in memory. Move topology handling to own handler service

Added:
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/topology/
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/topology/TopologyAware.java   (with props)
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/topology/TopologyCapabilities.java
      - copied, changed from r1631955, sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/TopologyCapabilities.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/topology/TopologyHandler.java   (with props)
Removed:
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/TopologyCapabilities.java
Modified:
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobConsumerManager.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobManagerConfiguration.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobManagerImpl.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobSchedulerImpl.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/MaintenanceTask.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/console/InventoryPlugin.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/console/WebConsolePlugin.java
    sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/InstanceDescriptionComparatorTest.java

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobConsumerManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobConsumerManager.java?rev=1631960&r1=1631959&r2=1631960&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobConsumerManager.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobConsumerManager.java Wed Oct 15 07:18:17 2014
@@ -42,6 +42,7 @@ import org.apache.sling.commons.osgi.Pro
 import org.apache.sling.discovery.PropertyProvider;
 import org.apache.sling.event.impl.support.TopicMatcher;
 import org.apache.sling.event.impl.support.TopicMatcherHelper;
+import org.apache.sling.event.impl.topology.TopologyCapabilities;
 import org.apache.sling.event.jobs.Job;
 import org.apache.sling.event.jobs.consumer.JobConsumer;
 import org.apache.sling.event.jobs.consumer.JobConsumer.JobResult;

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobManagerConfiguration.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobManagerConfiguration.java?rev=1631960&r1=1631959&r2=1631960&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobManagerConfiguration.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobManagerConfiguration.java Wed Oct 15 07:18:17 2014
@@ -34,6 +34,7 @@ import org.apache.sling.api.resource.Per
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.ResourceResolverFactory;
 import org.apache.sling.commons.osgi.PropertiesUtil;
+import org.apache.sling.event.impl.EnvironmentComponent;
 import org.apache.sling.event.impl.support.Environment;
 import org.apache.sling.event.impl.support.ResourceHelper;
 import org.slf4j.Logger;
@@ -132,6 +133,10 @@ public class JobManagerConfiguration {
     /** The resource path where scheduled jobs are stored - ending with a slash. */
     private String scheduledJobsPathWithSlash;
 
+    /** The environment component. */
+    @Reference
+    private EnvironmentComponent environment;
+
     @Reference
     private ResourceResolverFactory resourceResolverFactory;
 

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobManagerImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobManagerImpl.java?rev=1631960&r1=1631959&r2=1631960&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobManagerImpl.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobManagerImpl.java Wed Oct 15 07:18:17 2014
@@ -49,12 +49,7 @@ import org.apache.sling.api.resource.Res
 import org.apache.sling.api.resource.ValueMap;
 import org.apache.sling.commons.scheduler.Scheduler;
 import org.apache.sling.commons.threads.ThreadPoolManager;
-import org.apache.sling.discovery.TopologyEvent;
-import org.apache.sling.discovery.TopologyEvent.Type;
-import org.apache.sling.discovery.TopologyEventListener;
-import org.apache.sling.discovery.TopologyView;
 import org.apache.sling.event.EventUtil;
-import org.apache.sling.event.impl.EnvironmentComponent;
 import org.apache.sling.event.impl.jobs.config.InternalQueueConfiguration;
 import org.apache.sling.event.impl.jobs.config.QueueConfigurationManager;
 import org.apache.sling.event.impl.jobs.config.QueueConfigurationManager.QueueInfo;
@@ -69,6 +64,9 @@ import org.apache.sling.event.impl.jobs.
 import org.apache.sling.event.impl.support.Environment;
 import org.apache.sling.event.impl.support.ResourceHelper;
 import org.apache.sling.event.impl.support.ScheduleInfoImpl;
+import org.apache.sling.event.impl.topology.TopologyAware;
+import org.apache.sling.event.impl.topology.TopologyCapabilities;
+import org.apache.sling.event.impl.topology.TopologyHandler;
 import org.apache.sling.event.jobs.Job;
 import org.apache.sling.event.jobs.JobBuilder;
 import org.apache.sling.event.jobs.JobManager;
@@ -93,7 +91,7 @@ import org.slf4j.LoggerFactory;
  * Implementation of the job manager.
  */
 @Component(immediate=true)
-@Service(value={JobManager.class, EventHandler.class, TopologyEventListener.class, Runnable.class})
+@Service(value={JobManager.class, EventHandler.class, Runnable.class})
 @Properties({
     @Property(name="scheduler.period", longValue=60, propertyPrivate=true),
     @Property(name="scheduler.concurrent", boolValue=false, propertyPrivate=true),
@@ -108,14 +106,13 @@ import org.slf4j.LoggerFactory;
 })
 public class JobManagerImpl
     extends StatisticsImpl
-    implements JobManager, EventHandler, TopologyEventListener, Runnable {
+    implements JobManager, EventHandler, Runnable, TopologyAware {
 
     /** Default logger. */
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
-    /** The environment component. */
     @Reference
-    private EnvironmentComponent environment;
+    private TopologyHandler topologyHandler;
 
     @Reference
     private EventAdmin eventAdmin;
@@ -178,6 +175,7 @@ public class JobManagerImpl
         this.maintenanceTask = new MaintenanceTask(this.configuration);
         this.backgroundLoader = new BackgroundLoader(this, this.configuration);
 
+        this.topologyHandler.addListener(this);
         logger.info("Apache Sling Job Manager started on instance {}", Environment.APPLICATION_ID);
     }
 
@@ -187,6 +185,8 @@ public class JobManagerImpl
     @Deactivate
     protected void deactivate() {
         logger.info("Apache Sling Job Manager stopping on instance {}", Environment.APPLICATION_ID);
+        this.topologyHandler.removeListener(this);
+
         this.jobScheduler.deactivate();
 
         this.backgroundLoader.deactivate();
@@ -490,48 +490,24 @@ public class JobManagerImpl
             }
         }
 
-        // deactivate old capabilities - this stops all background processes
-        if ( this.topologyCapabilities != null ) {
-            this.topologyCapabilities.deactivate();
-        }
         this.topologyCapabilities = null;
     }
 
-    private void startProcessing(final TopologyView view) {
+    private void startProcessing(final TopologyCapabilities caps) {
         // create new capabilities and update view
-        this.topologyCapabilities = new TopologyCapabilities(view, this.configuration);
+        this.topologyCapabilities = caps;
 
         this.backgroundLoader.start();
     }
 
-    /**
-     * @see org.apache.sling.discovery.TopologyEventListener#handleTopologyEvent(org.apache.sling.discovery.TopologyEvent)
-     */
     @Override
-    public void handleTopologyEvent(final TopologyEvent event) {
-        this.logger.info("Received topology event {}", event);
-
-        // check if there is a change of properties which doesn't affect us
-        if ( event.getType() == Type.PROPERTIES_CHANGED ) {
-            final Map<String, String> newAllInstances = TopologyCapabilities.getAllInstancesMap(event.getNewView());
-            if ( this.topologyCapabilities != null && this.topologyCapabilities.isSame(newAllInstances) ) {
-                logger.info("No changes in capabilities - ignoring event");
-                return;
-            }
-        }
-
-        if ( event.getType() == Type.TOPOLOGY_CHANGING ) {
-           this.stopProcessing();
-
-        } else if ( event.getType() == Type.TOPOLOGY_INIT
-            || event.getType() == Type.TOPOLOGY_CHANGED
-            || event.getType() == Type.PROPERTIES_CHANGED ) {
-
+    public void topologyChanged(final TopologyCapabilities caps) {
+        if ( caps == null ) {
             this.stopProcessing();
-
-            this.startProcessing(event.getNewView());
+        } else {
+            this.startProcessing(caps);
         }
-        this.jobScheduler.handleTopologyEvent(event);
+        this.jobScheduler.topologyChanged(caps);
     }
 
     /**

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobSchedulerImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobSchedulerImpl.java?rev=1631960&r1=1631959&r2=1631960&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobSchedulerImpl.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobSchedulerImpl.java Wed Oct 15 07:18:17 2014
@@ -46,12 +46,11 @@ import org.apache.sling.api.resource.Val
 import org.apache.sling.commons.scheduler.JobContext;
 import org.apache.sling.commons.scheduler.ScheduleOptions;
 import org.apache.sling.commons.scheduler.Scheduler;
-import org.apache.sling.discovery.TopologyEvent;
-import org.apache.sling.discovery.TopologyEvent.Type;
-import org.apache.sling.discovery.TopologyEventListener;
 import org.apache.sling.event.impl.support.Environment;
 import org.apache.sling.event.impl.support.ResourceHelper;
 import org.apache.sling.event.impl.support.ScheduleInfoImpl;
+import org.apache.sling.event.impl.topology.TopologyAware;
+import org.apache.sling.event.impl.topology.TopologyCapabilities;
 import org.apache.sling.event.jobs.Job;
 import org.apache.sling.event.jobs.JobBuilder;
 import org.apache.sling.event.jobs.ScheduleInfo;
@@ -68,7 +67,7 @@ import org.slf4j.LoggerFactory;
  *
  */
 public class JobSchedulerImpl
-    implements EventHandler, TopologyEventListener, org.apache.sling.commons.scheduler.Job {
+    implements EventHandler, TopologyAware, org.apache.sling.commons.scheduler.Job {
 
     private static final String TOPIC_READ_JOB = "org/apache/sling/event/impl/jobs/READSCHEDULEDJOB";
 
@@ -592,17 +591,14 @@ public class JobSchedulerImpl
         }
     }
 
-    /**
-     * @see org.apache.sling.discovery.TopologyEventListener#handleTopologyEvent(org.apache.sling.discovery.TopologyEvent)
-     */
     @Override
-    public void handleTopologyEvent(final TopologyEvent event) {
-        if ( event.getType() == Type.TOPOLOGY_CHANGING ) {
+    public void topologyChanged(final TopologyCapabilities caps) {
+        if ( caps == null ) {
             this.active = false;
             this.stopScheduling();
-        } else if ( event.getType() == Type.TOPOLOGY_CHANGED || event.getType() == Type.TOPOLOGY_INIT ) {
+        } else {
             final boolean previouslyActive = this.active;
-            this.active = event.getNewView().getLocalInstance().isLeader();
+            this.active = caps.isLeader();
             if ( this.active && !previouslyActive ) {
                 this.startScheduling();
             }

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/MaintenanceTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/MaintenanceTask.java?rev=1631960&r1=1631959&r2=1631960&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/MaintenanceTask.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/MaintenanceTask.java Wed Oct 15 07:18:17 2014
@@ -38,6 +38,7 @@ import org.apache.sling.event.impl.jobs.
 import org.apache.sling.event.impl.support.BatchResourceRemover;
 import org.apache.sling.event.impl.support.Environment;
 import org.apache.sling.event.impl.support.ResourceHelper;
+import org.apache.sling.event.impl.topology.TopologyCapabilities;
 import org.apache.sling.event.jobs.Job;
 import org.apache.sling.event.jobs.QueueConfiguration;
 import org.slf4j.Logger;

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/console/InventoryPlugin.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/console/InventoryPlugin.java?rev=1631960&r1=1631959&r2=1631960&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/console/InventoryPlugin.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/console/InventoryPlugin.java Wed Oct 15 07:18:17 2014
@@ -39,9 +39,9 @@ import org.apache.felix.scr.annotations.
 import org.apache.sling.discovery.InstanceDescription;
 import org.apache.sling.event.impl.jobs.JobConsumerManager;
 import org.apache.sling.event.impl.jobs.JobManagerImpl;
-import org.apache.sling.event.impl.jobs.TopologyCapabilities;
 import org.apache.sling.event.impl.jobs.config.InternalQueueConfiguration;
 import org.apache.sling.event.impl.jobs.config.QueueConfigurationManager;
+import org.apache.sling.event.impl.topology.TopologyCapabilities;
 import org.apache.sling.event.jobs.JobManager;
 import org.apache.sling.event.jobs.Queue;
 import org.apache.sling.event.jobs.QueueConfiguration;

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/console/WebConsolePlugin.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/console/WebConsolePlugin.java?rev=1631960&r1=1631959&r2=1631960&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/console/WebConsolePlugin.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/console/WebConsolePlugin.java Wed Oct 15 07:18:17 2014
@@ -40,9 +40,9 @@ import org.apache.felix.scr.annotations.
 import org.apache.sling.discovery.InstanceDescription;
 import org.apache.sling.event.impl.jobs.JobConsumerManager;
 import org.apache.sling.event.impl.jobs.JobManagerImpl;
-import org.apache.sling.event.impl.jobs.TopologyCapabilities;
 import org.apache.sling.event.impl.jobs.config.InternalQueueConfiguration;
 import org.apache.sling.event.impl.jobs.config.QueueConfigurationManager;
+import org.apache.sling.event.impl.topology.TopologyCapabilities;
 import org.apache.sling.event.jobs.Job;
 import org.apache.sling.event.jobs.JobManager;
 import org.apache.sling.event.jobs.Queue;

Added: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/topology/TopologyAware.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/topology/TopologyAware.java?rev=1631960&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/topology/TopologyAware.java (added)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/topology/TopologyAware.java Wed Oct 15 07:18:17 2014
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.event.impl.topology;
+
+
+public interface TopologyAware {
+
+    void topologyChanged(final TopologyCapabilities caps);
+}

Propchange: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/topology/TopologyAware.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/topology/TopologyAware.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/topology/TopologyAware.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/topology/TopologyCapabilities.java (from r1631955, sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/TopologyCapabilities.java)
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/topology/TopologyCapabilities.java?p2=sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/topology/TopologyCapabilities.java&p1=sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/TopologyCapabilities.java&r1=1631955&r2=1631960&rev=1631960&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/TopologyCapabilities.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/topology/TopologyCapabilities.java Wed Oct 15 07:18:17 2014
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.sling.event.impl.jobs;
+package org.apache.sling.event.impl.topology;
 
 import java.util.ArrayList;
 import java.util.Collections;
@@ -28,6 +28,8 @@ import java.util.TreeMap;
 
 import org.apache.sling.discovery.InstanceDescription;
 import org.apache.sling.discovery.TopologyView;
+import org.apache.sling.event.impl.jobs.JobImpl;
+import org.apache.sling.event.impl.jobs.JobManagerConfiguration;
 import org.apache.sling.event.impl.jobs.config.QueueConfigurationManager.QueueInfo;
 import org.apache.sling.event.impl.support.Environment;
 import org.apache.sling.event.jobs.QueueConfiguration;

Added: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/topology/TopologyHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/topology/TopologyHandler.java?rev=1631960&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/topology/TopologyHandler.java (added)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/topology/TopologyHandler.java Wed Oct 15 07:18:17 2014
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.event.impl.topology;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.discovery.TopologyEvent;
+import org.apache.sling.discovery.TopologyEvent.Type;
+import org.apache.sling.discovery.TopologyEventListener;
+import org.apache.sling.discovery.TopologyView;
+import org.apache.sling.event.impl.jobs.JobManagerConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The topology handler listens for topology events
+ */
+@Component(immediate=true)
+@Service(value={TopologyHandler.class, TopologyEventListener.class})
+public class TopologyHandler
+    implements TopologyEventListener {
+
+    /** Logger. */
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+    /** List of topology awares. */
+    private final List<TopologyAware> listeners = new ArrayList<TopologyAware>();
+
+    @Reference
+    private JobManagerConfiguration configuration;
+
+    /** The topology capabilities. */
+    private volatile TopologyCapabilities topologyCapabilities;
+
+    private void stopProcessing() {
+        // deactivate old capabilities - this stops all background processes
+        if ( this.topologyCapabilities != null ) {
+            this.topologyCapabilities.deactivate();
+        }
+        this.topologyCapabilities = null;
+    }
+
+    private void startProcessing(final TopologyView view) {
+        // create new capabilities and update view
+        this.topologyCapabilities = new TopologyCapabilities(view, this.configuration);
+    }
+
+    /**
+     * @see org.apache.sling.discovery.TopologyEventListener#handleTopologyEvent(org.apache.sling.discovery.TopologyEvent)
+     */
+    @Override
+    public void handleTopologyEvent(final TopologyEvent event) {
+        this.logger.debug("Received topology event {}", event);
+
+        // check if there is a change of properties which doesn't affect us
+        if ( event.getType() == Type.PROPERTIES_CHANGED ) {
+            final Map<String, String> newAllInstances = TopologyCapabilities.getAllInstancesMap(event.getNewView());
+            if ( this.topologyCapabilities != null && this.topologyCapabilities.isSame(newAllInstances) ) {
+                logger.debug("No changes in capabilities - ignoring event");
+                return;
+            }
+        }
+
+        synchronized ( this.listeners ) {
+
+            if ( event.getType() == Type.TOPOLOGY_CHANGING ) {
+               this.stopProcessing();
+
+               for(final TopologyAware l : this.listeners) {
+                   l.topologyChanged(this.topologyCapabilities);
+               }
+            } else if ( event.getType() == Type.TOPOLOGY_INIT
+                || event.getType() == Type.TOPOLOGY_CHANGED
+                || event.getType() == Type.PROPERTIES_CHANGED ) {
+
+                this.stopProcessing();
+
+                this.startProcessing(event.getNewView());
+
+                for(final TopologyAware l : this.listeners) {
+                    l.topologyChanged(this.topologyCapabilities);
+                }
+            }
+
+        }
+    }
+
+    public void addListener(final TopologyAware service) {
+        synchronized ( this.listeners ) {
+            this.listeners.add(service);
+            service.topologyChanged(this.topologyCapabilities);
+        }
+    }
+
+    public void removeListener(final TopologyAware service) {
+        synchronized ( this.listeners )  {
+            this.listeners.remove(service);
+        }
+    }
+}

Propchange: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/topology/TopologyHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/topology/TopologyHandler.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/topology/TopologyHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/InstanceDescriptionComparatorTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/InstanceDescriptionComparatorTest.java?rev=1631960&r1=1631959&r2=1631960&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/InstanceDescriptionComparatorTest.java (original)
+++ sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/InstanceDescriptionComparatorTest.java Wed Oct 15 07:18:17 2014
@@ -27,6 +27,7 @@ import java.util.Map;
 
 import org.apache.sling.discovery.ClusterView;
 import org.apache.sling.discovery.InstanceDescription;
+import org.apache.sling.event.impl.topology.TopologyCapabilities;
 
 public class InstanceDescriptionComparatorTest {