Return-Path: X-Original-To: apmail-sling-commits-archive@www.apache.org Delivered-To: apmail-sling-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id AD85EC1CA for ; Mon, 3 Jun 2013 14:17:35 +0000 (UTC) Received: (qmail 9713 invoked by uid 500); 3 Jun 2013 14:17:35 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 9633 invoked by uid 500); 3 Jun 2013 14:17:34 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 9624 invoked by uid 99); 3 Jun 2013 14:17:33 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Jun 2013 14:17:33 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Jun 2013 14:17:31 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 6BF1923888E7; Mon, 3 Jun 2013 14:17:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@sling.apache.org From: stefanegli@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130603141711.6BF1923888E7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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();