/*
 * 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.stratos.autoscaler.event.publisher;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.stratos.messaging.broker.publish.EventPublisher;
import org.apache.stratos.messaging.broker.publish.EventPublisherPool;
import org.apache.stratos.messaging.event.Event;
import org.apache.stratos.messaging.event.instance.notifier.InstanceCleanupClusterEvent;
import org.apache.stratos.messaging.event.instance.notifier.InstanceCleanupMemberEvent;
import org.apache.stratos.messaging.util.Util;

public class InstanceNotificationPublisher {
    private static final Log log = LogFactory.getLog(InstanceNotificationPublisher.class);

    private static void publish(Event event) {
        String topic = Util.getMessageTopicName(event);

        EventPublisher instanceNotifyingEvent = EventPublisherPool.
                                getPublisher(topic);
        instanceNotifyingEvent.publish(event);
    }

    public static void sendInstanceCleanupEventForCluster(String clusterId, String instanceId) {
        log.info(String.format("Publishing Instance Cleanup Event: [cluster] %s", clusterId));
        publish(new InstanceCleanupClusterEvent(clusterId, instanceId));
    }

    /**
     * Publishing the instance termination notification to the instances
     *
     * @param memberId
     */
    public void sendInstanceCleanupEventForMember(String memberId) {
        log.info(String.format("Publishing Instance Cleanup Event: [member] %s", memberId));
        publish(new InstanceCleanupMemberEvent(memberId));
    }
}

@@ -1487,24 +1487,549 @@
 er.class);%0A%0A
+    /* An instance of InstanceNotificationPublisher is created when the class is loaded.%0A     * Since the class is loaded only once, it is guaranteed that an object of%0A     * InstanceNotificationPublisher is created only once. Hence it is singleton.%0A     */%0A    private static class InstanceHolder %7B%0A        private static final InstanceNotificationPublisher INSTANCE = new InstanceNotificationPublisher();%0A    %7D%0A%0A    public static InstanceNotificationPublisher getInstance() %7B%0A        return InstanceHolder.INSTANCE;%0A    %7D%0A%0A
     private 
@@ -2059,24 +2059,24 @@
 nt event) %7B%0A
-
         Stri
@@ -2307,21 +2307,27 @@
 public s
-tatic
+ynchronized
  void se
@@ -2688,24 +2688,24 @@
 rId%0A     */%0A
-
     public v
@@ -2703,16 +2703,29 @@
  public 
+synchronized 
 void sen

Make InstanceNotificationPublisher singleton