You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by la...@apache.org on 2014/12/09 11:24:18 UTC
[2/2] stratos git commit: Make InstanceNotificationPublisher singleton
Make InstanceNotificationPublisher singleton
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/5ee17362
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/5ee17362
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/5ee17362
Branch: refs/heads/4.1.0-test
Commit: 5ee17362a3d63fc30cdc98acdac4035c62640497
Parents: 0a07475
Author: Lahiru Sandaruwan <la...@apache.org>
Authored: Tue Dec 9 15:54:35 2014 +0530
Committer: Lahiru Sandaruwan <la...@apache.org>
Committed: Tue Dec 9 15:55:47 2014 +0530
----------------------------------------------------------------------
.../publisher/InstanceNotificationPublisher.java | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/5ee17362/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/publisher/InstanceNotificationPublisher.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/publisher/InstanceNotificationPublisher.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/publisher/InstanceNotificationPublisher.java
index ea68f32..34a9efa 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/publisher/InstanceNotificationPublisher.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/publisher/InstanceNotificationPublisher.java
@@ -31,6 +31,18 @@ import org.apache.stratos.messaging.util.Util;
public class InstanceNotificationPublisher {
private static final Log log = LogFactory.getLog(InstanceNotificationPublisher.class);
+ /* An instance of InstanceNotificationPublisher is created when the class is loaded.
+ * Since the class is loaded only once, it is guaranteed that an object of
+ * InstanceNotificationPublisher is created only once. Hence it is singleton.
+ */
+ private static class InstanceHolder {
+ private static final InstanceNotificationPublisher INSTANCE = new InstanceNotificationPublisher();
+ }
+
+ public static InstanceNotificationPublisher getInstance() {
+ return InstanceHolder.INSTANCE;
+ }
+
private static void publish(Event event) {
String topic = Util.getMessageTopicName(event);
@@ -39,7 +51,7 @@ public class InstanceNotificationPublisher {
instanceNotifyingEvent.publish(event);
}
- public static void sendInstanceCleanupEventForCluster(String clusterId, String instanceId) {
+ public synchronized void sendInstanceCleanupEventForCluster(String clusterId, String instanceId) {
log.info(String.format("Publishing Instance Cleanup Event: [cluster] %s", clusterId));
publish(new InstanceCleanupClusterEvent(clusterId, instanceId));
}
@@ -49,7 +61,7 @@ public class InstanceNotificationPublisher {
*
* @param memberId
*/
- public void sendInstanceCleanupEventForMember(String memberId) {
+ public synchronized void sendInstanceCleanupEventForMember(String memberId) {
log.info(String.format("Publishing Instance Cleanup Event: [member] %s", memberId));
publish(new InstanceCleanupMemberEvent(memberId));
}