sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1470555 - in /sling/trunk/contrib/extensions/discovery/impl: ./ src/main/java/org/apache/sling/discovery/impl/ src/test/java/org/apache/sling/discovery/impl/cluster/ src/test/java/org/apache/sling/discovery/impl/cluster/helpers/
Date Mon, 22 Apr 2013 14:48:05 GMT
Author: cziegeler
Date: Mon Apr 22 14:48:05 2013
New Revision: 1470555

URL: http://svn.apache.org/r1470555
Log:
SLING-2827 :  discovery.impl: a resource based implementation of the discovery.api . Apply
another patch from Stefan Egli (activate and changing patch)

Modified:
    sling/trunk/contrib/extensions/discovery/impl/pom.xml
    sling/trunk/contrib/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/DiscoveryServiceImpl.java
    sling/trunk/contrib/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/TopologyWebConsolePlugin.java
    sling/trunk/contrib/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/cluster/ClusterTest.java
    sling/trunk/contrib/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/cluster/helpers/AcceptsMultiple.java

Modified: sling/trunk/contrib/extensions/discovery/impl/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/discovery/impl/pom.xml?rev=1470555&r1=1470554&r2=1470555&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/discovery/impl/pom.xml (original)
+++ sling/trunk/contrib/extensions/discovery/impl/pom.xml Mon Apr 22 14:48:05 2013
@@ -29,7 +29,7 @@
 
     <artifactId>org.apache.sling.discovery.impl</artifactId>
     <packaging>bundle</packaging>
-    <version>0.0.6-SNAPSHOT</version>
+    <version>0.1.0-SNAPSHOT</version>
 
     <name>Apache Sling Resource-Based Discovery Service</name>
     <description>Implementation of Apache Sling Discovery based on Sling Resource providing
a ClusterView through resource-clustering (eg jackrabbit clustering) and a TopologyView through
HTTP POST heartbeats announcing sub-topologies to each other.</description>

Modified: sling/trunk/contrib/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/DiscoveryServiceImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/DiscoveryServiceImpl.java?rev=1470555&r1=1470554&r2=1470555&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/DiscoveryServiceImpl.java
(original)
+++ sling/trunk/contrib/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/DiscoveryServiceImpl.java
Mon Apr 22 14:48:05 2013
@@ -146,18 +146,18 @@ public class DiscoveryServiceImpl implem
 
         final TopologyEventListener[] registeredServices;
         synchronized (lock) {
-            activated = true;
             registeredServices = this.eventListeners;
             doUpdateProperties();
 
+            TopologyViewImpl newView = (TopologyViewImpl) getTopology();
+            TopologyEvent event = new TopologyEvent(Type.TOPOLOGY_INIT, null,
+                    newView);
+            for (final TopologyEventListener da : registeredServices) {
+                sendTopologyEvent(da, event);
+            }
+            activated = true;
+            oldView = newView;
         }
-        TopologyViewImpl newView = (TopologyViewImpl) getTopology();
-        TopologyEvent event = new TopologyEvent(Type.TOPOLOGY_INIT, null,
-                newView);
-        for (final TopologyEventListener da : registeredServices) {
-            da.handleTopologyEvent(event);
-        }
-        oldView = newView;
 
         URL topologyConnectorURL = config.getTopologyConnectorURL();
         if (topologyConnectorURL != null) {
@@ -168,6 +168,15 @@ public class DiscoveryServiceImpl implem
         logger.debug("DiscoveryServiceImpl activated.");
     }
 
