incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stefane...@apache.org
Subject svn commit: r1489000 - /sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/common/heartbeat/HeartbeatHandler.java
Date Mon, 03 Jun 2013 14:17:11 GMT
Author: stefanegli
Date: Mon Jun  3 14:17:11 2013
New Revision: 1489000

URL: http://svn.apache.org/r1489000
Log:
SLING-2895 : avoid heartbeats after deactivation

Modified:
    sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/common/heartbeat/HeartbeatHandler.java

Modified: sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/common/heartbeat/HeartbeatHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/common/heartbeat/HeartbeatHandler.java?rev=1489000&r1=1488999&r2=1489000&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/common/heartbeat/HeartbeatHandler.java
(original)
+++ sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/common/heartbeat/HeartbeatHandler.java
Mon Jun  3 14:17:11 2013
@@ -109,20 +109,29 @@ public class HeartbeatHandler implements
     /** SLING-2892: remember the value of the heartbeat this instance has written the last
time **/
     private Calendar lastHeartbeatWritten = null;
     
+    /** SLING-2895: avoid heartbeats after deactivation **/
+    private boolean activated = false;
+    
     @Activate
-    protected void activate(ComponentContext context) {
-        slingId = slingSettingsService.getSlingId();
-        // on activate the resetLeaderElectionId is set to true to ensure that
-        // the 'leaderElectionId' property is reset on next heartbeat issuance.
-        // the idea being that a node which leaves the cluster should not
-        // become leader on next join - and by resetting the leaderElectionId
-        // to the current time, this is ensured.
-        resetLeaderElectionId = true;
+    protected synchronized void activate(ComponentContext context) {
+    	synchronized(lock) {
+	        slingId = slingSettingsService.getSlingId();
+	        // on activate the resetLeaderElectionId is set to true to ensure that
+	        // the 'leaderElectionId' property is reset on next heartbeat issuance.
+	        // the idea being that a node which leaves the cluster should not
+	        // become leader on next join - and by resetting the leaderElectionId
+	        // to the current time, this is ensured.
+	        resetLeaderElectionId = true;
+	        activated = true;
+    	}
     }
 
     @Deactivate
     protected void deactivate() {
-        scheduler.removeJob(NAME);
+    	synchronized(lock) {
+	    	activated = false;
+    	}
+    	scheduler.removeJob(NAME);
     }
 
     /**
@@ -152,6 +161,11 @@ public class HeartbeatHandler implements
 
     public void run() {
         synchronized(lock) {
+        	if (!activated) {
+        		// SLING:2895: avoid heartbeats if not activated
+        		return;
+        	}
+        	
             // issue a heartbeat
             issueHeartbeat();
     



Mime
View raw message