+    private void sendTopologyEvent(TopologyEventListener da, TopologyEvent event) {
+        logger.debug("sendTopologyEvent: sending topologyEvent "+event+", to "+da);
+        try{
+            da.handleTopologyEvent(event);
+        } catch(Exception e) {
+            logger.warn("sendTopologyEvent: handler threw exception. handler: "+da+", exception:
"+e, e);
+        }
+    }
+
     /**
      * Deactivate this service
      */
@@ -181,23 +190,23 @@ public class DiscoveryServiceImpl implem
     /**
      * bind a discovery aware
      */
-    protected void bindTopologyEventListener(final TopologyEventListener clusterAware) {
+    protected void bindTopologyEventListener(final TopologyEventListener eventListener) {
 
         logger.debug("bindTopologyEventListener: Binding TopologyEventListener {}",
-                clusterAware);
+                eventListener);
 
         boolean activated = false;
         synchronized (lock) {
             List<TopologyEventListener> currentList = new ArrayList<TopologyEventListener>(
                     Arrays.asList(eventListeners));
-            currentList.add(clusterAware);
+            currentList.add(eventListener);
             this.eventListeners = currentList
                     .toArray(new TopologyEventListener[currentList.size()]);
             activated = this.activated;
         }
 
         if (activated) {
-            clusterAware.handleTopologyEvent(new TopologyEvent(
+            sendTopologyEvent(eventListener, new TopologyEvent(
                     Type.TOPOLOGY_INIT, null, getTopology()));
         }
     }
@@ -417,6 +426,12 @@ public class DiscoveryServiceImpl implem
      */
     private void handlePotentialTopologyChange() {
         synchronized (lock) {
+            if (!activated) {
+                // ignore this call then - an early call to issue
+                // a topologyevent before even activated
+                logger.debug("handlePotentialTopologyChange: ignoring early change before
activate finished.");
+                return;
+            }
             if (oldView == null) {
                 throw new IllegalStateException("oldView must not be null");
             }
@@ -430,9 +445,20 @@ public class DiscoveryServiceImpl implem
             }
 
             oldView.markOld();
-            for (final TopologyEventListener da : eventListeners) {
-                da.handleTopologyEvent(new TopologyEvent(difference, oldView,
-                        newView));
+            if (difference!=Type.TOPOLOGY_CHANGED) {
+                for (final TopologyEventListener da : eventListeners) {
+                    sendTopologyEvent(da, new TopologyEvent(difference, oldView,
+                            newView));
+                }
+            } else {
+                for (final TopologyEventListener da : eventListeners) {
+                    sendTopologyEvent(da, new TopologyEvent(Type.TOPOLOGY_CHANGING, oldView,
+                            null));
+                }
+                for (final TopologyEventListener da : eventListeners) {
+                    sendTopologyEvent(da, new TopologyEvent(Type.TOPOLOGY_CHANGED, oldView,
+                            newView));
+                }
             }
             this.oldView = newView;
         }

Modified: sling/trunk/contrib/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/TopologyWebConsolePlugin.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/TopologyWebConsolePlugin.java?rev=1470555&r1=1470554&r2=1470555&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/TopologyWebConsolePlugin.java
(original)
+++ sling/trunk/contrib/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/TopologyWebConsolePlugin.java
Mon Apr 22 14:48:05 2013
@@ -651,6 +651,9 @@ public class TopologyWebConsolePlugin ex
             addEventLog(event.getType(),
                     "view: " + shortViewInfo(event.getNewView()) + ". "
                             + details);
+        } else if (event.getType() == Type.TOPOLOGY_CHANGING) {
+            addEventLog(event.getType(),
+                    "old view: " + shortViewInfo(event.getOldView()));
         } else {
             if (event.getOldView() == null) {
                 addEventLog(event.getType(),

Modified: sling/trunk/contrib/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/cluster/ClusterTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/cluster/ClusterTest.java?rev=1470555&r1=1470554&r2=1470555&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/cluster/ClusterTest.java
(original)
+++ sling/trunk/contrib/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/cluster/ClusterTest.java
Mon Apr 22 14:48:05 2013
@@ -185,6 +185,7 @@ public class ClusterTest {
         AcceptsMultiple acceptsMultiple = new AcceptsMultiple(
                 Type.TOPOLOGY_CHANGING, Type.TOPOLOGY_CHANGED);
         assertingTopologyEventListener.addExpected(acceptsMultiple);
+        assertingTopologyEventListener.addExpected(acceptsMultiple);
         instance3 = Instance.newClusterInstance("thirdInstance", instance1,
                 false);
         instance1.runHeartbeatOnce();
@@ -195,6 +196,7 @@ public class ClusterTest {
         instance2.runHeartbeatOnce();
         instance3.runHeartbeatOnce();
         Thread.sleep(2000);
+        assertEquals(1, acceptsMultiple.getEventCnt(Type.TOPOLOGY_CHANGING));
         assertEquals(1, acceptsMultiple.getEventCnt(Type.TOPOLOGY_CHANGED));
     }
 

Modified: sling/trunk/contrib/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/cluster/helpers/AcceptsMultiple.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/cluster/helpers/AcceptsMultiple.java?rev=1470555&r1=1470554&r2=1470555&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/cluster/helpers/AcceptsMultiple.java
(original)
+++ sling/trunk/contrib/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/cluster/helpers/AcceptsMultiple.java
Mon Apr 22 14:48:05 2013
@@ -54,7 +54,12 @@ public class AcceptsMultiple implements 
     }
 
     public synchronized int getEventCnt(Type type) {
-        return counts.get(type);
+        Integer i = counts.get(type);
+        if (i!=null) {
+            return i;
+        } else {
+            return 0;
+        }
     }
 
 }



Mime
View raw message