You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by re...@apache.org on 2014/12/05 14:40:27 UTC

[1/5] stratos git commit: adding instance prefix to events, , processor and listener

Repository: stratos
Updated Branches:
  refs/heads/master 5f72e3d1c -> 3bd20e5ee


http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterInActivateProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterInActivateProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterInActivateProcessor.java
deleted file mode 100644
index 01dfe0c..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterInActivateProcessor.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * 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.messaging.message.processor.topology;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.messaging.domain.instance.ClusterInstance;
-import org.apache.stratos.messaging.domain.topology.Cluster;
-import org.apache.stratos.messaging.domain.topology.ClusterStatus;
-import org.apache.stratos.messaging.domain.topology.Service;
-import org.apache.stratos.messaging.domain.topology.Topology;
-import org.apache.stratos.messaging.event.topology.ClusterInactivateEvent;
-import org.apache.stratos.messaging.message.filter.topology.TopologyClusterFilter;
-import org.apache.stratos.messaging.message.filter.topology.TopologyServiceFilter;
-import org.apache.stratos.messaging.message.processor.MessageProcessor;
-import org.apache.stratos.messaging.message.processor.topology.updater.TopologyUpdater;
-import org.apache.stratos.messaging.util.Util;
-
-/**
- * This processor will act upon the cluster activated event
- */
-public class ClusterInActivateProcessor extends MessageProcessor {
-    private static final Log log = LogFactory.getLog(ClusterInActivateProcessor.class);
-    private MessageProcessor nextProcessor;
-
-    @Override
-    public void setNext(MessageProcessor nextProcessor) {
-        this.nextProcessor = nextProcessor;
-    }
-
-    @Override
-    public boolean process(String type, String message, Object object) {
-
-        Topology topology = (Topology) object;
-
-        if (ClusterInactivateEvent.class.getName().equals(type)) {
-            // Return if topology has not been initialized
-            if (!topology.isInitialized()) {
-                return false;
-            }
-
-            // Parse complete message and build event
-            ClusterInactivateEvent event = (ClusterInactivateEvent) Util.
-                    jsonToObject(message, ClusterInactivateEvent.class);
-
-            TopologyUpdater.acquireWriteLockForCluster(event.getServiceName(), event.getClusterId());
-            try {
-                return doProcess(event, topology);
-
-            } finally {
-                TopologyUpdater.releaseWriteLockForCluster(event.getServiceName(), event.getClusterId());
-            }
-
-        } else {
-            if (nextProcessor != null) {
-                // ask the next processor to take care of the message.
-                return nextProcessor.process(type, message, topology);
-            } else {
-                throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message));
-            }
-        }
-    }
-
-    private boolean doProcess(ClusterInactivateEvent event, Topology topology) {
-// Apply service filter
-        if (TopologyServiceFilter.getInstance().isActive()) {
-            if (TopologyServiceFilter.getInstance().serviceNameExcluded(event.getServiceName())) {
-                // Service is excluded, do not update topology or fire event
-                if (log.isDebugEnabled()) {
-                    log.debug(String.format("Service is excluded: [service] %s", event.getServiceName()));
-                }
-                return false;
-            }
-        }
-
-        // Apply cluster filter
-        if (TopologyClusterFilter.getInstance().isActive()) {
-            if (TopologyClusterFilter.getInstance().clusterIdExcluded(event.getClusterId())) {
-                // Cluster is excluded, do not update topology or fire event
-                if (log.isDebugEnabled()) {
-                    log.debug(String.format("Cluster is excluded: [cluster] %s", event.getClusterId()));
-                }
-                return false;
-            }
-        }
-
-        // Validate event against the existing topology
-        Service service = topology.getService(event.getServiceName());
-        if (service == null) {
-            if (log.isWarnEnabled()) {
-                log.warn(String.format("Service does not exist: [service] %s",
-                        event.getServiceName()));
-            }
-            return false;
-        }
-        Cluster cluster = service.getCluster(event.getClusterId());
-
-        if (cluster == null) {
-            if (log.isDebugEnabled()) {
-                log.debug(String.format("Cluster not exists in service: [service] %s [cluster] %s", event.getServiceName(),
-                        event.getClusterId()));
-            }
-        } else {
-            // Apply changes to the topology
-            ClusterInstance context = cluster.getInstanceContexts(event.getInstanceId());
-            if(context == null) {
-                log.warn("Cluster Instance Context is not found for [cluster] " +
-                        event.getClusterId() + " [instance-id] " +
-                        event.getInstanceId());
-            }
-            ClusterStatus status = ClusterStatus.Inactive;
-            if (!context.isStateTransitionValid(status)) {
-                log.error("Invalid State Transition from " + context.getStatus() + " to " + status);
-            }
-            context.setStatus(status);
-
-        }
-
-        // Notify event listeners
-        notifyEventListeners(event);
-        return true;
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterInstanceActivatedProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterInstanceActivatedProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterInstanceActivatedProcessor.java
new file mode 100644
index 0000000..1d02c47
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterInstanceActivatedProcessor.java
@@ -0,0 +1,143 @@
+/*
+ * 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.messaging.message.processor.topology;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.messaging.domain.instance.ClusterInstance;
+import org.apache.stratos.messaging.domain.topology.Cluster;
+import org.apache.stratos.messaging.domain.topology.ClusterStatus;
+import org.apache.stratos.messaging.domain.topology.Service;
+import org.apache.stratos.messaging.domain.topology.Topology;
+import org.apache.stratos.messaging.event.topology.ClusterInstanceActivatedEvent;
+import org.apache.stratos.messaging.message.filter.topology.TopologyClusterFilter;
+import org.apache.stratos.messaging.message.filter.topology.TopologyServiceFilter;
+import org.apache.stratos.messaging.message.processor.MessageProcessor;
+import org.apache.stratos.messaging.message.processor.topology.updater.TopologyUpdater;
+import org.apache.stratos.messaging.util.Util;
+
+/**
+ * This processor will act upon the cluster activated event
+ */
+public class ClusterInstanceActivatedProcessor extends MessageProcessor {
+    private static final Log log = LogFactory.getLog(ClusterInstanceActivatedProcessor.class);
+    private MessageProcessor nextProcessor;
+
+    @Override
+    public void setNext(MessageProcessor nextProcessor) {
+        this.nextProcessor = nextProcessor;
+    }
+
+    @Override
+    public boolean process(String type, String message, Object object) {
+
+        Topology topology = (Topology) object;
+
+        if (ClusterInstanceActivatedEvent.class.getName().equals(type)) {
+            // Return if topology has not been initialized
+            if (!topology.isInitialized()) {
+                return false;
+            }
+
+            // Parse complete message and build event
+            ClusterInstanceActivatedEvent event = (ClusterInstanceActivatedEvent) Util.
+                    jsonToObject(message, ClusterInstanceActivatedEvent.class);
+
+            TopologyUpdater.acquireWriteLockForCluster(event.getServiceName(), event.getClusterId());
+            try {
+                return doProcess(event, topology);
+
+            } finally {
+                TopologyUpdater.releaseWriteLockForCluster(event.getServiceName(), event.getClusterId());
+            }
+
+        } else {
+            if (nextProcessor != null) {
+                // ask the next processor to take care of the message.
+                return nextProcessor.process(type, message, topology);
+            } else {
+                throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message));
+            }
+        }
+    }
+
+    private boolean doProcess(ClusterInstanceActivatedEvent event, Topology topology) {
+
+        // Apply service filter
+        if (TopologyServiceFilter.getInstance().isActive()) {
+            if (TopologyServiceFilter.getInstance().serviceNameExcluded(event.getServiceName())) {
+                // Service is excluded, do not update topology or fire event
+                if (log.isDebugEnabled()) {
+                    log.debug(String.format("Service is excluded: [service] %s", event.getServiceName()));
+                }
+                return false;
+            }
+        }
+
+        // Apply cluster filter
+        if (TopologyClusterFilter.getInstance().isActive()) {
+            if (TopologyClusterFilter.getInstance().clusterIdExcluded(event.getClusterId())) {
+                // Cluster is excluded, do not update topology or fire event
+                if (log.isDebugEnabled()) {
+                    log.debug(String.format("Cluster is excluded: [cluster] %s", event.getClusterId()));
+                }
+                return false;
+            }
+        }
+
+        // Validate event against the existing topology
+        Service service = topology.getService(event.getServiceName());
+        if (service == null) {
+            if (log.isWarnEnabled()) {
+                log.warn(String.format("Service does not exist: [service] %s",
+                        event.getServiceName()));
+            }
+            return false;
+        }
+        Cluster cluster = service.getCluster(event.getClusterId());
+
+        if (cluster == null) {
+            if (log.isDebugEnabled()) {
+                log.debug(String.format("Cluster not exists in service: [service] %s [cluster] %s", event.getServiceName(),
+                        event.getClusterId()));
+                return false;
+            }
+        } else {
+            // Apply changes to the topology
+            ClusterInstance context = cluster.getInstanceContexts(event.getInstanceId());
+            if(context == null) {
+                log.warn("Cluster Instance Context is not found for [cluster] " +
+                        event.getClusterId() + " [instance-id] " +
+                        event.getInstanceId());
+                return false;
+            }
+            ClusterStatus status = ClusterStatus.Active;
+            if (!context.isStateTransitionValid(status)) {
+                log.error("Invalid State Transition from " + context.getStatus() + " to " + status);
+            }
+            context.setStatus(status);
+
+        }
+
+        // Notify event listeners
+        notifyEventListeners(event);
+        return true;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterInstanceInActivateProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterInstanceInActivateProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterInstanceInActivateProcessor.java
new file mode 100644
index 0000000..8483fe6
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterInstanceInActivateProcessor.java
@@ -0,0 +1,139 @@
+/*
+ * 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.messaging.message.processor.topology;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.messaging.domain.instance.ClusterInstance;
+import org.apache.stratos.messaging.domain.topology.Cluster;
+import org.apache.stratos.messaging.domain.topology.ClusterStatus;
+import org.apache.stratos.messaging.domain.topology.Service;
+import org.apache.stratos.messaging.domain.topology.Topology;
+import org.apache.stratos.messaging.event.topology.ClusterInstanceInactivateEvent;
+import org.apache.stratos.messaging.message.filter.topology.TopologyClusterFilter;
+import org.apache.stratos.messaging.message.filter.topology.TopologyServiceFilter;
+import org.apache.stratos.messaging.message.processor.MessageProcessor;
+import org.apache.stratos.messaging.message.processor.topology.updater.TopologyUpdater;
+import org.apache.stratos.messaging.util.Util;
+
+/**
+ * This processor will act upon the cluster activated event
+ */
+public class ClusterInstanceInActivateProcessor extends MessageProcessor {
+    private static final Log log = LogFactory.getLog(ClusterInstanceInActivateProcessor.class);
+    private MessageProcessor nextProcessor;
+
+    @Override
+    public void setNext(MessageProcessor nextProcessor) {
+        this.nextProcessor = nextProcessor;
+    }
+
+    @Override
+    public boolean process(String type, String message, Object object) {
+
+        Topology topology = (Topology) object;
+
+        if (ClusterInstanceInactivateEvent.class.getName().equals(type)) {
+            // Return if topology has not been initialized
+            if (!topology.isInitialized()) {
+                return false;
+            }
+
+            // Parse complete message and build event
+            ClusterInstanceInactivateEvent event = (ClusterInstanceInactivateEvent) Util.
+                    jsonToObject(message, ClusterInstanceInactivateEvent.class);
+
+            TopologyUpdater.acquireWriteLockForCluster(event.getServiceName(), event.getClusterId());
+            try {
+                return doProcess(event, topology);
+
+            } finally {
+                TopologyUpdater.releaseWriteLockForCluster(event.getServiceName(), event.getClusterId());
+            }
+
+        } else {
+            if (nextProcessor != null) {
+                // ask the next processor to take care of the message.
+                return nextProcessor.process(type, message, topology);
+            } else {
+                throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message));
+            }
+        }
+    }
+
+    private boolean doProcess(ClusterInstanceInactivateEvent event, Topology topology) {
+// Apply service filter
+        if (TopologyServiceFilter.getInstance().isActive()) {
+            if (TopologyServiceFilter.getInstance().serviceNameExcluded(event.getServiceName())) {
+                // Service is excluded, do not update topology or fire event
+                if (log.isDebugEnabled()) {
+                    log.debug(String.format("Service is excluded: [service] %s", event.getServiceName()));
+                }
+                return false;
+            }
+        }
+
+        // Apply cluster filter
+        if (TopologyClusterFilter.getInstance().isActive()) {
+            if (TopologyClusterFilter.getInstance().clusterIdExcluded(event.getClusterId())) {
+                // Cluster is excluded, do not update topology or fire event
+                if (log.isDebugEnabled()) {
+                    log.debug(String.format("Cluster is excluded: [cluster] %s", event.getClusterId()));
+                }
+                return false;
+            }
+        }
+
+        // Validate event against the existing topology
+        Service service = topology.getService(event.getServiceName());
+        if (service == null) {
+            if (log.isWarnEnabled()) {
+                log.warn(String.format("Service does not exist: [service] %s",
+                        event.getServiceName()));
+            }
+            return false;
+        }
+        Cluster cluster = service.getCluster(event.getClusterId());
+
+        if (cluster == null) {
+            if (log.isDebugEnabled()) {
+                log.debug(String.format("Cluster not exists in service: [service] %s [cluster] %s", event.getServiceName(),
+                        event.getClusterId()));
+            }
+        } else {
+            // Apply changes to the topology
+            ClusterInstance context = cluster.getInstanceContexts(event.getInstanceId());
+            if(context == null) {
+                log.warn("Cluster Instance Context is not found for [cluster] " +
+                        event.getClusterId() + " [instance-id] " +
+                        event.getInstanceId());
+            }
+            ClusterStatus status = ClusterStatus.Inactive;
+            if (!context.isStateTransitionValid(status)) {
+                log.error("Invalid State Transition from " + context.getStatus() + " to " + status);
+            }
+            context.setStatus(status);
+
+        }
+
+        // Notify event listeners
+        notifyEventListeners(event);
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterInstanceTerminatedProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterInstanceTerminatedProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterInstanceTerminatedProcessor.java
new file mode 100644
index 0000000..6f6d335
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterInstanceTerminatedProcessor.java
@@ -0,0 +1,141 @@
+/*
+ * 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.messaging.message.processor.topology;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.messaging.domain.instance.ClusterInstance;
+import org.apache.stratos.messaging.domain.topology.Cluster;
+import org.apache.stratos.messaging.domain.topology.ClusterStatus;
+import org.apache.stratos.messaging.domain.topology.Service;
+import org.apache.stratos.messaging.domain.topology.Topology;
+import org.apache.stratos.messaging.event.topology.ClusterInstanceTerminatedEvent;
+import org.apache.stratos.messaging.message.filter.topology.TopologyClusterFilter;
+import org.apache.stratos.messaging.message.filter.topology.TopologyServiceFilter;
+import org.apache.stratos.messaging.message.processor.MessageProcessor;
+import org.apache.stratos.messaging.message.processor.topology.updater.TopologyUpdater;
+import org.apache.stratos.messaging.util.Util;
+
+/**
+ * This processor will act upon the cluster activated event
+ */
+public class ClusterInstanceTerminatedProcessor extends MessageProcessor {
+    private static final Log log = LogFactory.getLog(ClusterInstanceTerminatedProcessor.class);
+    private MessageProcessor nextProcessor;
+
+    @Override
+    public void setNext(MessageProcessor nextProcessor) {
+        this.nextProcessor = nextProcessor;
+    }
+
+    @Override
+    public boolean process(String type, String message, Object object) {
+
+        Topology topology = (Topology) object;
+
+        if (ClusterInstanceTerminatedEvent.class.getName().equals(type)) {
+            // Return if topology has not been initialized
+            if (!topology.isInitialized()) {
+                return false;
+            }
+
+            // Parse complete message and build event
+            ClusterInstanceTerminatedEvent event = (ClusterInstanceTerminatedEvent) Util.
+                    jsonToObject(message, ClusterInstanceTerminatedEvent.class);
+
+            TopologyUpdater.acquireWriteLockForCluster(event.getServiceName(), event.getClusterId());
+            try {
+                return doProcess(event, topology);
+
+            } finally {
+                TopologyUpdater.releaseWriteLockForCluster(event.getServiceName(), event.getClusterId());
+            }
+
+        } else {
+            if (nextProcessor != null) {
+                // ask the next processor to take care of the message.
+                return nextProcessor.process(type, message, topology);
+            } else {
+                throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message));
+            }
+        }
+    }
+
+    private boolean doProcess(ClusterInstanceTerminatedEvent event, Topology topology) {
+
+        // Apply service filter
+        if (TopologyServiceFilter.getInstance().isActive()) {
+            if (TopologyServiceFilter.getInstance().serviceNameExcluded(event.getServiceName())) {
+                // Service is excluded, do not update topology or fire event
+                if (log.isDebugEnabled()) {
+                    log.debug(String.format("Service is excluded: [service] %s", event.getServiceName()));
+                }
+                return false;
+            }
+        }
+
+        // Apply cluster filter
+        if (TopologyClusterFilter.getInstance().isActive()) {
+            if (TopologyClusterFilter.getInstance().clusterIdExcluded(event.getClusterId())) {
+                // Cluster is excluded, do not update topology or fire event
+                if (log.isDebugEnabled()) {
+                    log.debug(String.format("Cluster is excluded: [cluster] %s", event.getClusterId()));
+                }
+                return false;
+            }
+        }
+
+        // Validate event against the existing topology
+        Service service = topology.getService(event.getServiceName());
+        if (service == null) {
+            if (log.isWarnEnabled()) {
+                log.warn(String.format("Service does not exist: [service] %s",
+                        event.getServiceName()));
+            }
+            return false;
+        }
+        Cluster cluster = service.getCluster(event.getClusterId());
+
+        if (cluster == null) {
+            if (log.isDebugEnabled()) {
+                log.debug(String.format("Cluster not exists in service: [service] %s [cluster] %s", event.getServiceName(),
+                        event.getClusterId()));
+            }
+        } else {
+            // Apply changes to the topology
+            ClusterInstance context = cluster.getInstanceContexts(event.getInstanceId());
+            if(context == null) {
+                log.warn("Cluster Instance Context is not found for [cluster] " +
+                        event.getClusterId() + " [instance-id] " +
+                        event.getInstanceId());
+            }
+            ClusterStatus status = ClusterStatus.Terminated;
+            if (!context.isStateTransitionValid(status)) {
+                log.error("Invalid State Transition from " + context.getStatus() + " to " + status);
+            }
+            context.setStatus(status);
+
+        }
+
+        // Notify event listeners
+        notifyEventListeners(event);
+        return true;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterInstanceTerminatingProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterInstanceTerminatingProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterInstanceTerminatingProcessor.java
new file mode 100644
index 0000000..7ddc21f
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterInstanceTerminatingProcessor.java
@@ -0,0 +1,141 @@
+/*
+ * 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.messaging.message.processor.topology;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.messaging.domain.instance.ClusterInstance;
+import org.apache.stratos.messaging.domain.topology.Cluster;
+import org.apache.stratos.messaging.domain.topology.ClusterStatus;
+import org.apache.stratos.messaging.domain.topology.Service;
+import org.apache.stratos.messaging.domain.topology.Topology;
+import org.apache.stratos.messaging.event.topology.ClusterInstanceTerminatingEvent;
+import org.apache.stratos.messaging.message.filter.topology.TopologyClusterFilter;
+import org.apache.stratos.messaging.message.filter.topology.TopologyServiceFilter;
+import org.apache.stratos.messaging.message.processor.MessageProcessor;
+import org.apache.stratos.messaging.message.processor.topology.updater.TopologyUpdater;
+import org.apache.stratos.messaging.util.Util;
+
+/**
+ * This processor will act upon the cluster activated event
+ */
+public class ClusterInstanceTerminatingProcessor extends MessageProcessor {
+    private static final Log log = LogFactory.getLog(ClusterInstanceTerminatingProcessor.class);
+    private MessageProcessor nextProcessor;
+
+    @Override
+    public void setNext(MessageProcessor nextProcessor) {
+        this.nextProcessor = nextProcessor;
+    }
+
+    @Override
+    public boolean process(String type, String message, Object object) {
+
+        Topology topology = (Topology) object;
+
+        if (ClusterInstanceTerminatingEvent.class.getName().equals(type)) {
+            // Return if topology has not been initialized
+            if (!topology.isInitialized()) {
+                return false;
+            }
+
+            // Parse complete message and build event
+            ClusterInstanceTerminatingEvent event = (ClusterInstanceTerminatingEvent) Util.
+                    jsonToObject(message, ClusterInstanceTerminatingEvent.class);
+
+            TopologyUpdater.acquireWriteLockForCluster(event.getServiceName(), event.getClusterId());
+            try {
+                return doProcess(event, topology);
+
+            } finally {
+                TopologyUpdater.releaseWriteLockForCluster(event.getServiceName(), event.getClusterId());
+            }
+
+        } else {
+            if (nextProcessor != null) {
+                // ask the next processor to take care of the message.
+                return nextProcessor.process(type, message, topology);
+            } else {
+                throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message));
+            }
+        }
+    }
+
+    private boolean doProcess(ClusterInstanceTerminatingEvent event, Topology topology) {
+
+        // Apply service filter
+        if (TopologyServiceFilter.getInstance().isActive()) {
+            if (TopologyServiceFilter.getInstance().serviceNameExcluded(event.getServiceName())) {
+                // Service is excluded, do not update topology or fire event
+                if (log.isDebugEnabled()) {
+                    log.debug(String.format("Service is excluded: [service] %s", event.getServiceName()));
+                }
+                return false;
+            }
+        }
+
+        // Apply cluster filter
+        if (TopologyClusterFilter.getInstance().isActive()) {
+            if (TopologyClusterFilter.getInstance().clusterIdExcluded(event.getClusterId())) {
+                // Cluster is excluded, do not update topology or fire event
+                if (log.isDebugEnabled()) {
+                    log.debug(String.format("Cluster is excluded: [cluster] %s", event.getClusterId()));
+                }
+                return false;
+            }
+        }
+
+        // Validate event against the existing topology
+        Service service = topology.getService(event.getServiceName());
+        if (service == null) {
+            if (log.isWarnEnabled()) {
+                log.warn(String.format("Service does not exist: [service] %s",
+                        event.getServiceName()));
+            }
+            return false;
+        }
+        Cluster cluster = service.getCluster(event.getClusterId());
+
+        if (cluster == null) {
+            if (log.isDebugEnabled()) {
+                log.debug(String.format("Cluster not exists in service: [service] %s [cluster] %s", event.getServiceName(),
+                        event.getClusterId()));
+            }
+        } else {
+            // Apply changes to the topology
+            ClusterInstance context = cluster.getInstanceContexts(event.getInstanceId());
+            if(context == null) {
+                log.warn("Cluster Instance Context is not found for [cluster] " +
+                        event.getClusterId() + " [instance-id] " +
+                        event.getInstanceId());
+            }
+            ClusterStatus status = ClusterStatus.Terminating;
+            if (!context.isStateTransitionValid(status)) {
+                log.error("Invalid State Transition from " + context.getStatus() + " to " + status);
+            }
+            context.setStatus(status);
+
+        }
+
+        // Notify event listeners
+        notifyEventListeners(event);
+        return true;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterTerminatedProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterTerminatedProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterTerminatedProcessor.java
deleted file mode 100644
index f80f742..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterTerminatedProcessor.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * 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.messaging.message.processor.topology;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.messaging.domain.instance.ClusterInstance;
-import org.apache.stratos.messaging.domain.topology.Cluster;
-import org.apache.stratos.messaging.domain.topology.ClusterStatus;
-import org.apache.stratos.messaging.domain.topology.Service;
-import org.apache.stratos.messaging.domain.topology.Topology;
-import org.apache.stratos.messaging.event.topology.ClusterTerminatedEvent;
-import org.apache.stratos.messaging.message.filter.topology.TopologyClusterFilter;
-import org.apache.stratos.messaging.message.filter.topology.TopologyServiceFilter;
-import org.apache.stratos.messaging.message.processor.MessageProcessor;
-import org.apache.stratos.messaging.message.processor.topology.updater.TopologyUpdater;
-import org.apache.stratos.messaging.util.Util;
-
-/**
- * This processor will act upon the cluster activated event
- */
-public class ClusterTerminatedProcessor extends MessageProcessor {
-    private static final Log log = LogFactory.getLog(ClusterTerminatedProcessor.class);
-    private MessageProcessor nextProcessor;
-
-    @Override
-    public void setNext(MessageProcessor nextProcessor) {
-        this.nextProcessor = nextProcessor;
-    }
-
-    @Override
-    public boolean process(String type, String message, Object object) {
-
-        Topology topology = (Topology) object;
-
-        if (ClusterTerminatedEvent.class.getName().equals(type)) {
-            // Return if topology has not been initialized
-            if (!topology.isInitialized()) {
-                return false;
-            }
-
-            // Parse complete message and build event
-            ClusterTerminatedEvent event = (ClusterTerminatedEvent) Util.
-                    jsonToObject(message, ClusterTerminatedEvent.class);
-
-            TopologyUpdater.acquireWriteLockForCluster(event.getServiceName(), event.getClusterId());
-            try {
-                return doProcess(event, topology);
-
-            } finally {
-                TopologyUpdater.releaseWriteLockForCluster(event.getServiceName(), event.getClusterId());
-            }
-
-        } else {
-            if (nextProcessor != null) {
-                // ask the next processor to take care of the message.
-                return nextProcessor.process(type, message, topology);
-            } else {
-                throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message));
-            }
-        }
-    }
-
-    private boolean doProcess(ClusterTerminatedEvent event, Topology topology) {
-
-        // Apply service filter
-        if (TopologyServiceFilter.getInstance().isActive()) {
-            if (TopologyServiceFilter.getInstance().serviceNameExcluded(event.getServiceName())) {
-                // Service is excluded, do not update topology or fire event
-                if (log.isDebugEnabled()) {
-                    log.debug(String.format("Service is excluded: [service] %s", event.getServiceName()));
-                }
-                return false;
-            }
-        }
-
-        // Apply cluster filter
-        if (TopologyClusterFilter.getInstance().isActive()) {
-            if (TopologyClusterFilter.getInstance().clusterIdExcluded(event.getClusterId())) {
-                // Cluster is excluded, do not update topology or fire event
-                if (log.isDebugEnabled()) {
-                    log.debug(String.format("Cluster is excluded: [cluster] %s", event.getClusterId()));
-                }
-                return false;
-            }
-        }
-
-        // Validate event against the existing topology
-        Service service = topology.getService(event.getServiceName());
-        if (service == null) {
-            if (log.isWarnEnabled()) {
-                log.warn(String.format("Service does not exist: [service] %s",
-                        event.getServiceName()));
-            }
-            return false;
-        }
-        Cluster cluster = service.getCluster(event.getClusterId());
-
-        if (cluster == null) {
-            if (log.isDebugEnabled()) {
-                log.debug(String.format("Cluster not exists in service: [service] %s [cluster] %s", event.getServiceName(),
-                        event.getClusterId()));
-            }
-        } else {
-            // Apply changes to the topology
-            ClusterInstance context = cluster.getInstanceContexts(event.getInstanceId());
-            if(context == null) {
-                log.warn("Cluster Instance Context is not found for [cluster] " +
-                        event.getClusterId() + " [instance-id] " +
-                        event.getInstanceId());
-            }
-            ClusterStatus status = ClusterStatus.Terminated;
-            if (!context.isStateTransitionValid(status)) {
-                log.error("Invalid State Transition from " + context.getStatus() + " to " + status);
-            }
-            context.setStatus(status);
-
-        }
-
-        // Notify event listeners
-        notifyEventListeners(event);
-        return true;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterTerminatingProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterTerminatingProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterTerminatingProcessor.java
deleted file mode 100644
index 5d23678..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterTerminatingProcessor.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * 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.messaging.message.processor.topology;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.messaging.domain.instance.ClusterInstance;
-import org.apache.stratos.messaging.domain.topology.Cluster;
-import org.apache.stratos.messaging.domain.topology.ClusterStatus;
-import org.apache.stratos.messaging.domain.topology.Service;
-import org.apache.stratos.messaging.domain.topology.Topology;
-import org.apache.stratos.messaging.event.topology.ClusterTerminatingEvent;
-import org.apache.stratos.messaging.message.filter.topology.TopologyClusterFilter;
-import org.apache.stratos.messaging.message.filter.topology.TopologyServiceFilter;
-import org.apache.stratos.messaging.message.processor.MessageProcessor;
-import org.apache.stratos.messaging.message.processor.topology.updater.TopologyUpdater;
-import org.apache.stratos.messaging.util.Util;
-
-/**
- * This processor will act upon the cluster activated event
- */
-public class ClusterTerminatingProcessor extends MessageProcessor {
-    private static final Log log = LogFactory.getLog(ClusterTerminatingProcessor.class);
-    private MessageProcessor nextProcessor;
-
-    @Override
-    public void setNext(MessageProcessor nextProcessor) {
-        this.nextProcessor = nextProcessor;
-    }
-
-    @Override
-    public boolean process(String type, String message, Object object) {
-
-        Topology topology = (Topology) object;
-
-        if (ClusterTerminatingEvent.class.getName().equals(type)) {
-            // Return if topology has not been initialized
-            if (!topology.isInitialized()) {
-                return false;
-            }
-
-            // Parse complete message and build event
-            ClusterTerminatingEvent event = (ClusterTerminatingEvent) Util.
-                    jsonToObject(message, ClusterTerminatingEvent.class);
-
-            TopologyUpdater.acquireWriteLockForCluster(event.getServiceName(), event.getClusterId());
-            try {
-                return doProcess(event, topology);
-
-            } finally {
-                TopologyUpdater.releaseWriteLockForCluster(event.getServiceName(), event.getClusterId());
-            }
-
-        } else {
-            if (nextProcessor != null) {
-                // ask the next processor to take care of the message.
-                return nextProcessor.process(type, message, topology);
-            } else {
-                throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message));
-            }
-        }
-    }
-
-    private boolean doProcess(ClusterTerminatingEvent event, Topology topology) {
-
-        // Apply service filter
-        if (TopologyServiceFilter.getInstance().isActive()) {
-            if (TopologyServiceFilter.getInstance().serviceNameExcluded(event.getServiceName())) {
-                // Service is excluded, do not update topology or fire event
-                if (log.isDebugEnabled()) {
-                    log.debug(String.format("Service is excluded: [service] %s", event.getServiceName()));
-                }
-                return false;
-            }
-        }
-
-        // Apply cluster filter
-        if (TopologyClusterFilter.getInstance().isActive()) {
-            if (TopologyClusterFilter.getInstance().clusterIdExcluded(event.getClusterId())) {
-                // Cluster is excluded, do not update topology or fire event
-                if (log.isDebugEnabled()) {
-                    log.debug(String.format("Cluster is excluded: [cluster] %s", event.getClusterId()));
-                }
-                return false;
-            }
-        }
-
-        // Validate event against the existing topology
-        Service service = topology.getService(event.getServiceName());
-        if (service == null) {
-            if (log.isWarnEnabled()) {
-                log.warn(String.format("Service does not exist: [service] %s",
-                        event.getServiceName()));
-            }
-            return false;
-        }
-        Cluster cluster = service.getCluster(event.getClusterId());
-
-        if (cluster == null) {
-            if (log.isDebugEnabled()) {
-                log.debug(String.format("Cluster not exists in service: [service] %s [cluster] %s", event.getServiceName(),
-                        event.getClusterId()));
-            }
-        } else {
-            // Apply changes to the topology
-            ClusterInstance context = cluster.getInstanceContexts(event.getInstanceId());
-            if(context == null) {
-                log.warn("Cluster Instance Context is not found for [cluster] " +
-                        event.getClusterId() + " [instance-id] " +
-                        event.getInstanceId());
-            }
-            ClusterStatus status = ClusterStatus.Terminating;
-            if (!context.isStateTransitionValid(status)) {
-                log.error("Invalid State Transition from " + context.getStatus() + " to " + status);
-            }
-            context.setStatus(status);
-
-        }
-
-        // Notify event listeners
-        notifyEventListeners(event);
-        return true;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/TopologyMessageProcessorChain.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/TopologyMessageProcessorChain.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/TopologyMessageProcessorChain.java
index 190f728..184e2b9 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/TopologyMessageProcessorChain.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/TopologyMessageProcessorChain.java
@@ -39,8 +39,8 @@ public class TopologyMessageProcessorChain extends MessageProcessorChain {
     private ApplicationClustersRemovedMessageProcessor appClustersRemovedMessageProcessor;
     private ClusterCreatedMessageProcessor clusterCreatedMessageProcessor;
     private ClusterResetMessageProcessor clusterResetMessageProcessor;
-    private ClusterActivatedProcessor clusterActivatedProcessor;
-    private ClusterInActivateProcessor clusterInActivateProcessor;
+    private ClusterInstanceActivatedProcessor clusterActivatedProcessor;
+    private ClusterInstanceInActivateProcessor clusterInActivateProcessor;
     private ClusterRemovedMessageProcessor clusterRemovedMessageProcessor;
     private InstanceSpawnedMessageProcessor instanceSpawnedMessageProcessor;
     private MemberStartedMessageProcessor memberStartedMessageProcessor;
@@ -49,8 +49,8 @@ public class TopologyMessageProcessorChain extends MessageProcessorChain {
     private MemberMaintenanceModeProcessor memberMaintenanceModeProcessor;
     private MemberSuspendedMessageProcessor memberSuspendedMessageProcessor;
     private MemberTerminatedMessageProcessor memberTerminatedMessageProcessor;
-    private ClusterTerminatingProcessor clusterTerminatingProcessor;
-    private ClusterTerminatedProcessor clusterTerminatedProcessor;
+    private ClusterInstanceTerminatingProcessor clusterTerminatingProcessor;
+    private ClusterInstanceTerminatedProcessor clusterTerminatedProcessor;
     private ClusterInstanceCreatedMessageProcessor clusterInstanceCreatedMessageProcessor;
 
     public void initialize() {
@@ -73,16 +73,16 @@ public class TopologyMessageProcessorChain extends MessageProcessorChain {
         clusterCreatedMessageProcessor = new ClusterCreatedMessageProcessor();
         add(clusterCreatedMessageProcessor);
 
-        clusterActivatedProcessor = new ClusterActivatedProcessor();
+        clusterActivatedProcessor = new ClusterInstanceActivatedProcessor();
         add(clusterActivatedProcessor);
 
-        clusterInActivateProcessor = new ClusterInActivateProcessor();
+        clusterInActivateProcessor = new ClusterInstanceInActivateProcessor();
         add(clusterInActivateProcessor);
 
         clusterRemovedMessageProcessor = new ClusterRemovedMessageProcessor();
         add(clusterRemovedMessageProcessor);
 
-        clusterTerminatedProcessor = new ClusterTerminatedProcessor();
+        clusterTerminatedProcessor = new ClusterInstanceTerminatedProcessor();
         add(clusterTerminatedProcessor);
 
         clusterInstanceCreatedMessageProcessor = new ClusterInstanceCreatedMessageProcessor();
@@ -91,7 +91,7 @@ public class TopologyMessageProcessorChain extends MessageProcessorChain {
         clusterResetMessageProcessor = new ClusterResetMessageProcessor();
         add(clusterResetMessageProcessor);
 
-        clusterTerminatingProcessor = new ClusterTerminatingProcessor();
+        clusterTerminatingProcessor = new ClusterInstanceTerminatingProcessor();
         add(clusterTerminatingProcessor);
 
         instanceSpawnedMessageProcessor = new InstanceSpawnedMessageProcessor();
@@ -129,19 +129,19 @@ public class TopologyMessageProcessorChain extends MessageProcessorChain {
             appClustersCreatedMessageProcessor.addEventListener(eventListener);
         } else if (eventListener instanceof ApplicationClustersRemovedEventListener) {
             appClustersRemovedMessageProcessor.addEventListener(eventListener);
-        } else if (eventListener instanceof ClusterActivatedEventListener) {
+        } else if (eventListener instanceof ClusterInstanceActivatedEventListener) {
             clusterActivatedProcessor.addEventListener(eventListener);
-        } else if (eventListener instanceof ClusterInActivateEventListener) {
+        } else if (eventListener instanceof ClusterInstanceInActivateEventListener) {
             clusterInActivateProcessor.addEventListener(eventListener);
         } else if (eventListener instanceof ClusterRemovedEventListener) {
             clusterRemovedMessageProcessor.addEventListener(eventListener);
         } else if (eventListener instanceof ClusterInstanceCreatedEventListener) {
             clusterInstanceCreatedMessageProcessor.addEventListener(eventListener);
-        } else if(eventListener instanceof ClusterTerminatedEventListener){
+        } else if(eventListener instanceof ClusterInstanceTerminatedEventListener){
             clusterTerminatedProcessor.addEventListener(eventListener);
         } else if(eventListener instanceof ClusterResetEventListener){
             clusterResetMessageProcessor.addEventListener(eventListener);
-        } else if(eventListener instanceof  ClusterTerminatingEventListener){
+        } else if(eventListener instanceof ClusterInstanceTerminatingEventListener){
             clusterTerminatingProcessor.addEventListener(eventListener);
         }else if (eventListener instanceof InstanceSpawnedEventListener) {
             instanceSpawnedMessageProcessor.addEventListener(eventListener);


[4/5] stratos git commit: adding instance prefix to events, , processor and listener

Posted by re...@apache.org.
adding instance prefix to events,, processor and listener


Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/cf1b3727
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/cf1b3727
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/cf1b3727

Branch: refs/heads/master
Commit: cf1b372724f2f4ae63878a24dd6e6fdbcc6be65a
Parents: 5f72e3d
Author: reka <rt...@gmail.com>
Authored: Fri Dec 5 12:35:13 2014 +0530
Committer: reka <rt...@gmail.com>
Committed: Fri Dec 5 12:35:35 2014 +0530

----------------------------------------------------------------------
 .../applications/topic/ApplicationBuilder.java  |  32 ++---
 .../topic/ApplicationsEventPublisher.java       |  48 ++++---
 .../AutoscalerTopologyEventReceiver.java        |  28 ++--
 .../monitor/cluster/AbstractClusterMonitor.java |  26 ++--
 .../monitor/cluster/ClusterMonitorFactory.java  |   2 +-
 .../cluster/ClusterStatusActiveProcessor.java   |   2 +-
 .../group/GroupStatusActiveProcessor.java       |   4 +-
 .../group/GroupStatusTerminatedProcessor.java   |   4 +-
 .../group/GroupStatusTerminatingProcessor.java  |   2 +-
 .../stratos/autoscaler/util/AutoscalerUtil.java |   4 +-
 .../application/ApplicationTopicReceiver.java   |   4 +-
 .../messaging/topology/TopologyBuilder.java     |  12 +-
 .../topology/TopologyEventPublisher.java        |   8 +-
 .../applications/ApplicationActivatedEvent.java |  46 ------
 .../ApplicationInstanceActivatedEvent.java      |  46 ++++++
 .../event/applications/GroupActivatedEvent.java |  54 -------
 .../applications/GroupInactivatedEvent.java     |  51 -------
 .../GroupInstanceActivatedEvent.java            |  54 +++++++
 .../applications/GroupInstanceCreatedEvent.java |  55 +++++++
 .../GroupInstanceInactivatedEvent.java          |  51 +++++++
 .../GroupInstanceTerminatedEvent.java           |  54 +++++++
 .../GroupInstanceTerminatingEvent.java          |  54 +++++++
 .../event/applications/GroupResetEvent.java     |  54 -------
 .../applications/GroupTerminatedEvent.java      |  54 -------
 .../applications/GroupTerminatingEvent.java     |  54 -------
 .../event/topology/ClusterActivatedEvent.java   |  63 --------
 .../event/topology/ClusterInactivateEvent.java  |  63 --------
 .../topology/ClusterInstanceActivatedEvent.java |  63 ++++++++
 .../ClusterInstanceInactivateEvent.java         |  63 ++++++++
 .../ClusterInstanceTerminatedEvent.java         |  63 ++++++++
 .../ClusterInstanceTerminatingEvent.java        |  61 ++++++++
 .../event/topology/ClusterTerminatedEvent.java  |  63 --------
 .../event/topology/ClusterTerminatingEvent.java |  61 --------
 .../ApplicationActivatedEventListener.java      |  27 ----
 .../ApplicationInactivatedEventListener.java    |  27 ----
 ...plicationInstanceActivatedEventListener.java |  27 ++++
 ...icationInstanceInactivatedEventListener.java |  27 ++++
 ...licationInstanceTerminatedEventListener.java |  27 ++++
 ...icationInstanceTerminatingEventListener.java |  27 ++++
 .../ApplicationTerminatedEventListener.java     |  27 ----
 .../ApplicationTerminatingEventListener.java    |  27 ----
 .../GroupActivatedEventListener.java            |  24 ----
 .../GroupInactivateEventListener.java           |  24 ----
 .../GroupInstanceActivatedEventListener.java    |  24 ++++
 .../GroupInstanceCreatedEventListener.java      |  24 ++++
 .../GroupInstanceInactivateEventListener.java   |  24 ++++
 .../GroupInstanceTerminatedEventListener.java   |  24 ++++
 .../GroupInstanceTerminatingEventListener.java  |  24 ++++
 .../applications/GroupResetEventListener.java   |  24 ----
 .../GroupTerminatedEventListener.java           |  24 ----
 .../GroupTerminatingEventListener.java          |  24 ----
 .../topology/ClusterActivatedEventListener.java |  24 ----
 .../ClusterInActivateEventListener.java         |  24 ----
 .../ClusterInstanceActivatedEventListener.java  |  24 ++++
 .../ClusterInstanceInActivateEventListener.java |  24 ++++
 .../ClusterInstanceTerminatedEventListener.java |  24 ++++
 ...ClusterInstanceTerminatingEventListener.java |  24 ++++
 .../ClusterTerminatedEventListener.java         |  24 ----
 .../ClusterTerminatingEventListener.java        |  24 ----
 .../ApplicationActivatedMessageProcessor.java   | 114 ---------------
 .../ApplicationInactivatedMessageProcessor.java | 114 ---------------
 ...cationInstanceActivatedMessageProcessor.java | 114 +++++++++++++++
 ...tionInstanceInactivatedMessageProcessor.java | 114 +++++++++++++++
 ...ationInstanceTerminatedMessageProcessor.java |  97 +++++++++++++
 ...tionInstanceTerminatingMessageProcessor.java | 113 +++++++++++++++
 .../ApplicationTerminatedMessageProcessor.java  |  97 -------------
 .../ApplicationTerminatingMessageProcessor.java | 113 ---------------
 .../ApplicationsMessageProcessorChain.java      |  54 +++----
 .../applications/GroupActivatedProcessor.java   | 120 ----------------
 .../applications/GroupInActivateProcessor.java  | 120 ----------------
 .../GroupInstanceActivatedProcessor.java        | 120 ++++++++++++++++
 .../GroupInstanceCreatedProcessor.java          | 116 +++++++++++++++
 .../GroupInstanceInActivateProcessor.java       | 120 ++++++++++++++++
 .../GroupInstanceTerminatingProcessor.java      | 122 ++++++++++++++++
 .../applications/GroupResetProcessor.java       | 121 ----------------
 .../applications/GroupTerminatedProcessor.java  | 121 ----------------
 .../applications/GroupTerminatingProcessor.java | 122 ----------------
 .../topology/ClusterActivatedProcessor.java     | 143 -------------------
 .../topology/ClusterInActivateProcessor.java    | 139 ------------------
 .../ClusterInstanceActivatedProcessor.java      | 143 +++++++++++++++++++
 .../ClusterInstanceInActivateProcessor.java     | 139 ++++++++++++++++++
 .../ClusterInstanceTerminatedProcessor.java     | 141 ++++++++++++++++++
 .../ClusterInstanceTerminatingProcessor.java    | 141 ++++++++++++++++++
 .../topology/ClusterTerminatedProcessor.java    | 141 ------------------
 .../topology/ClusterTerminatingProcessor.java   | 141 ------------------
 .../topology/TopologyMessageProcessorChain.java |  24 ++--
 86 files changed, 2498 insertions(+), 2617 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java
index 042497c..b0db089 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java
@@ -107,7 +107,7 @@ public class ApplicationBuilder {
             application.addInstance(instanceId, applicationInstance);
             //updateApplicationMonitor(appId, status);
             ApplicationHolder.persistApplication(application);
-            //ApplicationsEventPublisher.sendApplicationActivatedEvent(appId);
+            ApplicationsEventPublisher.sendApplicationInstanceCreatedEvent(appId, applicationInstance);
         } else {
             log.warn(String.format("Application Instance Context already exists" +
                     " [appId] %s [ApplicationInstanceId] %s", appId, instanceId));
@@ -115,7 +115,7 @@ public class ApplicationBuilder {
         return applicationInstance;
     }
 
-    public static void handleApplicationActivatedEvent(String appId, String instanceId) {
+    public static void handleApplicationInstanceActivatedEvent(String appId, String instanceId) {
         if (log.isDebugEnabled()) {
             log.debug("Handling application activation event: [application-id] " + appId);
         }
@@ -136,7 +136,7 @@ public class ApplicationBuilder {
             application.setStatus(status, instanceId);
             updateApplicationMonitor(appId, status, instanceId);
             ApplicationHolder.persistApplication(application);
-            ApplicationsEventPublisher.sendApplicationActivatedEvent(appId, instanceId);
+            ApplicationsEventPublisher.sendApplicationInstanceActivatedEvent(appId, instanceId);
         } else {
             log.warn(String.format("Application state transition is not valid: [application-id] %s " +
                     " [instance-id] %s [current-status] %s [status-requested] %s",
@@ -201,7 +201,7 @@ public class ApplicationBuilder {
                     application.setStatus(status, context1.getInstanceId());
                     updateApplicationMonitor(appId, status, context1.getInstanceId());
                     ApplicationHolder.persistApplication(application);
-                    ApplicationsEventPublisher.sendApplicationTerminatingEvent(appId, context1.getInstanceId());
+                    ApplicationsEventPublisher.sendApplicationInstanceTerminatingEvent(appId, context1.getInstanceId());
                 } else {
                     log.warn(String.format("Application Instance state transition is not valid: [application-id] %s " +
                                     " [instance-id] %s [current-status] %s [status-requested] %s", appId,
@@ -241,7 +241,7 @@ public class ApplicationBuilder {
         return true;
     }
 
-    public static void handleApplicationTerminatedEvent(String appId, String instanceId) {
+    public static void handleApplicationInstanceTerminatedEvent(String appId, String instanceId) {
         if (log.isDebugEnabled()) {
             log.debug("Handling application terminated event: [application-id] " + appId);
         }
@@ -265,7 +265,7 @@ public class ApplicationBuilder {
                 ApplicationHolder.removeApplication(appId);
                 log.info("Application is removed: [application-id] " + appId);
 
-                ApplicationsEventPublisher.sendApplicationTerminatedEvent(appId, clusterData);
+                ApplicationsEventPublisher.sendApplicationInstanceTerminatedEvent(appId, clusterData);
             } else {
                 log.warn(String.format("Application state transition is not valid: [application-id] %s " +
                         " [current-status] %s [status-requested] %s", appId,
@@ -275,7 +275,7 @@ public class ApplicationBuilder {
         }
     }
 
-    public static void handleGroupTerminatedEvent(String appId, String groupId, String instanceId) {
+    public static void handleGroupInstanceTerminatedEvent(String appId, String groupId, String instanceId) {
         if (log.isDebugEnabled()) {
             log.debug("Handling group terminated event: [group-id] " + groupId +
                     " [application-id] " + appId);
@@ -304,7 +304,7 @@ public class ApplicationBuilder {
                 //setting the status, persist and publish
                 updateGroupMonitor(appId, groupId, status, instanceId);
                 ApplicationHolder.persistApplication(application);
-                ApplicationsEventPublisher.sendGroupTerminatedEvent(appId, groupId, instanceId);
+                ApplicationsEventPublisher.sendGroupInstanceTerminatedEvent(appId, groupId, instanceId);
             } else {
                 log.warn("Group state transition is not valid: [group-id] " + groupId +
                         " [instance-id] " + instanceId + " [current-state] " + context.getStatus()
@@ -318,7 +318,7 @@ public class ApplicationBuilder {
 
     }
 
-    public static void handleGroupActivatedEvent(String appId, String groupId, String instanceId) {
+    public static void handleGroupInstanceActivatedEvent(String appId, String groupId, String instanceId) {
         if (log.isDebugEnabled()) {
             log.debug("Handling group activation for the [group-id]: " + groupId +
                     " in the [application-id] " + appId);
@@ -347,7 +347,7 @@ public class ApplicationBuilder {
                 //setting the status, persist and publish
                 updateGroupMonitor(appId, groupId, status, instanceId);
                 ApplicationHolder.persistApplication(application);
-                ApplicationsEventPublisher.sendGroupActivatedEvent(appId, groupId, instanceId);
+                ApplicationsEventPublisher.sendGroupInstanceActivatedEvent(appId, groupId, instanceId);
             } else {
                 log.warn("Group state transition is not valid: [group-id] " + groupId +
                         " [instance-id] " + instanceId + " [current-state] " + context.getStatus()
@@ -360,7 +360,7 @@ public class ApplicationBuilder {
         }
     }
 
-    public static void handleGroupCreatedEvent(String appId, String groupId, String instanceId) {
+    public static void handleGroupInstanceCreatedEvent(String appId, String groupId, String instanceId) {
         if (log.isDebugEnabled()) {
             log.debug("Handling Group creation for the [group]: " + groupId +
                     " in the [application] " + appId);
@@ -387,7 +387,7 @@ public class ApplicationBuilder {
             //setting the status, persist and publish
             updateGroupMonitor(appId, groupId, status, instanceId);
             ApplicationHolder.persistApplication(application);
-            ApplicationsEventPublisher.sendGroupCreatedEvent(appId, groupId, instanceId);
+            ApplicationsEventPublisher.sendGroupInstanceCreatedEvent(appId, groupId, null);
         } else {
             log.warn("Group state transition is not valid: [group-id] " + groupId + " [current-state] " + group.getStatus(null)
                     + "[requested-state] " + status);
@@ -429,7 +429,7 @@ public class ApplicationBuilder {
             group.addInstance(instanceId, instance);
             //updateGroupMonitor(appId, groupId, status);
             ApplicationHolder.persistApplication(application);
-            //ApplicationsEventPublisher.sendGroupCreatedEvent(appId, groupId);
+            //ApplicationsEventPublisher.sendGroupInstanceCreatedEvent(appId, groupId);
         } else {
             log.warn("Group Instance Context already exists: [group-id] " + groupId +
                     " [Group-Instance-Id] " + instanceId);
@@ -468,7 +468,7 @@ public class ApplicationBuilder {
                 //setting the status, persist and publish
                 updateGroupMonitor(appId, groupId, status, instanceId);
                 ApplicationHolder.persistApplication(application);
-                ApplicationsEventPublisher.sendGroupInActivateEvent(appId, groupId, instanceId);
+                ApplicationsEventPublisher.sendGroupInstanceInActivateEvent(appId, groupId, instanceId);
             } else {
                 log.warn("Group state transition is not valid: [group-id] " + groupId +
                         " [instance-id] " + instanceId + " [current-state] " + context.getStatus()
@@ -512,7 +512,7 @@ public class ApplicationBuilder {
                     //setting the status, persist and publish
                     updateGroupMonitor(appId, groupId, status, instanceId);
                     ApplicationHolder.persistApplication(application);
-                    ApplicationsEventPublisher.sendGroupTerminatingEvent(appId, groupId, instanceId);
+                    ApplicationsEventPublisher.sendGroupInstanceTerminatingEvent(appId, groupId, instanceId);
                 } else {
                     log.warn("Group state transition is not valid: [group-id] " + groupId +
                             " [instance-id] " + instanceId + " [current-state] " + context.getStatus()
@@ -535,7 +535,7 @@ public class ApplicationBuilder {
                 log.error("Invalid state transfer from " + group.getStatus(null) + " to " + groupStatus);
             }
             // force update for now
-            //group.setStatus(groupStatus, null);
+            //group.notifyParentMonitor(groupStatus, null);
 
             // go recursively and update
             if (group.getGroups() != null) {

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationsEventPublisher.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationsEventPublisher.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationsEventPublisher.java
index 1f4f6ca..305b4e7 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationsEventPublisher.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationsEventPublisher.java
@@ -7,6 +7,8 @@ import org.apache.stratos.messaging.broker.publish.EventPublisherPool;
 import org.apache.stratos.messaging.domain.applications.Application;
 import org.apache.stratos.messaging.domain.applications.Applications;
 import org.apache.stratos.messaging.domain.applications.ClusterDataHolder;
+import org.apache.stratos.messaging.domain.instance.ApplicationInstance;
+import org.apache.stratos.messaging.domain.instance.GroupInstance;
 import org.apache.stratos.messaging.event.Event;
 import org.apache.stratos.messaging.event.applications.*;
 import org.apache.stratos.messaging.util.Util;
@@ -29,70 +31,76 @@ public class ApplicationsEventPublisher {
         publishEvent(new ApplicationCreatedEvent(application));
     }
 
-    public static void sendGroupCreatedEvent(String appId, String groupId, String instanceId) {
+    public static void sendApplicationInstanceCreatedEvent(String appId,
+                                                           ApplicationInstance applicationInstance) {
+
+        publishEvent(new ApplicationInstanceCreatedEvent(appId, applicationInstance));
+    }
+    public static void sendGroupInstanceCreatedEvent(String appId, String groupId,
+                                                     GroupInstance groupInstance) {
         if (log.isInfoEnabled()) {
             log.info("Publishing Group created event for [application]: " + appId +
                     " [group]: " + groupId);
         }
-        GroupResetEvent groupCreatedEvent =
-                new GroupResetEvent(appId, groupId, instanceId);
+        GroupInstanceCreatedEvent groupCreatedEvent =
+                new GroupInstanceCreatedEvent(appId, groupId, groupInstance);
 
         publishEvent(groupCreatedEvent);
     }
 
-    public static void sendGroupActivatedEvent(String appId, String groupId, String instanceId) {
+    public static void sendGroupInstanceActivatedEvent(String appId, String groupId, String instanceId) {
         if (log.isInfoEnabled()) {
             log.info("Publishing Group activated event for [application]: " + appId +
                     " [group]: " + groupId);
         }
-        GroupActivatedEvent groupActivatedEvent =
-                new GroupActivatedEvent(appId, groupId, instanceId);
+        GroupInstanceActivatedEvent groupActivatedEvent =
+                new GroupInstanceActivatedEvent(appId, groupId, instanceId);
 
         publishEvent(groupActivatedEvent);
     }
 
-    public static void sendGroupInActivateEvent(String appId, String groupId, String instanceId) {
+    public static void sendGroupInstanceInActivateEvent(String appId, String groupId, String instanceId) {
         if (log.isInfoEnabled()) {
             log.info("Publishing Group in-activate event for [application]: " + appId +
                     " [group]: " + groupId);
         }
-        GroupInactivatedEvent groupInactivateEvent = new GroupInactivatedEvent(appId, groupId, instanceId);
+        GroupInstanceInactivatedEvent groupInactivateEvent = new GroupInstanceInactivatedEvent(appId, groupId, instanceId);
 
         publishEvent(groupInactivateEvent);
     }
 
-    public static void sendGroupTerminatingEvent(String appId, String groupId, String instanceId) {
+    public static void sendGroupInstanceTerminatingEvent(String appId, String groupId, String instanceId) {
         if (log.isInfoEnabled()) {
             log.info("Publishing Group terminating event for [application]: " + appId +
                     " [group]: " + groupId);
         }
-        GroupTerminatingEvent groupInTerminatingEvent =
-                new GroupTerminatingEvent(appId, groupId, instanceId);
+        GroupInstanceTerminatingEvent groupInTerminatingEvent =
+                new GroupInstanceTerminatingEvent(appId, groupId, instanceId);
         publishEvent(groupInTerminatingEvent);
     }
 
-    public static void sendGroupTerminatedEvent(String appId, String groupId, String instanceId) {
+    public static void sendGroupInstanceTerminatedEvent(String appId, String groupId, String instanceId) {
 
         if (log.isInfoEnabled()) {
             log.info("Publishing Group terminated event for [application]: " + appId +
                     " [group]: " + groupId);
         }
-        GroupTerminatedEvent groupInTerminatedEvent =
-                new GroupTerminatedEvent(appId, groupId, instanceId);
+        GroupInstanceTerminatedEvent groupInTerminatedEvent =
+                new GroupInstanceTerminatedEvent(appId, groupId, instanceId);
         publishEvent(groupInTerminatedEvent);
     }
 
-    public static void sendApplicationActivatedEvent(String appId, String instanceId) {
+    public static void sendApplicationInstanceActivatedEvent(String appId, String instanceId) {
         if (log.isInfoEnabled()) {
             log.info("Publishing Application activated event for [application]: " + appId);
         }
-        ApplicationActivatedEvent applicationActivatedEvent =
-                new ApplicationActivatedEvent(appId, instanceId);
+        ApplicationInstanceActivatedEvent applicationActivatedEvent =
+                new ApplicationInstanceActivatedEvent(appId, instanceId);
 
         publishEvent(applicationActivatedEvent);
     }
 
-    public static void sendApplicationInactivatedEvent(String appId, String instanceId) {
+    public static void sendApplicationInstanceInactivatedEvent(String appId, String instanceId) {
         if (log.isInfoEnabled()) {
             log.info("Publishing Application In-activated event for [application]: " + appId);
         }
@@ -102,7 +110,7 @@ public class ApplicationsEventPublisher {
 
     }
 
-    public static void sendApplicationTerminatingEvent(String appId, String instanceId) {
+    public static void sendApplicationInstanceTerminatingEvent(String appId, String instanceId) {
         if (log.isInfoEnabled()) {
             log.info("Publishing Application terminating event for [application]: " + appId);
         }
@@ -111,7 +119,7 @@ public class ApplicationsEventPublisher {
         publishEvent(applicationTerminatingEvent);
     }
 
-    public static void sendApplicationTerminatedEvent(String appId, Set<ClusterDataHolder> clusterData) {
+    public static void sendApplicationInstanceTerminatedEvent(String appId, Set<ClusterDataHolder> clusterData) {
         if (log.isInfoEnabled()) {
             log.info("Publishing Application terminated event for [application]: " + appId);
         }

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/topology/AutoscalerTopologyEventReceiver.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/topology/AutoscalerTopologyEventReceiver.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/topology/AutoscalerTopologyEventReceiver.java
index abc829c..e1357f5 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/topology/AutoscalerTopologyEventReceiver.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/topology/AutoscalerTopologyEventReceiver.java
@@ -159,12 +159,13 @@ public class AutoscalerTopologyEventReceiver {
             }
         });
 
-        topologyEventReceiver.addEventListener(new ClusterActivatedEventListener() {
+        topologyEventReceiver.addEventListener(new ClusterInstanceActivatedEventListener() {
             @Override
             protected void onEvent(Event event) {
                 log.info("[ClusterActivatedEvent] Received: " + event.getClass());
-                ClusterActivatedEvent clusterActivatedEvent = (ClusterActivatedEvent) event;
+                ClusterInstanceActivatedEvent clusterActivatedEvent = (ClusterInstanceActivatedEvent) event;
                 String clusterId = clusterActivatedEvent.getClusterId();
+                String instanceId = clusterActivatedEvent.getInstanceId();
                 AutoscalerContext asCtx = AutoscalerContext.getInstance();
                 AbstractClusterMonitor monitor;
                 monitor = asCtx.getClusterMonitor(clusterId);
@@ -176,6 +177,7 @@ public class AutoscalerTopologyEventReceiver {
                     return;
                 }
                 //changing the status in the monitor, will notify its parent monitor
+                monitor.notifyParentMonitor(ClusterStatus.Active, instanceId);
 
             }
         });
@@ -199,7 +201,7 @@ public class AutoscalerTopologyEventReceiver {
                 }
                 //changing the status in the monitor, will notify its parent monitor
                 monitor.destroy();
-                monitor.setStatus(ClusterStatus.Created, instanceId);
+                monitor.notifyParentMonitor(ClusterStatus.Created, instanceId);
 
             }
         });
@@ -211,11 +213,11 @@ public class AutoscalerTopologyEventReceiver {
             }
         });
 
-        topologyEventReceiver.addEventListener(new ClusterInActivateEventListener() {
+        topologyEventReceiver.addEventListener(new ClusterInstanceInActivateEventListener() {
             @Override
             protected void onEvent(Event event) {
                 log.info("[ClusterInActivateEvent] Received: " + event.getClass());
-                ClusterInactivateEvent clusterInactivateEvent = (ClusterInactivateEvent) event;
+                ClusterInstanceInactivateEvent clusterInactivateEvent = (ClusterInstanceInactivateEvent) event;
                 String clusterId = clusterInactivateEvent.getClusterId();
                 String instanceId = clusterInactivateEvent.getInstanceId();
                 AutoscalerContext asCtx = AutoscalerContext.getInstance();
@@ -229,15 +231,15 @@ public class AutoscalerTopologyEventReceiver {
                     return;
                 }
                 //changing the status in the monitor, will notify its parent monitor
-                monitor.setStatus(ClusterStatus.Inactive, instanceId);
+                monitor.notifyParentMonitor(ClusterStatus.Inactive, instanceId);
             }
         });
 
-        topologyEventReceiver.addEventListener(new ClusterTerminatingEventListener() {
+        topologyEventReceiver.addEventListener(new ClusterInstanceTerminatingEventListener() {
             @Override
             protected void onEvent(Event event) {
                 log.info("[ClusterTerminatingEvent] Received: " + event.getClass());
-                ClusterTerminatingEvent clusterTerminatingEvent = (ClusterTerminatingEvent) event;
+                ClusterInstanceTerminatingEvent clusterTerminatingEvent = (ClusterInstanceTerminatingEvent) event;
                 String clusterId = clusterTerminatingEvent.getClusterId();
                 String instanceId = clusterTerminatingEvent.getInstanceId();
                 AutoscalerContext asCtx = AutoscalerContext.getInstance();
@@ -257,10 +259,10 @@ public class AutoscalerTopologyEventReceiver {
                 ClusterInstance clusterInstance = (ClusterInstance) monitor.getInstance(instanceId);
                 if (clusterInstance.getCurrentState() == ClusterStatus.Active) {
                     // terminated gracefully
-                    monitor.setStatus(ClusterStatus.Terminating, instanceId);
+                    monitor.notifyParentMonitor(ClusterStatus.Terminating, instanceId);
                     InstanceNotificationPublisher.sendInstanceCleanupEventForCluster(clusterId, instanceId);
                 } else {
-                    monitor.setStatus(ClusterStatus.Terminating, instanceId);
+                    monitor.notifyParentMonitor(ClusterStatus.Terminating, instanceId);
                     monitor.terminateAllMembers(instanceId, clusterInstance.getNetworkPartitionId());
                 }
                 ServiceReferenceHolder.getInstance().getClusterStatusProcessorChain().
@@ -268,11 +270,11 @@ public class AutoscalerTopologyEventReceiver {
             }
         });
 
-        topologyEventReceiver.addEventListener(new ClusterTerminatedEventListener() {
+        topologyEventReceiver.addEventListener(new ClusterInstanceTerminatedEventListener() {
             @Override
             protected void onEvent(Event event) {
                 log.info("[ClusterTerminatedEvent] Received: " + event.getClass());
-                ClusterTerminatedEvent clusterTerminatedEvent = (ClusterTerminatedEvent) event;
+                ClusterInstanceTerminatedEvent clusterTerminatedEvent = (ClusterInstanceTerminatedEvent) event;
                 String clusterId = clusterTerminatedEvent.getClusterId();
                 String instanceId = clusterTerminatedEvent.getInstanceId();
                 AutoscalerContext asCtx = AutoscalerContext.getInstance();
@@ -294,7 +296,7 @@ public class AutoscalerTopologyEventReceiver {
                     return;
                 }
                 //changing the status in the monitor, will notify its parent monitor
-                monitor.setStatus(ClusterStatus.Terminated, instanceId);
+                monitor.notifyParentMonitor(ClusterStatus.Terminated, instanceId);
                 monitor.removeInstance(instanceId);
                 if (!monitor.hasInstance() && appMonitor.isTerminating()) {
                     //Destroying and Removing the Cluster monitor

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/AbstractClusterMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/AbstractClusterMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/AbstractClusterMonitor.java
index 4c7498b..19905b1 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/AbstractClusterMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/AbstractClusterMonitor.java
@@ -34,6 +34,7 @@ import org.apache.stratos.messaging.domain.applications.Application;
 import org.apache.stratos.messaging.domain.applications.ApplicationStatus;
 import org.apache.stratos.messaging.domain.applications.Group;
 import org.apache.stratos.messaging.domain.applications.GroupStatus;
+import org.apache.stratos.messaging.domain.instance.ClusterInstance;
 import org.apache.stratos.messaging.domain.topology.ClusterStatus;
 import org.apache.stratos.messaging.event.health.stat.*;
 import org.apache.stratos.messaging.event.topology.*;
@@ -206,28 +207,23 @@ public abstract class AbstractClusterMonitor extends Monitor implements Runnable
         return status;
     }
 
-    public void setStatus(ClusterStatus status, String instanceId) {
-
-//        this.clusterContext.getClusterInstance(instanceId).setStatus(status);
+    public void notifyParentMonitor(ClusterStatus status, String instanceId) {
         /**
          * notifying the parent monitor about the state change
          * If the cluster in_active and if it is a in_dependent cluster,
          * then won't send the notification to parent.
          */
-        if (status == ClusterStatus.Inactive && !this.hasStartupDependents) {
-            log.info("[Cluster] " + clusterId + "is not notifying the parent, " +
-                    "since it is identified as the independent unit");
-
-            /*} else if (status == ClusterStatus.Terminating) {
-                // notify parent
-                log.info("[Cluster] " + clusterId + " is not notifying the parent, " +
-                        "since it is in Terminating State");
-*/
+        ClusterInstance instance = (ClusterInstance) this.instanceIdToInstanceMap.get(instanceId);
+        if(instance == null) {
+            log.warn("The required cluster [instance] " + instanceId + " not found in the ClusterMonitor");
         } else {
-            MonitorStatusEventBuilder.handleClusterStatusEvent(this.parent, status, this.clusterId, instanceId);
+            if (instance.getStatus() == ClusterStatus.Inactive && !this.hasStartupDependents) {
+                log.info("[Cluster] " + clusterId + "is not notifying the parent, " +
+                        "since it is identified as the independent unit");
+            } else {
+                MonitorStatusEventBuilder.handleClusterStatusEvent(this.parent, status, this.clusterId, instanceId);
+            }
         }
-
-
     }
 
     public int getMonitorIntervalMilliseconds() {

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitorFactory.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitorFactory.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitorFactory.java
index e33e04c..f906f64 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitorFactory.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitorFactory.java
@@ -97,7 +97,7 @@ public class ClusterMonitorFactory {
 //
 //        VMLbClusterMonitor clusterMonitor =
 //                new VMLbClusterMonitor(cluster.getServiceName(), cluster.getClusterId());
-//        clusterMonitor.setStatus(ClusterStatus.Created);
+//        clusterMonitor.notifyParentMonitor(ClusterStatus.Created);
 //
 //        log.info("VMLbClusterMonitor created: " + clusterMonitor.toString());
 //        return clusterMonitor;

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusActiveProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusActiveProcessor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusActiveProcessor.java
index b80cbdf..c007a46 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusActiveProcessor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusActiveProcessor.java
@@ -69,7 +69,7 @@ public class ClusterStatusActiveProcessor extends ClusterStatusProcessor {
             //minimum check per partition
             ClusterInstanceContext instanceContext = clusterLevelNetworkPartitionContext.getClusterInstanceContext(instanceId);
             if (instanceContext != null) {
-                if (instanceContext.getActiveMembers() >= instanceContext.getMaxInstanceCount()) {
+                if (instanceContext.getActiveMembers() >= instanceContext.getMinInstanceCount()) {
                     clusterActive = true;
                 } else {
                     clusterActive = false;

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusActiveProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusActiveProcessor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusActiveProcessor.java
index 9e60357..c59736d 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusActiveProcessor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusActiveProcessor.java
@@ -91,12 +91,12 @@ public class GroupStatusActiveProcessor extends GroupStatusProcessor {
                     if (component instanceof Application) {
                         //send application activated event
                         log.info("sending app activate: " + appId);
-                        ApplicationBuilder.handleApplicationActivatedEvent(appId, instanceId);
+                        ApplicationBuilder.handleApplicationInstanceActivatedEvent(appId, instanceId);
                         return true;
                     } else if (component instanceof Group) {
                         //send activation to the parent
                         log.info("sending group activate: " + component.getUniqueIdentifier());
-                        ApplicationBuilder.handleGroupActivatedEvent(appId, component.getUniqueIdentifier(), instanceId);
+                        ApplicationBuilder.handleGroupInstanceActivatedEvent(appId, component.getUniqueIdentifier(), instanceId);
                         return true;
                     }
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusTerminatedProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusTerminatedProcessor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusTerminatedProcessor.java
index e2a6368..9c01b9a 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusTerminatedProcessor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusTerminatedProcessor.java
@@ -93,13 +93,13 @@ public class GroupStatusTerminatedProcessor extends GroupStatusProcessor {
                     //send the terminated event
                     if (component instanceof Application) {
                         log.info("sending app terminated: " + appId);
-                        ApplicationBuilder.handleApplicationTerminatedEvent(appId, instanceId);
+                        ApplicationBuilder.handleApplicationInstanceTerminatedEvent(appId, instanceId);
                         return true;
                     } else if (component instanceof Group) {
                         //send activation to the parent
                         if (((Group) component).getStatus(null) != GroupStatus.Terminated) {
                             log.info("sending group terminated : " + component.getUniqueIdentifier());
-                            ApplicationBuilder.handleGroupTerminatedEvent(appId,
+                            ApplicationBuilder.handleGroupInstanceTerminatedEvent(appId,
                                     component.getUniqueIdentifier(), instanceId);
                             return true;
                         }

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusTerminatingProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusTerminatingProcessor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusTerminatingProcessor.java
index 37b2a2d..86a8cc2 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusTerminatingProcessor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusTerminatingProcessor.java
@@ -94,7 +94,7 @@ public class GroupStatusTerminatingProcessor extends GroupStatusProcessor {
                     //send the terminated event
                     if (component instanceof Application) {
                         log.info("sending app terminated: " + appId);
-                        ApplicationBuilder.handleApplicationTerminatedEvent(appId, instanceId);
+                        ApplicationBuilder.handleApplicationInstanceTerminatedEvent(appId, instanceId);
                         return true;
                     } else if (component instanceof Group) {
                         //send activation to the parent

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
index 2ed1074..7e2ac38 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
@@ -173,7 +173,7 @@ public class AutoscalerUtil {
                                         new LbClusterMonitor(clusterId,
                                                            cluster.getServiceName(),
                                                            deploymentPolicy, policy);
-        clusterMonitor.setStatus(Status.Created);
+        clusterMonitor.notifyParentMonitor(Status.Created);
         // partition group = network partition context
         for (NetworkPartition partitionGroup : deploymentPolicy.gNetworkPartitionups()) {
 
@@ -386,7 +386,7 @@ public class AutoscalerUtil {
                 try {
                     long start = System.currentTimeMillis();
                     log.info("application monitor is going to be started for [application] " +
-                                appId);
+                            appId);
                     try {
                         applicationMonitor = MonitorFactory.getApplicationMonitor(appId);
                     } catch (PolicyValidationException e) {

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/receiver/application/ApplicationTopicReceiver.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/receiver/application/ApplicationTopicReceiver.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/receiver/application/ApplicationTopicReceiver.java
index e8d3674..445df42 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/receiver/application/ApplicationTopicReceiver.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/receiver/application/ApplicationTopicReceiver.java
@@ -23,7 +23,7 @@ import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.cloud.controller.messaging.topology.TopologyBuilder;
 import org.apache.stratos.messaging.event.Event;
 import org.apache.stratos.messaging.event.applications.ApplicationInstanceTerminatedEvent;
-import org.apache.stratos.messaging.listener.applications.ApplicationTerminatedEventListener;
+import org.apache.stratos.messaging.listener.applications.ApplicationInstanceTerminatedEventListener;
 import org.apache.stratos.messaging.message.receiver.applications.ApplicationsEventReceiver;
 
 import java.util.concurrent.ExecutorService;
@@ -67,7 +67,7 @@ public class ApplicationTopicReceiver {
 	}
 
     private void addEventListeners() {
-        applicationsEventReceiver.addEventListener(new ApplicationTerminatedEventListener() {
+        applicationsEventReceiver.addEventListener(new ApplicationInstanceTerminatedEventListener() {
             @Override
             protected void onEvent(Event event) {
                 //Remove the application related data

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java
index f49cda2..743ab73 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java
@@ -781,8 +781,8 @@ public class TopologyBuilder {
             return;
         }
 
-        org.apache.stratos.messaging.event.topology.ClusterActivatedEvent clusterActivatedEvent1 =
-                new org.apache.stratos.messaging.event.topology.ClusterActivatedEvent(
+        ClusterInstanceActivatedEvent clusterActivatedEvent1 =
+                new ClusterInstanceActivatedEvent(
                         clusterActivatedEvent.getAppId(),
                         clusterActivatedEvent.getServiceName(),
                         clusterActivatedEvent.getClusterId(),
@@ -833,8 +833,8 @@ public class TopologyBuilder {
             return;
         }
 
-        ClusterInactivateEvent clusterInActivatedEvent1 =
-                new ClusterInactivateEvent(
+        ClusterInstanceInactivateEvent clusterInActivatedEvent1 =
+                new ClusterInstanceInactivateEvent(
                         clusterInActivateEvent.getAppId(),
                         clusterInActivateEvent.getServiceName(),
                         clusterInActivateEvent.getClusterId(),
@@ -902,7 +902,7 @@ public class TopologyBuilder {
                 log.info("Cluster Terminated adding status started for" + cluster.getClusterId());
                 TopologyManager.updateTopology(topology);
                 //publishing data
-                ClusterTerminatedEvent clusterTerminatedEvent = new ClusterTerminatedEvent(event.getAppId(),
+                ClusterInstanceTerminatedEvent clusterTerminatedEvent = new ClusterInstanceTerminatedEvent(event.getAppId(),
                         event.getServiceName(), event.getClusterId(), event.getInstanceId());
 
                 TopologyEventPublisher.sendClusterTerminatedEvent(clusterTerminatedEvent);
@@ -945,7 +945,7 @@ public class TopologyBuilder {
                 log.info("Cluster Terminating adding status started for" + cluster.getClusterId());
                 TopologyManager.updateTopology(topology);
                 //publishing data
-                ClusterTerminatingEvent clusterTerminaingEvent = new ClusterTerminatingEvent(event.getAppId(),
+                ClusterInstanceTerminatingEvent clusterTerminaingEvent = new ClusterInstanceTerminatingEvent(event.getAppId(),
                         event.getServiceName(), event.getClusterId(), event.getInstanceId());
 
                 TopologyEventPublisher.sendClusterTerminatingEvent(clusterTerminaingEvent);

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyEventPublisher.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyEventPublisher.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyEventPublisher.java
index eea941c..2965a6f 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyEventPublisher.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyEventPublisher.java
@@ -228,7 +228,7 @@ public class TopologyEventPublisher {
         publishEvent(memberMaintenanceModeEvent);
     }
 
-    public static void sendClusterActivatedEvent(ClusterActivatedEvent clusterActivatedEvent) {
+    public static void sendClusterActivatedEvent(ClusterInstanceActivatedEvent clusterActivatedEvent) {
         if (log.isInfoEnabled()) {
             log.info(String.format("Publishing cluster activated event: [service] %s [cluster] %s " +
                             " [instance-id] %s [appId] %s",
@@ -240,7 +240,7 @@ public class TopologyEventPublisher {
         publishEvent(clusterActivatedEvent);
     }
 
-    public static void sendClusterInactivateEvent(ClusterInactivateEvent clusterInactiveEvent) {
+    public static void sendClusterInactivateEvent(ClusterInstanceInactivateEvent clusterInactiveEvent) {
         if (log.isInfoEnabled()) {
             log.info(String.format("Publishing cluster in-active event: [service] %s [cluster] %s " +
                             "[instance-id] %s [appId] %s",
@@ -289,7 +289,7 @@ public class TopologyEventPublisher {
         publishEvent(completeTopologyEvent);
     }
 
-    public static void sendClusterTerminatingEvent(ClusterTerminatingEvent clusterTerminatingEvent) {
+    public static void sendClusterTerminatingEvent(ClusterInstanceTerminatingEvent clusterTerminatingEvent) {
 
         if (log.isInfoEnabled()) {
             log.info(String.format("Publishing Cluster terminating event: [appId] %s [cluster id] %s" +
@@ -301,7 +301,7 @@ public class TopologyEventPublisher {
         publishEvent(clusterTerminatingEvent);
     }
 
-    public static void sendClusterTerminatedEvent(ClusterTerminatedEvent clusterTerminatedEvent) {
+    public static void sendClusterTerminatedEvent(ClusterInstanceTerminatedEvent clusterTerminatedEvent) {
 
         if (log.isInfoEnabled()) {
             log.info(String.format("Publishing Cluster terminated event: [appId] %s [cluster id] %s" +

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/ApplicationActivatedEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/ApplicationActivatedEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/ApplicationActivatedEvent.java
deleted file mode 100644
index 68a63a8..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/ApplicationActivatedEvent.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.messaging.event.applications;
-
-import org.apache.stratos.messaging.event.Event;
-
-import java.io.Serializable;
-
-/**
- * This event will be fired upon the application activated is detected.
- */
-public class ApplicationActivatedEvent extends Event implements Serializable {
-    private static final long serialVersionUID = 2625412714611885089L;
-
-    private String appId;
-    private String instanceId;
-
-    public ApplicationActivatedEvent(String appId, String instanceId) {
-        this.appId = appId;
-        this.instanceId = instanceId;
-    }
-
-    public String getAppId() {
-        return appId;
-    }
-
-    public String getInstanceId() {
-        return instanceId;
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/ApplicationInstanceActivatedEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/ApplicationInstanceActivatedEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/ApplicationInstanceActivatedEvent.java
new file mode 100644
index 0000000..855f07e
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/ApplicationInstanceActivatedEvent.java
@@ -0,0 +1,46 @@
+/*
+ * 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.messaging.event.applications;
+
+import org.apache.stratos.messaging.event.Event;
+
+import java.io.Serializable;
+
+/**
+ * This event will be fired upon the application activated is detected.
+ */
+public class ApplicationInstanceActivatedEvent extends Event implements Serializable {
+    private static final long serialVersionUID = 2625412714611885089L;
+
+    private String appId;
+    private String instanceId;
+
+    public ApplicationInstanceActivatedEvent(String appId, String instanceId) {
+        this.appId = appId;
+        this.instanceId = instanceId;
+    }
+
+    public String getAppId() {
+        return appId;
+    }
+
+    public String getInstanceId() {
+        return instanceId;
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupActivatedEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupActivatedEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupActivatedEvent.java
deleted file mode 100644
index c106949..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupActivatedEvent.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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.messaging.event.applications;
-
-import org.apache.stratos.messaging.event.Event;
-
-import java.io.Serializable;
-
-/**
- * This event is fired by cartridge agent when it has started the server and
- * applications are ready to serve the incoming requests.
- */
-public class GroupActivatedEvent extends Event implements Serializable {
-    private static final long serialVersionUID = 2625412714611885089L;
-
-    private String groupId;
-    private String appId;
-    private String instanceId;
-
-    public GroupActivatedEvent(String appId, String groupId, String instanceId) {
-        this.appId = appId;
-        this.groupId = groupId;
-        this.instanceId = instanceId;
-    }
-
-    public String getGroupId() {
-        return this.groupId;
-    }
-
-    public String getAppId() {
-        return appId;
-    }
-
-    public String getInstanceId() {
-        return instanceId;
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupInactivatedEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupInactivatedEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupInactivatedEvent.java
deleted file mode 100644
index 9160e54..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupInactivatedEvent.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.messaging.event.applications;
-
-import org.apache.stratos.messaging.event.Event;
-
-import java.io.Serializable;
-
-public class GroupInactivatedEvent extends Event implements Serializable {
-
-    private static final long serialVersionUID = 2625412714611885089L;
-
-    private String groupId;
-    private String appId;
-    private String instanceId;
-
-    public GroupInactivatedEvent(String appId, String groupId, String instanceId) {
-        this.appId = appId;
-        this.groupId = groupId;
-        this.instanceId = instanceId;
-    }
-
-    public String getGroupId() {
-        return this.groupId;
-    }
-
-    public String getAppId() {
-        return appId;
-    }
-
-    public String getInstanceId() {
-        return instanceId;
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupInstanceActivatedEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupInstanceActivatedEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupInstanceActivatedEvent.java
new file mode 100644
index 0000000..02b343d
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupInstanceActivatedEvent.java
@@ -0,0 +1,54 @@
+/*
+ * 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.messaging.event.applications;
+
+import org.apache.stratos.messaging.event.Event;
+
+import java.io.Serializable;
+
+/**
+ * This event is fired by cartridge agent when it has started the server and
+ * applications are ready to serve the incoming requests.
+ */
+public class GroupInstanceActivatedEvent extends Event implements Serializable {
+    private static final long serialVersionUID = 2625412714611885089L;
+
+    private String groupId;
+    private String appId;
+    private String instanceId;
+
+    public GroupInstanceActivatedEvent(String appId, String groupId, String instanceId) {
+        this.appId = appId;
+        this.groupId = groupId;
+        this.instanceId = instanceId;
+    }
+
+    public String getGroupId() {
+        return this.groupId;
+    }
+
+    public String getAppId() {
+        return appId;
+    }
+
+    public String getInstanceId() {
+        return instanceId;
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupInstanceCreatedEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupInstanceCreatedEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupInstanceCreatedEvent.java
new file mode 100644
index 0000000..a4b3c5a
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupInstanceCreatedEvent.java
@@ -0,0 +1,55 @@
+/*
+ * 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.messaging.event.applications;
+
+import org.apache.stratos.messaging.domain.instance.GroupInstance;
+import org.apache.stratos.messaging.event.Event;
+
+import java.io.Serializable;
+
+/**
+ * This event is fired by cartridge agent when it has started the server and
+ * applications are ready to serve the incoming requests.
+ */
+public class GroupInstanceCreatedEvent extends Event implements Serializable {
+    private static final long serialVersionUID = 2625412714611885089L;
+
+    private String groupId;
+    private String appId;
+    private GroupInstance groupInstance;
+
+    public GroupInstanceCreatedEvent(String appId, String groupId, GroupInstance groupInstance) {
+        this.appId = appId;
+        this.groupId = groupId;
+        this.groupInstance = groupInstance;
+    }
+
+    public String getGroupId() {
+        return this.groupId;
+    }
+
+    public String getAppId() {
+        return appId;
+    }
+
+    public GroupInstance getGroupInstance() {
+        return groupInstance;
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupInstanceInactivatedEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupInstanceInactivatedEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupInstanceInactivatedEvent.java
new file mode 100644
index 0000000..d57b3c5
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupInstanceInactivatedEvent.java
@@ -0,0 +1,51 @@
+/*
+ * 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.messaging.event.applications;
+
+import org.apache.stratos.messaging.event.Event;
+
+import java.io.Serializable;
+
+public class GroupInstanceInactivatedEvent extends Event implements Serializable {
+
+    private static final long serialVersionUID = 2625412714611885089L;
+
+    private String groupId;
+    private String appId;
+    private String instanceId;
+
+    public GroupInstanceInactivatedEvent(String appId, String groupId, String instanceId) {
+        this.appId = appId;
+        this.groupId = groupId;
+        this.instanceId = instanceId;
+    }
+
+    public String getGroupId() {
+        return this.groupId;
+    }
+
+    public String getAppId() {
+        return appId;
+    }
+
+    public String getInstanceId() {
+        return instanceId;
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupInstanceTerminatedEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupInstanceTerminatedEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupInstanceTerminatedEvent.java
new file mode 100644
index 0000000..3c8ffb2
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupInstanceTerminatedEvent.java
@@ -0,0 +1,54 @@
+/*
+ * 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.messaging.event.applications;
+
+import org.apache.stratos.messaging.event.Event;
+
+import java.io.Serializable;
+
+/**
+ * This event is fired by cartridge agent when it has started the server and
+ * applications are ready to serve the incoming requests.
+ */
+public class GroupInstanceTerminatedEvent extends Event implements Serializable {
+    private static final long serialVersionUID = 2625412714611885089L;
+
+    private String groupId;
+    private String appId;
+    private String instanceId;
+
+    public GroupInstanceTerminatedEvent(String appId, String groupId, String instanceId) {
+        this.appId = appId;
+        this.groupId = groupId;
+        this.instanceId = instanceId;
+    }
+
+    public String getGroupId() {
+        return this.groupId;
+    }
+
+    public String getAppId() {
+        return appId;
+    }
+
+    public String getInstanceId() {
+        return instanceId;
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupInstanceTerminatingEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupInstanceTerminatingEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupInstanceTerminatingEvent.java
new file mode 100644
index 0000000..65b069b
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupInstanceTerminatingEvent.java
@@ -0,0 +1,54 @@
+/*
+ * 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.messaging.event.applications;
+
+import org.apache.stratos.messaging.event.Event;
+
+import java.io.Serializable;
+
+/**
+ * This event is fired by cartridge agent when it has started the server and
+ * applications are ready to serve the incoming requests.
+ */
+public class GroupInstanceTerminatingEvent extends Event implements Serializable {
+    private static final long serialVersionUID = 2625412714611885089L;
+
+    private String groupId;
+    private String appId;
+    private String instanceId;
+
+    public GroupInstanceTerminatingEvent(String appId, String groupId, String instanceId) {
+        this.appId = appId;
+        this.groupId = groupId;
+        this.instanceId = instanceId;
+    }
+
+    public String getGroupId() {
+        return this.groupId;
+    }
+
+    public String getAppId() {
+        return appId;
+    }
+
+    public String getInstanceId() {
+        return instanceId;
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupResetEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupResetEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupResetEvent.java
deleted file mode 100644
index 206b526..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupResetEvent.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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.messaging.event.applications;
-
-import org.apache.stratos.messaging.event.Event;
-
-import java.io.Serializable;
-
-/**
- * This event is fired by cartridge agent when it has started the server and
- * applications are ready to serve the incoming requests.
- */
-public class GroupResetEvent extends Event implements Serializable {
-    private static final long serialVersionUID = 2625412714611885089L;
-
-    private String groupId;
-    private String appId;
-    private String instanceId;
-
-    public GroupResetEvent(String appId, String groupId, String instanceId) {
-        this.appId = appId;
-        this.groupId = groupId;
-        this.instanceId = instanceId;
-    }
-
-    public String getGroupId() {
-        return this.groupId;
-    }
-
-    public String getAppId() {
-        return appId;
-    }
-
-    public String getInstanceId() {
-        return instanceId;
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupTerminatedEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupTerminatedEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupTerminatedEvent.java
deleted file mode 100644
index a7bf347..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupTerminatedEvent.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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.messaging.event.applications;
-
-import org.apache.stratos.messaging.event.Event;
-
-import java.io.Serializable;
-
-/**
- * This event is fired by cartridge agent when it has started the server and
- * applications are ready to serve the incoming requests.
- */
-public class GroupTerminatedEvent extends Event implements Serializable {
-    private static final long serialVersionUID = 2625412714611885089L;
-
-    private String groupId;
-    private String appId;
-    private String instanceId;
-
-    public GroupTerminatedEvent(String appId, String groupId, String instanceId) {
-        this.appId = appId;
-        this.groupId = groupId;
-        this.instanceId = instanceId;
-    }
-
-    public String getGroupId() {
-        return this.groupId;
-    }
-
-    public String getAppId() {
-        return appId;
-    }
-
-    public String getInstanceId() {
-        return instanceId;
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupTerminatingEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupTerminatingEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupTerminatingEvent.java
deleted file mode 100644
index 6f79b15..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/applications/GroupTerminatingEvent.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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.messaging.event.applications;
-
-import org.apache.stratos.messaging.event.Event;
-
-import java.io.Serializable;
-
-/**
- * This event is fired by cartridge agent when it has started the server and
- * applications are ready to serve the incoming requests.
- */
-public class GroupTerminatingEvent extends Event implements Serializable {
-    private static final long serialVersionUID = 2625412714611885089L;
-
-    private String groupId;
-    private String appId;
-    private String instanceId;
-
-    public GroupTerminatingEvent(String appId, String groupId, String instanceId) {
-        this.appId = appId;
-        this.groupId = groupId;
-        this.instanceId = instanceId;
-    }
-
-    public String getGroupId() {
-        return this.groupId;
-    }
-
-    public String getAppId() {
-        return appId;
-    }
-
-    public String getInstanceId() {
-        return instanceId;
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterActivatedEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterActivatedEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterActivatedEvent.java
deleted file mode 100644
index c3f6adf..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterActivatedEvent.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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.messaging.event.topology;
-
-import org.apache.stratos.messaging.domain.topology.ClusterStatus;
-import org.apache.stratos.messaging.event.Event;
-
-/**
- * Cluster activated event will be sent by Autoscaler
- */
-public class ClusterActivatedEvent extends Event {
-
-    private final String serviceName;
-    private final String clusterId;
-    private String appId;
-    private String instanceId;
-
-    public ClusterActivatedEvent(String appId, String serviceName, String clusterId, String instanceId) {
-        this.serviceName = serviceName;
-        this.clusterId = clusterId;
-        this.appId = appId;
-        this.instanceId = instanceId;
-    }
-
-    public String getServiceName() {
-        return serviceName;
-    }
-
-    @Override
-    public String toString() {
-        return "ClusterActivatedEvent [serviceName=" + serviceName + ", clusterStatus=" +
-                "]";
-    }
-
-    public String getClusterId() {
-        return clusterId;
-    }
-
-    public String getAppId() {
-        return appId;
-    }
-
-    public String getInstanceId() {
-        return instanceId;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterInactivateEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterInactivateEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterInactivateEvent.java
deleted file mode 100644
index 4ace80e..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterInactivateEvent.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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.messaging.event.topology;
-
-import org.apache.stratos.messaging.event.Event;
-
-/**
- * Cluster activated event will be sent by Autoscaler
- */
-public class ClusterInactivateEvent extends Event {
-
-    private final String serviceName;
-    private final String clusterId;
-    private String appId;
-    private String instanceId;
-
-
-    public ClusterInactivateEvent(String appId, String serviceName, String clusterId, String instanceId) {
-        this.serviceName = serviceName;
-        this.clusterId = clusterId;
-        this.appId = appId;
-        this.instanceId = instanceId;
-
-    }
-
-    public String getServiceName() {
-        return serviceName;
-    }
-
-    @Override
-    public String toString() {
-        return "ClusterActivatedEvent [serviceName=" + serviceName + ", clusterStatus=" +
-                "]";
-    }
-
-    public String getClusterId() {
-        return clusterId;
-    }
-
-    public String getAppId() {
-        return appId;
-    }
-
-    public String getInstanceId() {
-        return instanceId;
-    }
-}


[5/5] stratos git commit: fixing group level deployment policy parsing and improving processors

Posted by re...@apache.org.
fixing group level deployment policy parsing and improving processors


Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/3bd20e5e
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/3bd20e5e
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/3bd20e5e

Branch: refs/heads/master
Commit: 3bd20e5ee2a4479a8953df6c6e62e478b8ebd672
Parents: cf1b372
Author: reka <rt...@gmail.com>
Authored: Fri Dec 5 19:09:56 2014 +0530
Committer: reka <rt...@gmail.com>
Committed: Fri Dec 5 19:09:56 2014 +0530

----------------------------------------------------------------------
 .../autoscaler/api/AutoScalerServiceImpl.java   |   1 +
 .../context/cluster/VMClusterContext.java       |  43 +--
 .../ClusterLevelNetworkPartitionContext.java    |  10 +-
 .../GroupLevelNetworkPartitionContext.java      |  85 +++-
 .../AutoscalerTopologyEventReceiver.java        | 162 ++++----
 .../autoscaler/monitor/MonitorFactory.java      |  22 +-
 .../monitor/component/GroupMonitor.java         | 384 +++++++++----------
 .../component/ParentComponentMonitor.java       |  21 +-
 .../policy/deployment/DeploymentPolicy.java     |  14 -
 .../cluster/ClusterStatusActiveProcessor.java   |   1 +
 .../cluster/ClusterStatusInActiveProcessor.java |   8 +-
 .../group/GroupStatusInActiveProcessor.java     |   1 +
 .../application/beans/GroupDefinition.java      |   2 +-
 .../domain/instance/ClusterInstance.java        |  11 -
 .../domain/instance/GroupInstance.java          |   8 -
 .../messaging/domain/instance/Instance.java     |  11 +
 .../ApplicationsMessageProcessorChain.java      |   6 +
 .../rest/endpoint/api/StratosApiV41.java        |   2 +-
 18 files changed, 406 insertions(+), 386 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/3bd20e5e/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/api/AutoScalerServiceImpl.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/api/AutoScalerServiceImpl.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/api/AutoScalerServiceImpl.java
index bd98a76..64016fc 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/api/AutoScalerServiceImpl.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/api/AutoScalerServiceImpl.java
@@ -190,6 +190,7 @@ public class AutoScalerServiceImpl implements AutoScalerServiceInterface {
                 }
             } catch (PartitionValidationException e) {
                 log.error("Error while validating the deployment policy", e);
+                //TODO throw exception
             } finally {
                 ApplicationHolder.releaseReadLock();
             }

http://git-wip-us.apache.org/repos/asf/stratos/blob/3bd20e5e/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/cluster/VMClusterContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/cluster/VMClusterContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/cluster/VMClusterContext.java
index 2f83178..f506596 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/cluster/VMClusterContext.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/cluster/VMClusterContext.java
@@ -21,7 +21,6 @@ package org.apache.stratos.autoscaler.context.cluster;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.autoscaler.applications.ApplicationHolder;
-import org.apache.stratos.autoscaler.client.CloudControllerClient;
 import org.apache.stratos.autoscaler.context.member.MemberStatsContext;
 import org.apache.stratos.autoscaler.context.partition.ClusterLevelPartitionContext;
 import org.apache.stratos.autoscaler.context.partition.network.ClusterLevelNetworkPartitionContext;
@@ -131,7 +130,7 @@ public class VMClusterContext extends AbstractClusterContext {
             networkPartitionContext = this.networkPartitionCtxts.get(
                     clusterInstance.getNetworkPartitionId());
         } else {
-            if(policy != null) {
+            if (policy != null) {
                 ChildLevelNetworkPartition networkPartition = policy.
                         getChildLevelNetworkPartition(clusterInstance.getNetworkPartitionId());
                 networkPartitionContext = new ClusterLevelNetworkPartitionContext(networkPartition.getId(),
@@ -139,9 +138,7 @@ public class VMClusterContext extends AbstractClusterContext {
             } else {
                 //Parent should have the partition specified
                 networkPartitionContext = new ClusterLevelNetworkPartitionContext(
-                                                        clusterInstance.getNetworkPartitionId(),
-                                                        null,
-                                                        0);
+                        clusterInstance.getNetworkPartitionId());
             }
 
         }
@@ -149,7 +146,7 @@ public class VMClusterContext extends AbstractClusterContext {
         if (clusterInstance.getPartitionId() != null) {
             //Need to add partition Context based on the given one from the parent
             networkPartitionContext = addPartition(clusterInstance, cluster,
-                                                    networkPartitionContext, null);
+                    networkPartitionContext, null);
         } else {
             networkPartitionContext = parseDeploymentPolicy(clusterInstance, cluster,
                     policy, networkPartitionContext);
@@ -159,7 +156,7 @@ public class VMClusterContext extends AbstractClusterContext {
                     networkPartitionContext);
             if (log.isInfoEnabled()) {
                 log.info(String.format("Cluster instance context has been added to network partition, [cluster instance]" +
-                        " %s [network partition] %s", clusterInstance.getInstanceId(),
+                                " %s [network partition] %s", clusterInstance.getInstanceId(),
                         clusterInstance.getNetworkPartitionId()));
             }
         }
@@ -178,7 +175,7 @@ public class VMClusterContext extends AbstractClusterContext {
             log.error(msg);
             throw new PolicyValidationException(msg);
         }
-        
+
         if (log.isDebugEnabled()) {
             log.debug("Deployment policy name: " + childPolicy.getId());
         }
@@ -198,12 +195,12 @@ public class VMClusterContext extends AbstractClusterContext {
         //Retrieving the ChildLevelNetworkPartition and create NP Context
         ChildLevelNetworkPartition networkPartition;
         networkPartition = childPolicy.
-                                getChildLevelNetworkPartition(clusterInstance.getNetworkPartitionId());
+                getChildLevelNetworkPartition(clusterInstance.getNetworkPartitionId());
         if (clusterLevelNetworkPartitionContext == null) {
             clusterLevelNetworkPartitionContext = new ClusterLevelNetworkPartitionContext(
-                                                                networkPartition.getId(),
-                                                                networkPartition.getPartitionAlgo(),
-                                                                networkPartition.getMin());
+                    networkPartition.getId(),
+                    networkPartition.getPartitionAlgo(),
+                    networkPartition.getMin());
         }
 
         //Fill cluster instance context with child level partitions
@@ -240,7 +237,7 @@ public class VMClusterContext extends AbstractClusterContext {
         }
 
         ClusterInstanceContext clusterInstanceContext = clusterLevelNetworkPartitionContext.
-                                        getClusterInstanceContext(clusterInstance.getInstanceId());
+                getClusterInstanceContext(clusterInstance.getInstanceId());
         int maxInstances = 1;
         if (clusterInstanceContext == null) {
             int minInstances = 1;
@@ -248,7 +245,8 @@ public class VMClusterContext extends AbstractClusterContext {
             try {
                 Application application = ApplicationHolder.getApplications().
                         getApplication(cluster.getAppId());
-                ClusterDataHolder dataHolder = application.getClusterData(AutoscalerUtil.getAliasFromClusterId(clusterId));
+                ClusterDataHolder dataHolder = application.
+                        getClusterData(AutoscalerUtil.getAliasFromClusterId(clusterId));
                 minInstances = dataHolder.getMinInstances();
                 maxInstances = dataHolder.getMaxInstances();
             } finally {
@@ -256,10 +254,10 @@ public class VMClusterContext extends AbstractClusterContext {
             }
             clusterInstanceContext = new ClusterInstanceContext(clusterInstance.getInstanceId(),
                     clusterLevelNetworkPartitionContext.getPartitionAlgorithm(),
-                    minInstances, maxInstances , nPartitionId);
+                    minInstances, maxInstances, nPartitionId);
         }
         String partitionId;
-        if(childLevelPartition != null) {
+        if (childLevelPartition != null) {
             //use it own defined partition
             partitionId = childLevelPartition.getPartitionId();
             maxInstances = childLevelPartition.getMax();
@@ -269,18 +267,19 @@ public class VMClusterContext extends AbstractClusterContext {
         }
         //Retrieving the actual partition from application
         Partition appPartition = deploymentPolicy.getApplicationLevelNetworkPartition(nPartitionId).
-                                                                        getPartition(partitionId);
+                getPartition(partitionId);
         org.apache.stratos.cloud.controller.stub.domain.Partition partition =
                 convertTOCCPartition(appPartition);
 
         //Validate the partition
-        CloudControllerClient.getInstance().validatePartition(partition);
+        //TODO validate partition removal
+        //CloudControllerClient.getInstance().validatePartition(partition);
 
         //Creating cluster level partition context
         ClusterLevelPartitionContext clusterLevelPartitionContext = new ClusterLevelPartitionContext(
-                                                        maxInstances,
-                                                        partition,
-                                                        clusterInstance.getNetworkPartitionId());
+                maxInstances,
+                partition,
+                clusterInstance.getNetworkPartitionId());
         clusterLevelPartitionContext.setServiceName(cluster.getServiceName());
         clusterLevelPartitionContext.setProperties(cluster.getProperties());
 
@@ -302,8 +301,6 @@ public class VMClusterContext extends AbstractClusterContext {
         }
 
 
-
-
         return clusterLevelNetworkPartitionContext;
     }
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/3bd20e5e/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/network/ClusterLevelNetworkPartitionContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/network/ClusterLevelNetworkPartitionContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/network/ClusterLevelNetworkPartitionContext.java
index 036228d..bb00c2b 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/network/ClusterLevelNetworkPartitionContext.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/network/ClusterLevelNetworkPartitionContext.java
@@ -36,23 +36,25 @@ public class ClusterLevelNetworkPartitionContext extends NetworkPartitionContext
     private static final long serialVersionUID = 572769304374110159L;
     private final String id;
 
-    private final String partitionAlgorithm;
+    private String partitionAlgorithm;
     private int min;
 
     private Map<String, ClusterInstanceContext> instanceIdToClusterInstanceContextMap;
 
 
     public ClusterLevelNetworkPartitionContext(String id, String partitionAlgorithm, int min) {
-
-        //super(id, partitionAlgo, partitions);
         this.id = id;
         this.partitionAlgorithm = partitionAlgorithm;
         this.min = min;
-
         setInstanceIdToClusterInstanceContextMap(new HashMap<String, ClusterInstanceContext>());
 
     }
 
+    public ClusterLevelNetworkPartitionContext(String id) {
+        this.id = id;
+        setInstanceIdToClusterInstanceContextMap(new HashMap<String, ClusterInstanceContext>());
+    }
+
 
     public int hashCode() {
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/3bd20e5e/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/network/GroupLevelNetworkPartitionContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/network/GroupLevelNetworkPartitionContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/network/GroupLevelNetworkPartitionContext.java
index 402bbfa..3ffe6d3 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/network/GroupLevelNetworkPartitionContext.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/network/GroupLevelNetworkPartitionContext.java
@@ -21,16 +21,16 @@ package org.apache.stratos.autoscaler.context.partition.network;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.autoscaler.context.group.GroupInstanceContext;
-import org.apache.stratos.autoscaler.context.partition.ClusterLevelPartitionContext;
 import org.apache.stratos.autoscaler.context.partition.GroupLevelPartitionContext;
-import org.apache.stratos.cloud.controller.stub.domain.Partition;
 
 import java.io.Serializable;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * Holds runtime data of a network partition.
- *
  */
 public class GroupLevelNetworkPartitionContext extends NetworkPartitionContext implements Serializable {
     private static final Log log = LogFactory.getLog(GroupLevelNetworkPartitionContext.class);
@@ -42,9 +42,10 @@ public class GroupLevelNetworkPartitionContext extends NetworkPartitionContext i
     private int requiredInstanceCountBasedOnStats;
     private int requiredInstanceCountBasedOnDependencies;
 
-    private final String partitionAlgorithm;
+    private String partitionAlgorithm;
 
-    private final Partition[] partitions;
+    //Group level partition contexts
+    private List<GroupLevelPartitionContext> partitionContexts;
 
     //details required for partition selection algorithms
     private int currentPartitionIndex;
@@ -52,18 +53,10 @@ public class GroupLevelNetworkPartitionContext extends NetworkPartitionContext i
     //group instances kept inside a partition
     private Map<String, GroupInstanceContext> instanceIdToInstanceContextMap;
 
-    public GroupLevelNetworkPartitionContext(String id, String partitionAlgo, Partition[] partitions) {
+    public GroupLevelNetworkPartitionContext(String id, String partitionAlgo) {
         this.id = id;
         this.partitionAlgorithm = partitionAlgo;
-        if (partitions == null) {
-            this.partitions = new Partition[0];
-        } else {
-            this.partitions = Arrays.copyOf(partitions, partitions.length);
-        }
-        for (Partition partition : partitions) {
-            minInstanceCount += partition.getPartitionMin();
-            maxInstanceCount += partition.getPartitionMax();
-        }
+        partitionContexts = new ArrayList<GroupLevelPartitionContext>();
         requiredInstanceCountBasedOnStats = minInstanceCount;
         requiredInstanceCountBasedOnDependencies = minInstanceCount;
         instanceIdToInstanceContextMap = new HashMap<String, GroupInstanceContext>();
@@ -71,6 +64,14 @@ public class GroupLevelNetworkPartitionContext extends NetworkPartitionContext i
 
     }
 
+    public GroupLevelNetworkPartitionContext(String id) {
+        this.id = id;
+        partitionContexts = new ArrayList<GroupLevelPartitionContext>();
+        requiredInstanceCountBasedOnStats = minInstanceCount;
+        requiredInstanceCountBasedOnDependencies = minInstanceCount;
+        instanceIdToInstanceContextMap = new HashMap<String, GroupInstanceContext>();
+    }
+
     public Map<String, GroupInstanceContext> getInstanceIdToInstanceContextMap() {
         return instanceIdToInstanceContextMap;
     }
@@ -150,15 +151,10 @@ public class GroupLevelNetworkPartitionContext extends NetworkPartitionContext i
     }
 
 
-
     public String getPartitionAlgorithm() {
         return partitionAlgorithm;
     }
 
-    public Partition[] getPartitions() {
-        return partitions;
-    }
-
     public int getScaleDownRequestsCount() {
         return scaleDownRequestsCount;
     }
@@ -187,6 +183,53 @@ public class GroupLevelNetworkPartitionContext extends NetworkPartitionContext i
         this.requiredInstanceCountBasedOnDependencies = requiredInstanceCountBasedOnDependencies;
     }
 
+    public List<GroupLevelPartitionContext> getPartitionCtxts() {
+
+        return partitionContexts;
+    }
+
+    public GroupLevelPartitionContext getPartitionCtxt(String partitionId) {
+
+        for (GroupLevelPartitionContext partitionContext : partitionContexts) {
+            if (partitionContext.getPartitionId().equals(partitionId)) {
+                return partitionContext;
+            }
+        }
+        return null;
+    }
+
+    public void addPartitionContext(GroupLevelPartitionContext partitionContext) {
+        partitionContexts.add(partitionContext);
+    }
+
+    public int getNonTerminatedMemberCountOfPartition(String partitionId) {
+
+        for (GroupLevelPartitionContext partitionContext : partitionContexts) {
+            if (partitionContext.getPartitionId().equals(partitionId)) {
+                return partitionContext.getNonTerminatedInstanceCount();
+            }
+        }
+        return 0;
+    }
+
+    public int getActiveMemberCount(String currentPartitionId) {
+
+        for (GroupLevelPartitionContext partitionContext : partitionContexts) {
+            if (partitionContext.getPartitionId().equals(currentPartitionId)) {
+                return partitionContext.getActiveInstanceCount();
+            }
+        }
+        return 0;
+    }
+
+    public GroupLevelPartitionContext getPartitionContextById(String partitionId) {
+        for (GroupLevelPartitionContext partitionContext : partitionContexts) {
+            if (partitionContext.getPartitionId().equals(partitionId)) {
+                return partitionContext;
+            }
+        }
+        return null;
+    }
 
 
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/3bd20e5e/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/topology/AutoscalerTopologyEventReceiver.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/topology/AutoscalerTopologyEventReceiver.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/topology/AutoscalerTopologyEventReceiver.java
index e1357f5..e007a3f 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/topology/AutoscalerTopologyEventReceiver.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/topology/AutoscalerTopologyEventReceiver.java
@@ -412,87 +412,87 @@ public class AutoscalerTopologyEventReceiver {
         });
 
         topologyEventReceiver.addEventListener(new ClusterInstanceCreatedEventListener() {
-                                                   @Override
-                                                   protected void onEvent(Event event) {
-
-                                                       ClusterInstanceCreatedEvent clusterInstanceCreatedEvent =
-                                                               (ClusterInstanceCreatedEvent) event;
-                                                       AbstractClusterMonitor clusterMonitor = AutoscalerContext.getInstance().
-                                                               getClusterMonitor(clusterInstanceCreatedEvent.getClusterId());
-                                                       String instanceId = ((ClusterInstanceCreatedEvent) event).getInstanceId();
-                                                       //FIXME to take lock when clusterMonitor is running
-                                                       if (clusterMonitor != null) {
-                                                           TopologyManager.acquireReadLockForCluster(clusterInstanceCreatedEvent.getServiceName(),
-                                                                   clusterInstanceCreatedEvent.getClusterId());
-
-                                                           try {
-                                                               Service service = TopologyManager.getTopology().
-                                                                       getService(clusterInstanceCreatedEvent.getServiceName());
-
-                                                               if (service != null) {
-                                                                   Cluster cluster = service.getCluster(clusterInstanceCreatedEvent.getClusterId());
-                                                                   if (cluster != null) {
-                                                                       try {
-                                                                           if (cluster.isKubernetesCluster()) {
-                                                                               clusterMonitor.setClusterContext(
-                                                                                       ClusterContextFactory.getKubernetesClusterContext(
-                                                                                               instanceId,
-                                                                                               cluster));
-                                                                           } else {
-                                                                               VMClusterContext clusterContext =
-                                                                                       (VMClusterContext) clusterMonitor.getClusterContext();
-                                                                               if (clusterContext == null) {
-                                                                                   clusterContext = ClusterContextFactory.
-                                                                                           getVMClusterContext(instanceId,
-                                                                                                   cluster);
-                                                                                   clusterMonitor.setClusterContext(clusterContext);
-
-                                                                               }
-                                                                               clusterContext.addInstanceContext(instanceId, cluster);
-                                                                               if (clusterMonitor.getInstance(instanceId) == null) {
-                                                                                   ClusterInstance clusterInstance = cluster.
-                                                                                           getInstanceContexts(instanceId);
-                                                                                   ClusterInstance instance = new ClusterInstance(clusterInstance.getAlias(),
-                                                                                           cluster.getClusterId(),
-                                                                                           clusterInstance.getInstanceId());
-                                                                                   instance.setParentId(clusterInstance.getParentId());
-                                                                                   instance.setNetworkPartitionId(clusterInstance.getNetworkPartitionId());
-                                                                                   instance.setPartitionId(clusterInstance.getPartitionId());
-                                                                                   instance.setStatus(clusterInstance.getStatus());
-                                                                                   clusterMonitor.addInstance(instance);
-                                                                               }
-
-
-                                                                           }
-                                                                           if (clusterMonitor.hasMonitoringStarted().compareAndSet(false, true)) {
-                                                                               clusterMonitor.startScheduler();
-                                                                               log.info("Monitoring task for Cluster Monitor with cluster id " +
-                                                                                       clusterInstanceCreatedEvent.getClusterId() + " started successfully");
-                                                                           }
-                                                                       } catch (PolicyValidationException e) {
-                                                                           log.error(e.getMessage(), e);
-                                                                       } catch (PartitionValidationException e) {
-                                                                           log.error(e.getMessage(), e);
-                                                                       }
-                                                                   }
-
-                                                               } else {
-                                                                   log.error("Service " + clusterInstanceCreatedEvent.getServiceName() +
-                                                                           " not found, no cluster instance added to ClusterMonitor " +
-                                                                           clusterInstanceCreatedEvent.getClusterId());
-                                                               }
-
-                                                           } finally {
-                                                               TopologyManager.releaseReadLockForCluster(clusterInstanceCreatedEvent.getServiceName(),
-                                                                       clusterInstanceCreatedEvent.getClusterId());
-                                                           }
-
-                                                       } else {
-                                                           log.error("No Cluster Monitor found for cluster id " +
-                                                                   clusterInstanceCreatedEvent.getClusterId());
-                                                       }
-                                                   }
-                                               }
+           @Override
+           protected void onEvent(Event event) {
+
+               ClusterInstanceCreatedEvent clusterInstanceCreatedEvent =
+                       (ClusterInstanceCreatedEvent) event;
+               AbstractClusterMonitor clusterMonitor = AutoscalerContext.getInstance().
+                       getClusterMonitor(clusterInstanceCreatedEvent.getClusterId());
+               String instanceId = ((ClusterInstanceCreatedEvent) event).getInstanceId();
+               //FIXME to take lock when clusterMonitor is running
+               if (clusterMonitor != null) {
+                   TopologyManager.acquireReadLockForCluster(clusterInstanceCreatedEvent.getServiceName(),
+                           clusterInstanceCreatedEvent.getClusterId());
+
+                   try {
+                       Service service = TopologyManager.getTopology().
+                               getService(clusterInstanceCreatedEvent.getServiceName());
+
+                       if (service != null) {
+                           Cluster cluster = service.getCluster(clusterInstanceCreatedEvent.getClusterId());
+                           if (cluster != null) {
+                               try {
+                                   if (cluster.isKubernetesCluster()) {
+                                       clusterMonitor.setClusterContext(
+                                               ClusterContextFactory.getKubernetesClusterContext(
+                                                       instanceId,
+                                                       cluster));
+                                   } else {
+                                       VMClusterContext clusterContext =
+                                               (VMClusterContext) clusterMonitor.getClusterContext();
+                                       if (clusterContext == null) {
+                                           clusterContext = ClusterContextFactory.
+                                                   getVMClusterContext(instanceId,
+                                                           cluster);
+                                           clusterMonitor.setClusterContext(clusterContext);
+
+                                       }
+                                       clusterContext.addInstanceContext(instanceId, cluster);
+                                       if (clusterMonitor.getInstance(instanceId) == null) {
+                                           ClusterInstance clusterInstance = cluster.
+                                                   getInstanceContexts(instanceId);
+                                           ClusterInstance instance = new ClusterInstance(clusterInstance.getAlias(),
+                                                   cluster.getClusterId(),
+                                                   clusterInstance.getInstanceId());
+                                           instance.setParentId(clusterInstance.getParentId());
+                                           instance.setNetworkPartitionId(clusterInstance.getNetworkPartitionId());
+                                           instance.setPartitionId(clusterInstance.getPartitionId());
+                                           instance.setStatus(clusterInstance.getStatus());
+                                           clusterMonitor.addInstance(instance);
+                                       }
+
+
+                                   }
+                                   if (clusterMonitor.hasMonitoringStarted().compareAndSet(false, true)) {
+                                       clusterMonitor.startScheduler();
+                                       log.info("Monitoring task for Cluster Monitor with cluster id " +
+                                               clusterInstanceCreatedEvent.getClusterId() + " started successfully");
+                                   }
+                               } catch (PolicyValidationException e) {
+                                   log.error(e.getMessage(), e);
+                               } catch (PartitionValidationException e) {
+                                   log.error(e.getMessage(), e);
+                               }
+                           }
+
+                       } else {
+                           log.error("Service " + clusterInstanceCreatedEvent.getServiceName() +
+                                   " not found, no cluster instance added to ClusterMonitor " +
+                                   clusterInstanceCreatedEvent.getClusterId());
+                       }
+
+                   } finally {
+                       TopologyManager.releaseReadLockForCluster(clusterInstanceCreatedEvent.getServiceName(),
+                               clusterInstanceCreatedEvent.getClusterId());
+                   }
+
+               } else {
+                   log.error("No Cluster Monitor found for cluster id " +
+                           clusterInstanceCreatedEvent.getClusterId());
+               }
+           }
+       }
 
         );
     }

http://git-wip-us.apache.org/repos/asf/stratos/blob/3bd20e5e/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorFactory.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorFactory.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorFactory.java
index addffa4..964ff01 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorFactory.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorFactory.java
@@ -121,7 +121,7 @@ public class MonitorFactory {
                 groupMonitor.setParent(parentMonitor);
                 //Setting the dependent behaviour of the monitor
                 if (parentMonitor.hasStartupDependents() || (context.hasStartupDependents() &&
-                                                            context.hasChild())) {
+                        context.hasChild())) {
                     groupMonitor.setHasStartupDependents(true);
                 } else {
                     groupMonitor.setHasStartupDependents(false);
@@ -146,7 +146,7 @@ public class MonitorFactory {
             Group group = ApplicationHolder.getApplications().
                     getApplication(appId).getGroupRecursively(context.getId());
             //Starting the minimum dependencies
-            initialStartup = groupMonitor.startMinimumDependencies(group, instanceIds);
+            initialStartup = groupMonitor.createInstanceAndStartDependencyAtStartup(group, instanceIds);
         } finally {
             ApplicationHolder.releaseWriteLock();
         }
@@ -222,7 +222,7 @@ public class MonitorFactory {
             try {
                 Application application = ApplicationHolder.getApplications().getApplication(appId);
                 for (ApplicationInstance instance :
-                                        application.getInstanceIdToInstanceContextMap().values()) {
+                        application.getInstanceIdToInstanceContextMap().values()) {
                     //Starting statusChecking to make it sync with the Topology in the restart of stratos.
                     ServiceReferenceHolder.getInstance().
                             getGroupStatusProcessorChain().
@@ -282,7 +282,7 @@ public class MonitorFactory {
 
             //setting the startup dependent behaviour of the cluster monitor
             if (parentMonitor.hasStartupDependents() || (context.hasStartupDependents() &&
-                                                        context.hasChild())) {
+                    context.hasChild())) {
                 clusterMonitor.setHasStartupDependents(true);
             } else {
                 clusterMonitor.setHasStartupDependents(false);
@@ -295,16 +295,16 @@ public class MonitorFactory {
                 clusterMonitor.setHasGroupScalingDependent(false);
             }
 
-            for(String parentInstanceId : parentInstanceIds) {
+            for (String parentInstanceId : parentInstanceIds) {
                 Instance instance = parentMonitor.getInstance(parentInstanceId);
                 String partitionId = null;
-                if(instance instanceof GroupInstance) {
-                    partitionId = ((GroupInstance)instance).getPartitionId();
+                if (instance instanceof GroupInstance) {
+                    partitionId = ((GroupInstance) instance).getPartitionId();
                 }
-                if(instance != null) {
+                if (instance != null) {
                     ClusterInstance clusterInstance = cluster.getInstanceContexts(parentInstanceId);
-                    if(clusterInstance != null) {
-                        if(cluster.isKubernetesCluster()) {
+                    if (clusterInstance != null) {
+                        if (cluster.isKubernetesCluster()) {
                             clusterMonitor.setClusterContext(
                                     ClusterContextFactory.getKubernetesClusterContext(
                                             clusterInstance.getInstanceId(),
@@ -318,7 +318,7 @@ public class MonitorFactory {
                             clusterMonitor.setClusterContext(clusterContext);
                             //create VMClusterContext and then add all the instanceContexts
                             clusterContext.addInstanceContext(parentInstanceId, cluster);
-                            if(clusterMonitor.getInstance(clusterInstance.getInstanceId()) == null) {
+                            if (clusterMonitor.getInstance(clusterInstance.getInstanceId()) == null) {
                                 clusterMonitor.addInstance(clusterInstance);
                             }
                         }

http://git-wip-us.apache.org/repos/asf/stratos/blob/3bd20e5e/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java
index 8eaf32b..c8df090 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java
@@ -68,8 +68,7 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
     private boolean groupScalingEnabled;
     //Network partition contexts
     private Map<String, GroupLevelNetworkPartitionContext> networkPartitionCtxts;
-    //Group level partition contexts
-    private List<GroupLevelPartitionContext> partitionContexts;
+
     //Indicates whether the monitor is destroyed or not
     private boolean isDestroyed;
     //Monitoring interval of the monitor
@@ -125,7 +124,7 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
      * @param status status of the group
      */
     public void setStatus(GroupStatus status, String instanceId) {
-        ((GroupInstance)this.instanceIdToInstanceMap.get(instanceId)).setStatus(status);
+        ((GroupInstance) this.instanceIdToInstanceMap.get(instanceId)).setStatus(status);
 
         if (status == GroupStatus.Inactive && !this.hasStartupDependents) {
             log.info("[Group] " + this.id + "is not notifying the parent, " +
@@ -191,9 +190,9 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
             } else {
                 log.warn("[monitor] " + id + " cannot be found in the inActive monitors list");
             }
-            GroupInstance instance = (GroupInstance)this.instanceIdToInstanceMap.get(instanceId);
+            GroupInstance instance = (GroupInstance) this.instanceIdToInstanceMap.get(instanceId);
             if (instance != null) {
-                if(instance.getStatus() == GroupStatus.Terminating) {
+                if (instance.getStatus() == GroupStatus.Terminating) {
                     ServiceReferenceHolder.getInstance().getGroupStatusProcessorChain().process(this.id,
                             appId, instanceId);
                 } else {
@@ -201,7 +200,7 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
                 }
             } else {
                 log.warn("The required instance cannot be found in the the [GroupMonitor] " +
-                    this.id);
+                        this.id);
             }
         }
     }
@@ -215,13 +214,13 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
                 statusEvent.getStatus() == ApplicationStatus.Terminating) {
             //Get all the instances which related to this instanceId
             GroupInstance instance = (GroupInstance) this.instanceIdToInstanceMap.get(instanceId);
-            if(instance != null) {
+            if (instance != null) {
                 ApplicationBuilder.handleGroupTerminatingEvent(appId, id, instanceId);
             } else {
                 //Using parentId need to get the children
                 List<String> instanceIds = this.getInstancesByParentInstanceId(instanceId);
-                if(!instanceIds.isEmpty()) {
-                    for(String instanceId1 : instanceIds) {
+                if (!instanceIds.isEmpty()) {
+                    for (String instanceId1 : instanceIds) {
                         ApplicationBuilder.handleGroupTerminatingEvent(appId, id, instanceId1);
                     }
                 }
@@ -291,47 +290,6 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
     }
 
     /**
-     * This will start the minimum required dependency instances
-     * based on the given parent instance ids
-     *
-     * @param group             blue print of the instance to be started
-     * @param parentInstanceIds parent instanceIds used to start the child instance
-     * @return whether first app startup or not
-     * @throws TopologyInConsistentException
-     */
-    public boolean startMinimumDependencies(Group group, List<String> parentInstanceIds)
-            throws TopologyInConsistentException {
-        boolean initialStartup = false;
-        int min = group.getGroupMinInstances();
-        if (group.getInstanceContextCount() >= min) {
-            startDependency(group);
-        } else {
-            if (group.getInstanceContextCount() > 0) {
-                List<String> instanceIds = new ArrayList<String>();
-                for (String parentInstanceId : parentInstanceIds) {
-                    List<Instance> contexts1 = group.getInstanceContextsWithParentId(parentInstanceId);
-                    //Finding the non startable instance ids
-                    if (group.getInstanceContexts(parentInstanceId) == null || contexts1.isEmpty() ||
-                            contexts1.size() == 0) {
-                        instanceIds.add(parentInstanceId);
-
-                    }
-                }
-                if (instanceIds.size() > 0) {
-                    //createInstanceAndStartDependency(group, instanceIds);
-                } else {
-                    startDependency(group);
-                }
-            } else {
-                //No available instances in the Applications. Need to start them all
-                createInstanceAndStartDependencyAtStartup(group, parentInstanceIds);
-                initialStartup = true;
-            }
-        }
-        return initialStartup;
-    }
-   
-    /**
      * Gets the parent instance context.
      *
      * @param parentInstanceId the parent instance id
@@ -339,7 +297,7 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
      */
     private Instance getParentInstanceContext(String parentInstanceId) {
         Instance parentInstanceContext;
-        
+
         Application application = ApplicationHolder.getApplications().getApplication(this.appId);
         if (this.id.equals(appId)) {
             parentInstanceContext = application.getInstanceContexts(parentInstanceId);
@@ -347,146 +305,204 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
             Group parentGroup = application.getGroupRecursively(this.parent.getId());
             parentInstanceContext = parentGroup.getInstanceContexts(parentInstanceId);
         }
-        
+
         return parentInstanceContext;
     }
-    
+
     /**
      * Gets the group level network partition context.
      *
      * @param parentInstanceContext the parent instance context
      * @return the group level network partition context
      */
-    private GroupLevelNetworkPartitionContext getGroupLevelNetworkPartitionContext(Instance parentInstanceContext) {
-    	GroupLevelNetworkPartitionContext groupLevelNetworkPartitionContext;
+    private GroupLevelNetworkPartitionContext getGroupLevelNetworkPartitionContext(String groupId,
+                                                                                   String appId,
+                                                                                   Instance parentInstanceContext) {
+        GroupLevelNetworkPartitionContext groupLevelNetworkPartitionContext;
+        ChildPolicy policy = PolicyManager.getInstance().
+                getDeploymentPolicyByApplication(appId).
+                getChildPolicy(groupId);
+
+
         if (this.networkPartitionCtxts.containsKey(parentInstanceContext)) {
             groupLevelNetworkPartitionContext = this.networkPartitionCtxts.
                     get(parentInstanceContext.getNetworkPartitionId());
         } else {
-            groupLevelNetworkPartitionContext = new GroupLevelNetworkPartitionContext(
-                    parentInstanceContext.getNetworkPartitionId(),
-                    null, null);
+            if (policy != null) {
+                ChildLevelNetworkPartition networkPartition = policy.
+                        getChildLevelNetworkPartition(parentInstanceContext.getNetworkPartitionId());
+                groupLevelNetworkPartitionContext = new GroupLevelNetworkPartitionContext(
+                        parentInstanceContext.getNetworkPartitionId(),
+                        networkPartition.getPartitionAlgo());
+            } else {
+                groupLevelNetworkPartitionContext = new GroupLevelNetworkPartitionContext(
+                        parentInstanceContext.getNetworkPartitionId());
+            }
             this.addNetworkPartitionContext(groupLevelNetworkPartitionContext);
         }
         return groupLevelNetworkPartitionContext;
     }
-    
+
     /**
-     * Finds the correct partition context to which the instance should be added to and 
+     * Finds the correct partition context to which the instance should be added to and
      * created and adds required context objects.
      *
-     * @param parentInstanceContext the parent instance context
-     * @param group the group
+     * @param parentInstanceContext   the parent instance context
+     * @param networkPartitionContext the GroupLevelNetworkPartitionContext
      * @return the partition context
      */
-    private String FindAndAddPartitionContext(Instance parentInstanceContext, Group group, boolean startup) {
-    	PartitionContext partitionContext = null;
-    	
-    	String networkPartitionId = parentInstanceContext.getNetworkPartitionId();
-        List<GroupLevelPartitionContext> childParitionContexts = null;
-    
+    private void addPartitionContext(Instance parentInstanceContext,
+                                     GroupLevelNetworkPartitionContext networkPartitionContext) {
+
+        String networkPartitionId = parentInstanceContext.getNetworkPartitionId();
+        List<GroupLevelPartitionContext> childPartitionContexts;
+
         ChildPolicy policy = PolicyManager.getInstance().
-                getDeploymentPolicyByApplication(group.getApplicationId()).
-                getChildPolicy(group.getUniqueIdentifier());
-
-        ChildLevelNetworkPartition networkPartition = policy.
-                getChildLevelNetworkPartition(networkPartitionId);
-        
-        if (startup) {  
-            // Create childPartitionContexts for all possibilities if startup
-            ChildLevelPartition[] childLevelPartitions = networkPartition.getChildLevelPartitions();
-            childParitionContexts = new ArrayList<GroupLevelPartitionContext>();
-            for (ChildLevelPartition childLevelPartition : childLevelPartitions) {
-            	partitionContext = new GroupLevelPartitionContext(childLevelPartition.getMax(), childLevelPartition.getPartitionId(), networkPartitionId); 
-            	childParitionContexts.add((GroupLevelPartitionContext) partitionContext);
-            	this.addPartitionContext((GroupLevelPartitionContext)partitionContext);
+                getDeploymentPolicyByApplication(this.appId).
+                getChildPolicy(this.id);
+
+
+        PartitionContext partitionContext;
+        String parentPartitionId = parentInstanceContext.getPartitionId();
+
+        if (policy == null) {
+            if (parentPartitionId != null &&
+                    networkPartitionContext.getPartitionCtxt(parentPartitionId) != null) {
+                partitionContext = new GroupLevelPartitionContext(0);
+                networkPartitionContext.addPartitionContext((GroupLevelPartitionContext) partitionContext);
             }
         } else {
-        	// Get partition contexts already created
-        	childParitionContexts = this.getPartitionCtxts();
+            ChildLevelNetworkPartition networkPartition = policy.
+                    getChildLevelNetworkPartition(networkPartitionId);
+            if (networkPartitionContext.getPartitionCtxts().isEmpty()) {
+                // Create childPartitionContexts for all possibilities if startup
+                ChildLevelPartition[] childLevelPartitions = networkPartition.getChildLevelPartitions();
+                childPartitionContexts = new ArrayList<GroupLevelPartitionContext>();
+
+                for (ChildLevelPartition childLevelPartition : childLevelPartitions) {
+                    partitionContext = new GroupLevelPartitionContext(childLevelPartition.getMax(),
+                            childLevelPartition.getPartitionId(), networkPartitionId);
+                    childPartitionContexts.add((GroupLevelPartitionContext) partitionContext);
+                    networkPartitionContext.addPartitionContext(
+                            (GroupLevelPartitionContext) partitionContext);
+                }
+            }
         }
-        
-        // Get partitionContext to create instance in
-        AutoscaleAlgorithm algorithm = this.getAutoscaleAlgorithm(networkPartition.getPartitionAlgo());
-        partitionContext = algorithm.getNextScaleUpPartitionContext((PartitionContext[]) childParitionContexts.toArray());
-        
-    	return partitionContext.getPartitionId();
     }
 
     /**
      * Creates the group instance and adds the required context objects
      *
-     * @param group the group
-     * @param parentInstanceContext the parent instance context
-     * @param partitionContext the partition context
+     * @param group                             the group
+     * @param parentInstanceContext             the parent instance context
+     * @param partitionContext
      * @param groupLevelNetworkPartitionContext the group level network partition context
-     * @param instanceIdstoStart the container with instance ids to start
      */
-    private String createGroupInstance(Group group, Instance parentInstanceContext, String partitionId, 
-    		GroupLevelNetworkPartitionContext groupLevelNetworkPartitionContext, String deploymentPolicyName, boolean startup)
-    {
-    	GroupInstance groupInstance = createGroupInstance(group, parentInstanceContext.getInstanceId(), partitionId, parentInstanceContext.getNetworkPartitionId());
+    private String createGroupInstanceAndAddToMonitor(Group group, Instance parentInstanceContext,
+                                                      PartitionContext partitionContext,
+                                                      GroupLevelNetworkPartitionContext groupLevelNetworkPartitionContext,
+                                                      GroupInstance groupInstance) {
+
+        String partitionId;
+
+        if (groupInstance == null) {
+            partitionId = partitionContext.getPartitionId();
+
+            groupInstance = createGroupInstance(group, parentInstanceContext.getInstanceId(),
+                    partitionId, parentInstanceContext.getNetworkPartitionId());
+        }
+
         this.addInstance(groupInstance);
-        
+
         String instanceId = groupInstance.getInstanceId();
         GroupInstanceContext groupInstanceContext = new GroupInstanceContext(instanceId);
-        PartitionContext partitionContext = this.getPartitionCtxt(partitionId);
-        
-        if (deploymentPolicyName != null && partitionContext != null && startup) {
-        	groupInstanceContext.addPartitionContext((GroupLevelPartitionContext)partitionContext);
-        }
+
+        groupInstanceContext.addPartitionContext((GroupLevelPartitionContext) partitionContext);
         groupLevelNetworkPartitionContext.addInstanceContext(groupInstanceContext);
-        
+
         if (partitionContext != null) {
-        	((GroupLevelPartitionContext)partitionContext).addActiveInstance(groupInstance);
+            ((GroupLevelPartitionContext) partitionContext).addActiveInstance(groupInstance);
         }
-        
+
         return instanceId;
     }
-    
+
     /**
      * This will create the required instance and start the dependency
-     * This method will be called on initial startup 
+     * This method will be called on initial startup
      *
      * @param group             blue print of the instance to be started
      * @param parentInstanceIds parent instanceIds used to start the child instance
      * @throws TopologyInConsistentException
      */
-    public void createInstanceAndStartDependencyAtStartup(Group group, List<String> parentInstanceIds)
+    public boolean createInstanceAndStartDependencyAtStartup(Group group, List<String> parentInstanceIds)
             throws TopologyInConsistentException {
-        List<String> instanceIdstoStart = new ArrayList<String>();
-         
+        boolean initialStartup = true;
+        List<String> instanceIdsToStart = new ArrayList<String>();
+
         for (String parentInstanceId : parentInstanceIds) {
             // Get parent instance context
             Instance parentInstanceContext = getParentInstanceContext(parentInstanceId);
-            
-            // Get existing or create new GroupLevelNetwokPartitionContext
-            GroupLevelNetworkPartitionContext groupLevelNetworkPartitionContext = getGroupLevelNetworkPartitionContext(parentInstanceContext);
-            
-            // Determine partitionContext
-            String deploymentPolicyName = group.getDeploymentPolicy();
-            String partitionId = null;
-            if(deploymentPolicyName != null) {
-            	partitionId = FindAndAddPartitionContext(parentInstanceContext, group, true);
-            }
-            else { 
-            	GroupInstance instance = (GroupInstance) this.parent.getInstance(parentInstanceId);
-            	if (instance != null) {
-            		partitionId = instance.getPartitionId();
-            	}
-            }
-                        
+
+            // Get existing or create new GroupLevelNetworkPartitionContext
+            GroupLevelNetworkPartitionContext groupLevelNetworkPartitionContext =
+                    getGroupLevelNetworkPartitionContext(group.getUniqueIdentifier(),
+                            this.appId, parentInstanceContext);
+            //adding the partitionContext to the network partition context
+            addPartitionContext(parentInstanceContext, groupLevelNetworkPartitionContext);
+
             String groupInstanceId;
+            PartitionContext partitionContext;
+            String parentPartitionId = parentInstanceContext.getPartitionId();
+
             // Create GroupInstance for partition instance and add to required contexts for minimum instance count
-            for(int i=0; i<groupLevelNetworkPartitionContext.getMinInstanceCount(); i++) {
-	            
-            	groupInstanceId = createGroupInstance(group, parentInstanceContext, partitionId, groupLevelNetworkPartitionContext, deploymentPolicyName, true);
-            	instanceIdstoStart.add(groupInstanceId);
+            int groupMin = groupLevelNetworkPartitionContext.getMinInstanceCount();
+
+            //Have to check whether group has generated its own instances
+            List<Instance> existingGroupInstances = group.getInstanceContextsWithParentId(parentInstanceId);
+            for(Instance instance : existingGroupInstances) {
+                initialStartup = false;
+                partitionContext = groupLevelNetworkPartitionContext.
+                        getPartitionContextById(parentPartitionId);
+                groupInstanceId = createGroupInstanceAndAddToMonitor(group, parentInstanceContext,
+                        partitionContext,
+                        groupLevelNetworkPartitionContext,
+                        null);
+                instanceIdsToStart.add(groupInstanceId);
             }
+
+            /**
+             * If the group instances have been partially created or not created,
+             * then create everything
+             */
+            if(existingGroupInstances.size() <= groupMin) {
+                for (int i = 0; i < groupMin - existingGroupInstances.size(); i++) {
+                    // Get partitionContext to create instance in
+                    if (parentPartitionId == null) {
+                        AutoscaleAlgorithm algorithm = this.getAutoscaleAlgorithm(
+                                        groupLevelNetworkPartitionContext.getPartitionAlgorithm());
+                        partitionContext = algorithm.getNextScaleUpPartitionContext(
+                                (PartitionContext[]) groupLevelNetworkPartitionContext.
+                                        getPartitionCtxts().toArray());
+                    } else {
+                        partitionContext = groupLevelNetworkPartitionContext.
+                                getPartitionContextById(parentPartitionId);
+                    }
+                    groupInstanceId = createGroupInstanceAndAddToMonitor(group, parentInstanceContext,
+                            partitionContext,
+                            groupLevelNetworkPartitionContext,
+                            null);
+                    instanceIdsToStart.add(groupInstanceId);
+                }
+            }
+
         }
-        startDependency(group, instanceIdstoStart);
+        startDependency(group, instanceIdsToStart);
+        return initialStartup;
     }
-    
+
+
+
     /**
      * This will start the group instance based on the given parent instanceId
      * A new monitor is not created in this case
@@ -497,34 +513,45 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
      */
     public void createInstanceAndStartDependencyOnScaleup(Group group, String parentInstanceId)
             throws MonitorNotFoundException {
-    	// Get parent instance context
+        // Get parent instance context
         Instance parentInstanceContext = getParentInstanceContext(parentInstanceId);
-        
-        // Get existing or create new GroupLevelNetwokPartitionContext
-        GroupLevelNetworkPartitionContext groupLevelNetworkPartitionContext = getGroupLevelNetworkPartitionContext(parentInstanceContext);
-        
-        // Determine partitionContext
-        String deploymentPolicyName = group.getDeploymentPolicy();
-        String partitionId = null;
-        if(deploymentPolicyName != null) {
-        	partitionId = FindAndAddPartitionContext(parentInstanceContext, group, false);
-        }
-        else {
-        	GroupInstance instance = (GroupInstance) this.parent.getInstance(parentInstanceId);
-        	if (instance != null) {
-        		partitionId = instance.getPartitionId();
-        	} 
+
+        // Get existing or create new GroupLevelNetworkPartitionContext
+        GroupLevelNetworkPartitionContext groupLevelNetworkPartitionContext =
+                getGroupLevelNetworkPartitionContext(group.getUniqueIdentifier(),
+                        this.appId, parentInstanceContext);
+        //adding the partitionContext to the network partition context
+        addPartitionContext(parentInstanceContext, groupLevelNetworkPartitionContext);
+
+        String groupInstanceId;
+        PartitionContext partitionContext;
+        String parentPartitionId = parentInstanceContext.getPartitionId();
+        int groupMax = groupLevelNetworkPartitionContext.getMaxInstanceCount();
+        if(group.getInstanceContextCount() < groupMax) {
+            // Get partitionContext to create instance in
+            if (parentPartitionId == null) {
+                AutoscaleAlgorithm algorithm = this.getAutoscaleAlgorithm(
+                        groupLevelNetworkPartitionContext.getPartitionAlgorithm());
+                partitionContext = algorithm.getNextScaleUpPartitionContext(
+                        (PartitionContext[]) groupLevelNetworkPartitionContext.
+                                getPartitionCtxts().toArray());
+            } else {
+                partitionContext = groupLevelNetworkPartitionContext.
+                        getPartitionContextById(parentPartitionId);
+            }
+            groupInstanceId = createGroupInstanceAndAddToMonitor(group, parentInstanceContext,
+                    partitionContext,
+                    groupLevelNetworkPartitionContext,
+                    null);
+            startDependency(group, groupInstanceId);
+        } else {
+            log.warn("[Group] " + group.getUniqueIdentifier() + " has reached the maximum limit as " +
+                    "[max] " + groupMax + ". Hence trying to notify the parent.");
         }
 
-        String groupInstanceId = createGroupInstance(group, parentInstanceContext, partitionId, groupLevelNetworkPartitionContext, deploymentPolicyName, false);
-        startDependency(group, groupInstanceId);
-    }
-    
-    public void createInstanceAndStartDependencyOnRestart(Group group, List<String> parentInstanceIds) {
-    	// TODO: Need to add functionality when restart happens
-    	// Should only do required work from Monitor side and not from Topology since that is already existent
     }
-    
+
+
     /**
      * This will create the group instance in the applications Topology
      *
@@ -535,7 +562,7 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
      * @return
      */
     private GroupInstance createGroupInstance(Group group, String parentInstanceId, String partitionId,
-                                       String networkPartitionId) {
+                                              String networkPartitionId) {
         String instanceId = parentInstanceId;
         int minGroupInstances = group.getGroupMinInstances();
         int maxGroupInstances = group.getGroupMaxInstances();
@@ -567,42 +594,5 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
         this.isDestroyed = isDestroyed;
     }
 
-    public List<GroupLevelPartitionContext> getPartitionCtxts() {
-
-        return partitionContexts;
-    }
-
-    public GroupLevelPartitionContext getPartitionCtxt(String partitionId) {
-        
-    	for(GroupLevelPartitionContext partitionContext : partitionContexts){
-            if(partitionContext.getPartitionId().equals(partitionId)){
-                return partitionContext;
-            }
-        }
-        return null;
-    }
-
-    public void addPartitionContext(GroupLevelPartitionContext partitionContext) {
-    	partitionContexts.add(partitionContext);
-    }
-
-    public int getNonTerminatedMemberCountOfPartition(String partitionId) {
 
-        for(GroupLevelPartitionContext partitionContext : partitionContexts){
-            if(partitionContext.getPartitionId().equals(partitionId)){
-                return partitionContext.getNonTerminatedInstanceCount();
-            }
-        }
-        return 0;
-    }
-
-    public int getActiveMemberCount(String currentPartitionId) {
-
-        for(GroupLevelPartitionContext partitionContext : partitionContexts){
-            if(partitionContext.getPartitionId().equals(currentPartitionId)){
-                return partitionContext.getActiveInstanceCount();
-            }
-        }
-        return 0;
-    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/3bd20e5e/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java
index 136cb9f..a0710ac 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java
@@ -90,7 +90,7 @@ public abstract class ParentComponentMonitor extends Monitor {
     public void startDependency(ParentComponent component, List<String> instanceIds) {
         //start the first dependency
         List<ApplicationChildContext> applicationContexts = this.startupDependencyTree.
-                getStarAbleDependencies();
+                getStarAbleDependencies(); //TODO t
         startDependency(applicationContexts, instanceIds);
 
     }
@@ -280,17 +280,17 @@ public abstract class ParentComponentMonitor extends Monitor {
     }
 
     /**
-     * @param eventId
+     * @param childId
      */
-    protected void onChildInactiveEvent(String eventId, String instanceId) {
+    protected void onChildInactiveEvent(String childId, String instanceId) {
         List<ApplicationChildContext> terminationList;
         Monitor monitor;
-        terminationList = this.startupDependencyTree.getTerminationDependencies(eventId);
+        terminationList = this.startupDependencyTree.getTerminationDependencies(childId);
         //Need to notify the parent about the status  change from Active-->InActive
-        if (this.parent != null) {
+        // TODO to make app also inaction if (this.parent != null) {
             ServiceReferenceHolder.getInstance().getGroupStatusProcessorChain().
                     process(this.id, this.appId, instanceId);
-        }
+        //}
         //TODO checking whether terminating them in reverse order,
         // TODO if so can handle it in the parent event.
 
@@ -302,15 +302,15 @@ public abstract class ParentComponentMonitor extends Monitor {
             //handling the killall scenario
             if (this.parent != null) {
                 //send terminating to the parent. So that it will push terminating to its children
-                ApplicationBuilder.handleGroupTerminatingEvent(this.appId, eventId, instanceId);
+                ApplicationBuilder.handleGroupTerminatingEvent(this.appId, childId, instanceId);
             } else {
                 //if it is an application, send terminating event individually for children
-                sendTerminatingEventOnNotification(terminationList, eventId, true, instanceId);
+                sendTerminatingEventOnNotification(terminationList, childId, true, instanceId);
             }
-            log.info("The group" + eventId + " has been marked as terminating " +
+            log.info("The group" + childId + " has been marked as terminating " +
                     "due to all the children are to be terminated");
         } else {
-            sendTerminatingEventOnNotification(terminationList, eventId, false, instanceId);
+            sendTerminatingEventOnNotification(terminationList, childId, false, instanceId);
         }
     }
 
@@ -605,6 +605,7 @@ public abstract class ParentComponentMonitor extends Monitor {
             int retries = 5;
             boolean success;
             do {
+                //TODO remove thread.sleep, exectutor service
                 try {
                     Thread.sleep(5000);
                 } catch (InterruptedException e1) {

http://git-wip-us.apache.org/repos/asf/stratos/blob/3bd20e5e/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/deployment/DeploymentPolicy.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/deployment/DeploymentPolicy.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/deployment/DeploymentPolicy.java
index fb63c02..e2a6819 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/deployment/DeploymentPolicy.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/deployment/DeploymentPolicy.java
@@ -40,7 +40,6 @@ public class DeploymentPolicy implements Serializable{
     private String description;
     private boolean isPublic;
     private ApplicationLevelNetworkPartition[] applicationLevelNetworkPartitions;
-    private ChildPolicyHolder childPolicyHolder;
     private ChildPolicy[] childPolicies;
     private int tenantId;
 
@@ -193,25 +192,12 @@ public class DeploymentPolicy implements Serializable{
         		+" [partitions] " + Arrays.toString(this.getAllPartitions());
     }
 
-    public ChildLevelNetworkPartition getChildLevelNetworkPartition(String networkPartitionId) {
-
-        childPolicyHolder.getChildLevelNetworkPartitionById(networkPartitionId);
-        return null;
-    }
 
     public ChildLevelNetworkPartition[] getChildLevelNetworkPartitions() {
         //TODO create a map of child level network partition context and return correct one
         return new ChildLevelNetworkPartition[0];
     }
 
-    public ChildPolicyHolder getChildPolicyHolder() {
-        return childPolicyHolder;
-    }
-
-    public void setChildPolicyHolder(ChildPolicyHolder childPolicyHolder) {
-        this.childPolicyHolder = childPolicyHolder;
-    }
-
     public ChildPolicy[] getChildPolicies() {
         return childPolicies;
     }

http://git-wip-us.apache.org/repos/asf/stratos/blob/3bd20e5e/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusActiveProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusActiveProcessor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusActiveProcessor.java
index c007a46..5a47401 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusActiveProcessor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusActiveProcessor.java
@@ -82,6 +82,7 @@ public class ClusterStatusActiveProcessor extends ClusterStatusProcessor {
                 log.info("Publishing Cluster activated event for [application]: "
                         + monitor.getAppId() + " [cluster]: " + clusterId);
             }
+            //TODO service call
             ClusterStatusEventPublisher.sendClusterActivatedEvent(monitor.getAppId(),
                     monitor.getServiceId(), monitor.getClusterId(), instanceId);
         }

http://git-wip-us.apache.org/repos/asf/stratos/blob/3bd20e5e/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusInActiveProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusInActiveProcessor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusInActiveProcessor.java
index 91305bf..c3b1d05 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusInActiveProcessor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusInActiveProcessor.java
@@ -79,14 +79,14 @@ public class ClusterStatusInActiveProcessor extends ClusterStatusProcessor {
             //send cluster In-Active event to cluster status topic
             ClusterStatusEventPublisher.sendClusterInActivateEvent(monitor.getAppId(),
                     monitor.getServiceId(), clusterId, instanceId);
-        } else {
+        } /*else {
             if (log.isInfoEnabled()) {
                 log.info("Publishing Cluster active event for [application]: "
                         + monitor.getAppId() + " [cluster]: " + clusterId);
             }
-            ClusterStatusEventPublisher.sendClusterActivatedEvent(monitor.getAppId(),
-                                                        monitor.getServiceId(), clusterId, instanceId);
-        }
+            //ClusterStatusEventPublisher.sendClusterActivatedEvent(monitor.getAppId(),
+              //                                          monitor.getServiceId(), clusterId, instanceId);
+        }*/
         return clusterInActive;
     }
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/3bd20e5e/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusInActiveProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusInActiveProcessor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusInActiveProcessor.java
index 90b608c..7911727 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusInActiveProcessor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusInActiveProcessor.java
@@ -160,6 +160,7 @@ public class GroupStatusInActiveProcessor extends GroupStatusProcessor {
             } else {
                 groupStat = false;
             }
+            //TODO get by parent
         }
         return groupStat;
     }

http://git-wip-us.apache.org/repos/asf/stratos/blob/3bd20e5e/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/composite/application/beans/GroupDefinition.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/composite/application/beans/GroupDefinition.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/composite/application/beans/GroupDefinition.java
index 0d77628..109370d 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/composite/application/beans/GroupDefinition.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/composite/application/beans/GroupDefinition.java
@@ -37,7 +37,7 @@ public class GroupDefinition implements Serializable {
     private int groupMaxInstances;
 
     public boolean isGroupScalingEnabled;
-    
+
     private List<CartridgeDefinition> cartridges;
 
     private List<GroupDefinition> groups;

http://git-wip-us.apache.org/repos/asf/stratos/blob/3bd20e5e/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/instance/ClusterInstance.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/instance/ClusterInstance.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/instance/ClusterInstance.java
index 38d1108..5dd9d19 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/instance/ClusterInstance.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/instance/ClusterInstance.java
@@ -26,8 +26,6 @@ import org.apache.stratos.messaging.domain.topology.lifecycle.LifeCycleStateMana
 import java.util.Stack;
 
 public class ClusterInstance extends Instance<ClusterStatus> implements LifeCycleStateTransitionBehavior<ClusterStatus> {
-    //partition id
-    private String partitionId;
 
     public ClusterInstance(String alias, String clusterId, String instanceId) {
         super(alias, instanceId);
@@ -55,15 +53,6 @@ public class ClusterInstance extends Instance<ClusterStatus> implements LifeCycl
         return this.lifeCycleStateManager.changeState(newState);
     }
 
-    public String getPartitionId() {
-        return partitionId;
-    }
-
-    public void setPartitionId(String partitionId) {
-        this.partitionId = partitionId;
-    }
-
-
     /**
      * Get the current state
      *

http://git-wip-us.apache.org/repos/asf/stratos/blob/3bd20e5e/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/instance/GroupInstance.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/instance/GroupInstance.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/instance/GroupInstance.java
index dd28fc3..88c34e2 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/instance/GroupInstance.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/instance/GroupInstance.java
@@ -26,8 +26,6 @@ import org.apache.stratos.messaging.domain.topology.lifecycle.LifeCycleStateMana
 import java.util.Stack;
 
 public class GroupInstance extends Instance<GroupStatus> implements LifeCycleStateTransitionBehavior<GroupStatus> {
-    //partition id
-    private String partitionId;
 
     public GroupInstance(String alias, String instanceId) {
         super(alias, instanceId);
@@ -55,11 +53,5 @@ public class GroupInstance extends Instance<GroupStatus> implements LifeCycleSta
         return this.lifeCycleStateManager.changeState(newState);
     }
 
-    public String getPartitionId() {
-        return partitionId;
-    }
 
-    public void setPartitionId(String partitionId) {
-        this.partitionId = partitionId;
-    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/3bd20e5e/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/instance/Instance.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/instance/Instance.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/instance/Instance.java
index a994d2e..ba6f089 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/instance/Instance.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/instance/Instance.java
@@ -39,6 +39,9 @@ public abstract class Instance<T extends LifeCycleState> implements Serializable
     private String parentId;
     //Network partition id
     private String networkPartitionId;
+    //partition id
+    protected String partitionId;
+
 
     public Instance(String alias, String instanceId) {
         this.alias = alias;
@@ -96,5 +99,13 @@ public abstract class Instance<T extends LifeCycleState> implements Serializable
         this.networkPartitionId = networkPartitionId;
     }
 
+    public String getPartitionId() {
+        return partitionId;
+    }
+
+    public void setPartitionId(String partitionId) {
+        this.partitionId = partitionId;
+    }
+
 }
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/3bd20e5e/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationsMessageProcessorChain.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationsMessageProcessorChain.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationsMessageProcessorChain.java
index b88a3ec..98b34ad 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationsMessageProcessorChain.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationsMessageProcessorChain.java
@@ -36,6 +36,7 @@ public class ApplicationsMessageProcessorChain extends MessageProcessorChain {
     private GroupInstanceInActivateProcessor groupInActivateMessageProcessor;
     private GroupInstanceTerminatedProcessor groupTerminatedProcessor;
     private GroupInstanceTerminatingProcessor groupTerminatingProcessor;
+    private ApplicationInstanceCreatedMessageProcessor applicationInstanceCreatedMessageProcessor;
     private ApplicationInstanceActivatedMessageProcessor applicationActivatedMessageProcessor;
     private ApplicationCreatedMessageProcessor applicationCreatedMessageProcessor;
     private ApplicationInstanceInactivatedMessageProcessor applicationInactivatedMessageProcessor;
@@ -61,6 +62,9 @@ public class ApplicationsMessageProcessorChain extends MessageProcessorChain {
         groupTerminatingProcessor = new GroupInstanceTerminatingProcessor();
         add(groupTerminatingProcessor);
 
+        applicationInstanceCreatedMessageProcessor = new ApplicationInstanceCreatedMessageProcessor();
+        add(applicationInstanceCreatedMessageProcessor);
+
         applicationActivatedMessageProcessor = new ApplicationInstanceActivatedMessageProcessor();
         add(applicationActivatedMessageProcessor);
 
@@ -96,6 +100,8 @@ public class ApplicationsMessageProcessorChain extends MessageProcessorChain {
             groupTerminatingProcessor.addEventListener(eventListener);
         } else if (eventListener instanceof GroupInstanceTerminatedEventListener) {
             groupTerminatedProcessor.addEventListener(eventListener);
+        } else if (eventListener instanceof ApplicationInstanceCreatedEventListener) {
+            applicationInstanceCreatedMessageProcessor.addEventListener(eventListener);
         } else if (eventListener instanceof ApplicationCreatedEventListener) {
             applicationCreatedMessageProcessor.addEventListener(eventListener);
         } else if (eventListener instanceof ApplicationInstanceActivatedEventListener) {

http://git-wip-us.apache.org/repos/asf/stratos/blob/3bd20e5e/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java
index fcc128d..fc31362 100644
--- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java
+++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java
@@ -330,7 +330,7 @@ public class StratosApiV41 extends AbstractApi {
     @AuthorizationAction("/permission/admin/manage/add/deploymentPolicy")
     public Response deployDeploymentPolicyDefinition(DeploymentPolicy deploymentPolicy)
             throws RestAPIException {
-
+        //TODO change the name to deployApplication
         String policyId = StratosApiV41Utils.deployDeploymentPolicy(deploymentPolicy);
         URI url = uriInfo.getAbsolutePathBuilder().path(policyId).build();
         return Response.created(url).build();


[3/5] stratos git commit: adding instance prefix to events, , processor and listener

Posted by re...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterInstanceActivatedEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterInstanceActivatedEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterInstanceActivatedEvent.java
new file mode 100644
index 0000000..34b304f
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterInstanceActivatedEvent.java
@@ -0,0 +1,63 @@
+/*
+ * 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.messaging.event.topology;
+
+import org.apache.stratos.messaging.domain.topology.ClusterStatus;
+import org.apache.stratos.messaging.event.Event;
+
+/**
+ * Cluster activated event will be sent by Autoscaler
+ */
+public class ClusterInstanceActivatedEvent extends Event {
+
+    private final String serviceName;
+    private final String clusterId;
+    private String appId;
+    private String instanceId;
+
+    public ClusterInstanceActivatedEvent(String appId, String serviceName, String clusterId, String instanceId) {
+        this.serviceName = serviceName;
+        this.clusterId = clusterId;
+        this.appId = appId;
+        this.instanceId = instanceId;
+    }
+
+    public String getServiceName() {
+        return serviceName;
+    }
+
+    @Override
+    public String toString() {
+        return "ClusterActivatedEvent [serviceName=" + serviceName + ", clusterStatus=" +
+                "]";
+    }
+
+    public String getClusterId() {
+        return clusterId;
+    }
+
+    public String getAppId() {
+        return appId;
+    }
+
+    public String getInstanceId() {
+        return instanceId;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterInstanceInactivateEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterInstanceInactivateEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterInstanceInactivateEvent.java
new file mode 100644
index 0000000..e84be18
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterInstanceInactivateEvent.java
@@ -0,0 +1,63 @@
+/*
+ * 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.messaging.event.topology;
+
+import org.apache.stratos.messaging.event.Event;
+
+/**
+ * Cluster activated event will be sent by Autoscaler
+ */
+public class ClusterInstanceInactivateEvent extends Event {
+
+    private final String serviceName;
+    private final String clusterId;
+    private String appId;
+    private String instanceId;
+
+
+    public ClusterInstanceInactivateEvent(String appId, String serviceName, String clusterId, String instanceId) {
+        this.serviceName = serviceName;
+        this.clusterId = clusterId;
+        this.appId = appId;
+        this.instanceId = instanceId;
+
+    }
+
+    public String getServiceName() {
+        return serviceName;
+    }
+
+    @Override
+    public String toString() {
+        return "ClusterActivatedEvent [serviceName=" + serviceName + ", clusterStatus=" +
+                "]";
+    }
+
+    public String getClusterId() {
+        return clusterId;
+    }
+
+    public String getAppId() {
+        return appId;
+    }
+
+    public String getInstanceId() {
+        return instanceId;
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterInstanceTerminatedEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterInstanceTerminatedEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterInstanceTerminatedEvent.java
new file mode 100644
index 0000000..8c51234
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterInstanceTerminatedEvent.java
@@ -0,0 +1,63 @@
+/*
+ * 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.messaging.event.topology;
+
+import org.apache.stratos.messaging.event.Event;
+
+/**
+ * Cluster activated event will be sent by Autoscaler
+ */
+public class ClusterInstanceTerminatedEvent extends Event {
+
+    private final String serviceName;
+    private final String clusterId;
+    private String appId;
+    private String instanceId;
+
+
+    public ClusterInstanceTerminatedEvent(String appId, String serviceName, String clusterId, String instanceId) {
+        this.serviceName = serviceName;
+        this.clusterId = clusterId;
+        this.appId = appId;
+        this.instanceId = instanceId;
+    }
+
+    public String getServiceName() {
+        return serviceName;
+    }
+
+    @Override
+    public String toString() {
+        return "ClusterActivatedEvent [serviceName=" + serviceName + ", clusterStatus=" +
+                "]";
+    }
+
+    public String getClusterId() {
+        return clusterId;
+    }
+
+    public String getAppId() {
+        return appId;
+    }
+
+    public String getInstanceId() {
+        return instanceId;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterInstanceTerminatingEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterInstanceTerminatingEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterInstanceTerminatingEvent.java
new file mode 100644
index 0000000..c1458be
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterInstanceTerminatingEvent.java
@@ -0,0 +1,61 @@
+/*
+ * 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.messaging.event.topology;
+
+import org.apache.stratos.messaging.event.Event;
+
+/**
+ * Cluster activated event will be sent by Autoscaler
+ */
+public class ClusterInstanceTerminatingEvent extends Event {
+
+    private final String serviceName;
+    private final String clusterId;
+    private String appId;
+    private String instanceId;
+
+    public ClusterInstanceTerminatingEvent(String appId, String serviceName, String clusterId, String instanceId) {
+        this.serviceName = serviceName;
+        this.clusterId = clusterId;
+        this.appId = appId;
+        this.instanceId = instanceId;
+    }
+
+    public String getServiceName() {
+        return serviceName;
+    }
+
+    @Override
+    public String toString() {
+        return "ClusterActivatedEvent [serviceName=" + serviceName + ", clusterStatus=" +
+                "]";
+    }
+
+    public String getClusterId() {
+        return clusterId;
+    }
+
+    public String getAppId() {
+        return appId;
+    }
+
+    public String getInstanceId() {
+        return instanceId;
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterTerminatedEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterTerminatedEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterTerminatedEvent.java
deleted file mode 100644
index 1013292..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterTerminatedEvent.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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.messaging.event.topology;
-
-import org.apache.stratos.messaging.event.Event;
-
-/**
- * Cluster activated event will be sent by Autoscaler
- */
-public class ClusterTerminatedEvent extends Event {
-
-    private final String serviceName;
-    private final String clusterId;
-    private String appId;
-    private String instanceId;
-
-
-    public ClusterTerminatedEvent(String appId, String serviceName, String clusterId, String instanceId) {
-        this.serviceName = serviceName;
-        this.clusterId = clusterId;
-        this.appId = appId;
-        this.instanceId = instanceId;
-    }
-
-    public String getServiceName() {
-        return serviceName;
-    }
-
-    @Override
-    public String toString() {
-        return "ClusterActivatedEvent [serviceName=" + serviceName + ", clusterStatus=" +
-                "]";
-    }
-
-    public String getClusterId() {
-        return clusterId;
-    }
-
-    public String getAppId() {
-        return appId;
-    }
-
-    public String getInstanceId() {
-        return instanceId;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterTerminatingEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterTerminatingEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterTerminatingEvent.java
deleted file mode 100644
index 86b15e4..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterTerminatingEvent.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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.messaging.event.topology;
-
-import org.apache.stratos.messaging.event.Event;
-
-/**
- * Cluster activated event will be sent by Autoscaler
- */
-public class ClusterTerminatingEvent extends Event {
-
-    private final String serviceName;
-    private final String clusterId;
-    private String appId;
-    private String instanceId;
-
-    public ClusterTerminatingEvent(String appId, String serviceName, String clusterId, String instanceId) {
-        this.serviceName = serviceName;
-        this.clusterId = clusterId;
-        this.appId = appId;
-        this.instanceId = instanceId;
-    }
-
-    public String getServiceName() {
-        return serviceName;
-    }
-
-    @Override
-    public String toString() {
-        return "ClusterActivatedEvent [serviceName=" + serviceName + ", clusterStatus=" +
-                "]";
-    }
-
-    public String getClusterId() {
-        return clusterId;
-    }
-
-    public String getAppId() {
-        return appId;
-    }
-
-    public String getInstanceId() {
-        return instanceId;
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationActivatedEventListener.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationActivatedEventListener.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationActivatedEventListener.java
deleted file mode 100644
index e244ae9..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationActivatedEventListener.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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.messaging.listener.applications;
-
-import org.apache.stratos.messaging.listener.EventListener;
-
-/**
- * This listener will get triggered upon the application activated event.
- */
-public abstract class ApplicationActivatedEventListener extends EventListener {
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationInactivatedEventListener.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationInactivatedEventListener.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationInactivatedEventListener.java
deleted file mode 100644
index d0593fb..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationInactivatedEventListener.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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.messaging.listener.applications;
-
-import org.apache.stratos.messaging.listener.EventListener;
-
-/**
- * This listener will get triggered upon the application inactivated event.
- */
-public abstract class ApplicationInactivatedEventListener extends EventListener {
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationInstanceActivatedEventListener.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationInstanceActivatedEventListener.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationInstanceActivatedEventListener.java
new file mode 100644
index 0000000..086efbc
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationInstanceActivatedEventListener.java
@@ -0,0 +1,27 @@
+/*
+ * 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.messaging.listener.applications;
+
+import org.apache.stratos.messaging.listener.EventListener;
+
+/**
+ * This listener will get triggered upon the application activated event.
+ */
+public abstract class ApplicationInstanceActivatedEventListener extends EventListener {
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationInstanceInactivatedEventListener.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationInstanceInactivatedEventListener.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationInstanceInactivatedEventListener.java
new file mode 100644
index 0000000..2fbfbf9
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationInstanceInactivatedEventListener.java
@@ -0,0 +1,27 @@
+/*
+ * 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.messaging.listener.applications;
+
+import org.apache.stratos.messaging.listener.EventListener;
+
+/**
+ * This listener will get triggered upon the application inactivated event.
+ */
+public abstract class ApplicationInstanceInactivatedEventListener extends EventListener {
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationInstanceTerminatedEventListener.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationInstanceTerminatedEventListener.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationInstanceTerminatedEventListener.java
new file mode 100644
index 0000000..e7c31f8
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationInstanceTerminatedEventListener.java
@@ -0,0 +1,27 @@
+/*
+ * 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.messaging.listener.applications;
+
+import org.apache.stratos.messaging.listener.EventListener;
+
+/**
+ * This listener will get triggered upon the application terminated event.
+ */
+public abstract class ApplicationInstanceTerminatedEventListener extends EventListener {
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationInstanceTerminatingEventListener.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationInstanceTerminatingEventListener.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationInstanceTerminatingEventListener.java
new file mode 100644
index 0000000..ef2ff49
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationInstanceTerminatingEventListener.java
@@ -0,0 +1,27 @@
+/*
+ * 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.messaging.listener.applications;
+
+import org.apache.stratos.messaging.listener.EventListener;
+
+/**
+ * This listener will get triggered upon the application terminating event.
+ */
+public abstract class ApplicationInstanceTerminatingEventListener extends EventListener {
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationTerminatedEventListener.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationTerminatedEventListener.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationTerminatedEventListener.java
deleted file mode 100644
index 064465c..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationTerminatedEventListener.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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.messaging.listener.applications;
-
-import org.apache.stratos.messaging.listener.EventListener;
-
-/**
- * This listener will get triggered upon the application terminated event.
- */
-public abstract class ApplicationTerminatedEventListener extends EventListener {
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationTerminatingEventListener.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationTerminatingEventListener.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationTerminatingEventListener.java
deleted file mode 100644
index 3be2ad2..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/ApplicationTerminatingEventListener.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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.messaging.listener.applications;
-
-import org.apache.stratos.messaging.listener.EventListener;
-
-/**
- * This listener will get triggered upon the application terminating event.
- */
-public abstract class ApplicationTerminatingEventListener extends EventListener {
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupActivatedEventListener.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupActivatedEventListener.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupActivatedEventListener.java
deleted file mode 100644
index 51455ae..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupActivatedEventListener.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * 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.messaging.listener.applications;
-
-import org.apache.stratos.messaging.listener.EventListener;
-
-public abstract class GroupActivatedEventListener extends EventListener {
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupInactivateEventListener.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupInactivateEventListener.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupInactivateEventListener.java
deleted file mode 100644
index aeb58da..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupInactivateEventListener.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * 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.messaging.listener.applications;
-
-import org.apache.stratos.messaging.listener.EventListener;
-
-public abstract class GroupInactivateEventListener extends EventListener {
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupInstanceActivatedEventListener.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupInstanceActivatedEventListener.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupInstanceActivatedEventListener.java
new file mode 100644
index 0000000..3c102cb
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupInstanceActivatedEventListener.java
@@ -0,0 +1,24 @@
+/*
+ * 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.messaging.listener.applications;
+
+import org.apache.stratos.messaging.listener.EventListener;
+
+public abstract class GroupInstanceActivatedEventListener extends EventListener {
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupInstanceCreatedEventListener.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupInstanceCreatedEventListener.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupInstanceCreatedEventListener.java
new file mode 100644
index 0000000..22de3c1
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupInstanceCreatedEventListener.java
@@ -0,0 +1,24 @@
+/*
+ * 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.messaging.listener.applications;
+
+import org.apache.stratos.messaging.listener.EventListener;
+
+public abstract class GroupInstanceCreatedEventListener extends EventListener {
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupInstanceInactivateEventListener.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupInstanceInactivateEventListener.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupInstanceInactivateEventListener.java
new file mode 100644
index 0000000..e402bd1
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupInstanceInactivateEventListener.java
@@ -0,0 +1,24 @@
+/*
+ * 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.messaging.listener.applications;
+
+import org.apache.stratos.messaging.listener.EventListener;
+
+public abstract class GroupInstanceInactivateEventListener extends EventListener {
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupInstanceTerminatedEventListener.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupInstanceTerminatedEventListener.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupInstanceTerminatedEventListener.java
new file mode 100644
index 0000000..7d396c0
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupInstanceTerminatedEventListener.java
@@ -0,0 +1,24 @@
+/*
+ * 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.messaging.listener.applications;
+
+import org.apache.stratos.messaging.listener.EventListener;
+
+public abstract class GroupInstanceTerminatedEventListener extends EventListener {
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupInstanceTerminatingEventListener.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupInstanceTerminatingEventListener.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupInstanceTerminatingEventListener.java
new file mode 100644
index 0000000..b85cbc0
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupInstanceTerminatingEventListener.java
@@ -0,0 +1,24 @@
+/*
+ * 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.messaging.listener.applications;
+
+import org.apache.stratos.messaging.listener.EventListener;
+
+public abstract class GroupInstanceTerminatingEventListener extends EventListener {
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupResetEventListener.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupResetEventListener.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupResetEventListener.java
deleted file mode 100644
index b4b67ed..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupResetEventListener.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * 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.messaging.listener.applications;
-
-import org.apache.stratos.messaging.listener.EventListener;
-
-public abstract class GroupResetEventListener extends EventListener {
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupTerminatedEventListener.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupTerminatedEventListener.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupTerminatedEventListener.java
deleted file mode 100644
index ed4bb3a..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupTerminatedEventListener.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * 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.messaging.listener.applications;
-
-import org.apache.stratos.messaging.listener.EventListener;
-
-public abstract class GroupTerminatedEventListener extends EventListener {
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupTerminatingEventListener.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupTerminatingEventListener.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupTerminatingEventListener.java
deleted file mode 100644
index 5168f77..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/applications/GroupTerminatingEventListener.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * 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.messaging.listener.applications;
-
-import org.apache.stratos.messaging.listener.EventListener;
-
-public abstract class GroupTerminatingEventListener extends EventListener {
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterActivatedEventListener.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterActivatedEventListener.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterActivatedEventListener.java
deleted file mode 100644
index 00efcfd..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterActivatedEventListener.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * 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.messaging.listener.topology;
-
-import org.apache.stratos.messaging.listener.EventListener;
-
-public abstract class ClusterActivatedEventListener extends EventListener {
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterInActivateEventListener.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterInActivateEventListener.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterInActivateEventListener.java
deleted file mode 100644
index 551f1b8..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterInActivateEventListener.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * 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.messaging.listener.topology;
-
-import org.apache.stratos.messaging.listener.EventListener;
-
-public abstract class ClusterInActivateEventListener extends EventListener {
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterInstanceActivatedEventListener.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterInstanceActivatedEventListener.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterInstanceActivatedEventListener.java
new file mode 100644
index 0000000..c35c759
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterInstanceActivatedEventListener.java
@@ -0,0 +1,24 @@
+/*
+ * 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.messaging.listener.topology;
+
+import org.apache.stratos.messaging.listener.EventListener;
+
+public abstract class ClusterInstanceActivatedEventListener extends EventListener {
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterInstanceInActivateEventListener.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterInstanceInActivateEventListener.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterInstanceInActivateEventListener.java
new file mode 100644
index 0000000..888892d
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterInstanceInActivateEventListener.java
@@ -0,0 +1,24 @@
+/*
+ * 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.messaging.listener.topology;
+
+import org.apache.stratos.messaging.listener.EventListener;
+
+public abstract class ClusterInstanceInActivateEventListener extends EventListener {
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterInstanceTerminatedEventListener.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterInstanceTerminatedEventListener.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterInstanceTerminatedEventListener.java
new file mode 100644
index 0000000..17c1b77
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterInstanceTerminatedEventListener.java
@@ -0,0 +1,24 @@
+/*
+ * 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.messaging.listener.topology;
+
+import org.apache.stratos.messaging.listener.EventListener;
+
+public abstract class ClusterInstanceTerminatedEventListener extends EventListener {
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterInstanceTerminatingEventListener.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterInstanceTerminatingEventListener.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterInstanceTerminatingEventListener.java
new file mode 100644
index 0000000..30ae39b
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterInstanceTerminatingEventListener.java
@@ -0,0 +1,24 @@
+/*
+ * 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.messaging.listener.topology;
+
+import org.apache.stratos.messaging.listener.EventListener;
+
+public abstract class ClusterInstanceTerminatingEventListener extends EventListener {
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterTerminatedEventListener.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterTerminatedEventListener.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterTerminatedEventListener.java
deleted file mode 100644
index 33d050d..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterTerminatedEventListener.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * 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.messaging.listener.topology;
-
-import org.apache.stratos.messaging.listener.EventListener;
-
-public abstract class ClusterTerminatedEventListener extends EventListener {
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterTerminatingEventListener.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterTerminatingEventListener.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterTerminatingEventListener.java
deleted file mode 100644
index 5c08203..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ClusterTerminatingEventListener.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * 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.messaging.listener.topology;
-
-import org.apache.stratos.messaging.listener.EventListener;
-
-public abstract class ClusterTerminatingEventListener extends EventListener {
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationActivatedMessageProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationActivatedMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationActivatedMessageProcessor.java
deleted file mode 100644
index 401e206..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationActivatedMessageProcessor.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * 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.messaging.message.processor.applications;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.messaging.domain.applications.Application;
-import org.apache.stratos.messaging.domain.applications.ApplicationStatus;
-import org.apache.stratos.messaging.domain.applications.Applications;
-import org.apache.stratos.messaging.domain.instance.ApplicationInstance;
-import org.apache.stratos.messaging.event.applications.ApplicationActivatedEvent;
-import org.apache.stratos.messaging.message.processor.MessageProcessor;
-import org.apache.stratos.messaging.message.processor.applications.updater.ApplicationsUpdater;
-import org.apache.stratos.messaging.util.Util;
-
-/**
- * This processor responsible to process the application activation even and update the Topology.
- */
-public class ApplicationActivatedMessageProcessor extends MessageProcessor {
-    private static final Log log =
-            LogFactory.getLog(ApplicationActivatedMessageProcessor.class);
-
-
-    private MessageProcessor nextProcessor;
-
-    @Override
-    public void setNext(MessageProcessor nextProcessor) {
-        this.nextProcessor = nextProcessor;
-    }
-
-
-    @Override
-    public boolean process(String type, String message, Object object) {
-        Applications applications = (Applications) object;
-
-        if (ApplicationActivatedEvent.class.getName().equals(type)) {
-            // Return if applications has not been initialized
-            if (!applications.isInitialized())
-                return false;
-
-            // Parse complete message and build event
-            ApplicationActivatedEvent event = (ApplicationActivatedEvent) Util.
-                    jsonToObject(message, ApplicationActivatedEvent.class);
-
-            ApplicationsUpdater.acquireWriteLockForApplication(event.getAppId());
-
-            try {
-                return doProcess(event, applications);
-
-            } finally {
-                ApplicationsUpdater.releaseWriteLockForApplication(event.getAppId());
-            }
-
-        } else {
-            if (nextProcessor != null) {
-                // ask the next processor to take care of the message.
-                return nextProcessor.process(type, message, applications);
-            } else {
-                throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message));
-            }
-        }
-    }
-
-    private boolean doProcess(ApplicationActivatedEvent event, Applications applications) {
-
-        // Validate event against the existing applications
-        Application application = applications.getApplication(event.getAppId());
-        if (application == null) {
-            if (log.isWarnEnabled()) {
-                log.warn(String.format("Application does not exist: [service] %s",
-                        event.getAppId()));
-            }
-            return false;
-        } else {
-            // Apply changes to the applications
-            ApplicationInstance context = application.getInstanceContexts(event.getInstanceId());
-            if(context == null) {
-                if (log.isWarnEnabled()) {
-                    log.warn(String.format("Application Instance not exists in Group: [AppId] %s" +
-                                    "[instanceId] %s", event.getAppId(), event.getInstanceId()));
-                    return false;
-                }
-            }
-            ApplicationStatus status = ApplicationStatus.Active;
-            if (!context.isStateTransitionValid(status)) {
-                log.error("Invalid State transfer from [ " + context.getStatus() +
-                        " ] to [ " + status + " ]");
-            }
-            context.setStatus(status);
-
-        }
-
-        // Notify event listeners
-        notifyEventListeners(event);
-        return true;
-
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationInactivatedMessageProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationInactivatedMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationInactivatedMessageProcessor.java
deleted file mode 100644
index 5a3ef91..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationInactivatedMessageProcessor.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * 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.messaging.message.processor.applications;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.messaging.domain.applications.Application;
-import org.apache.stratos.messaging.domain.applications.ApplicationStatus;
-import org.apache.stratos.messaging.domain.applications.Applications;
-import org.apache.stratos.messaging.domain.instance.ApplicationInstance;
-import org.apache.stratos.messaging.event.applications.ApplicationInstanceInactivatedEvent;
-import org.apache.stratos.messaging.message.processor.MessageProcessor;
-import org.apache.stratos.messaging.message.processor.applications.updater.ApplicationsUpdater;
-import org.apache.stratos.messaging.util.Util;
-
-/**
- * This processor responsible to process the application Inactivation even and update the Topology.
- */
-public class ApplicationInactivatedMessageProcessor extends MessageProcessor {
-    private static final Log log =
-            LogFactory.getLog(ApplicationInactivatedMessageProcessor.class);
-
-
-    private MessageProcessor nextProcessor;
-
-    @Override
-    public void setNext(MessageProcessor nextProcessor) {
-        this.nextProcessor = nextProcessor;
-    }
-
-
-    @Override
-    public boolean process(String type, String message, Object object) {
-        Applications applications = (Applications) object;
-
-        if (ApplicationInstanceInactivatedEvent.class.getName().equals(type)) {
-            // Return if applications has not been initialized
-            if (!applications.isInitialized())
-                return false;
-
-            // Parse complete message and build event
-            ApplicationInstanceInactivatedEvent event = (ApplicationInstanceInactivatedEvent) Util.
-                    jsonToObject(message, ApplicationInstanceInactivatedEvent.class);
-
-            ApplicationsUpdater.acquireWriteLockForApplication(event.getAppId());
-
-            try {
-                return doProcess(event, applications);
-
-            } finally {
-                ApplicationsUpdater.releaseWriteLockForApplication(event.getAppId());
-            }
-
-        } else {
-            if (nextProcessor != null) {
-                // ask the next processor to take care of the message.
-                return nextProcessor.process(type, message, applications);
-            } else {
-                throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message));
-            }
-        }
-    }
-
-    private boolean doProcess(ApplicationInstanceInactivatedEvent event, Applications applications) {
-
-        // Validate event against the existing applications
-        Application application = applications.getApplication(event.getAppId());
-        if (application == null) {
-            if (log.isWarnEnabled()) {
-                log.warn(String.format("Application does not exist: [service] %s",
-                        event.getAppId()));
-            }
-            return false;
-        } else {
-            // Apply changes to the applications
-            ApplicationInstance context = application.getInstanceContexts(event.getInstanceId());
-            if(context == null) {
-                if (log.isWarnEnabled()) {
-                    log.warn(String.format("Application Instance not exists in Group: [AppId] %s" +
-                            "[instanceId] %s", event.getAppId(), event.getInstanceId()));
-                    return false;
-                }
-            }
-            ApplicationStatus status = ApplicationStatus.Inactive;
-            if (!context.isStateTransitionValid(status)) {
-                log.error("Invalid State transfer from [ " + context.getStatus() +
-                        " ] to [ " + status + " ]");
-            }
-            context.setStatus(status);
-
-        }
-
-        // Notify event listeners
-        notifyEventListeners(event);
-        return true;
-
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationInstanceActivatedMessageProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationInstanceActivatedMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationInstanceActivatedMessageProcessor.java
new file mode 100644
index 0000000..bd83e10
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationInstanceActivatedMessageProcessor.java
@@ -0,0 +1,114 @@
+/*
+ * 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.messaging.message.processor.applications;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.messaging.domain.applications.Application;
+import org.apache.stratos.messaging.domain.applications.ApplicationStatus;
+import org.apache.stratos.messaging.domain.applications.Applications;
+import org.apache.stratos.messaging.domain.instance.ApplicationInstance;
+import org.apache.stratos.messaging.event.applications.ApplicationInstanceActivatedEvent;
+import org.apache.stratos.messaging.message.processor.MessageProcessor;
+import org.apache.stratos.messaging.message.processor.applications.updater.ApplicationsUpdater;
+import org.apache.stratos.messaging.util.Util;
+
+/**
+ * This processor responsible to process the application activation even and update the Topology.
+ */
+public class ApplicationInstanceActivatedMessageProcessor extends MessageProcessor {
+    private static final Log log =
+            LogFactory.getLog(ApplicationInstanceActivatedMessageProcessor.class);
+
+
+    private MessageProcessor nextProcessor;
+
+    @Override
+    public void setNext(MessageProcessor nextProcessor) {
+        this.nextProcessor = nextProcessor;
+    }
+
+
+    @Override
+    public boolean process(String type, String message, Object object) {
+        Applications applications = (Applications) object;
+
+        if (ApplicationInstanceActivatedEvent.class.getName().equals(type)) {
+            // Return if applications has not been initialized
+            if (!applications.isInitialized())
+                return false;
+
+            // Parse complete message and build event
+            ApplicationInstanceActivatedEvent event = (ApplicationInstanceActivatedEvent) Util.
+                    jsonToObject(message, ApplicationInstanceActivatedEvent.class);
+
+            ApplicationsUpdater.acquireWriteLockForApplication(event.getAppId());
+
+            try {
+                return doProcess(event, applications);
+
+            } finally {
+                ApplicationsUpdater.releaseWriteLockForApplication(event.getAppId());
+            }
+
+        } else {
+            if (nextProcessor != null) {
+                // ask the next processor to take care of the message.
+                return nextProcessor.process(type, message, applications);
+            } else {
+                throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message));
+            }
+        }
+    }
+
+    private boolean doProcess(ApplicationInstanceActivatedEvent event, Applications applications) {
+
+        // Validate event against the existing applications
+        Application application = applications.getApplication(event.getAppId());
+        if (application == null) {
+            if (log.isWarnEnabled()) {
+                log.warn(String.format("Application does not exist: [service] %s",
+                        event.getAppId()));
+            }
+            return false;
+        } else {
+            // Apply changes to the applications
+            ApplicationInstance context = application.getInstanceContexts(event.getInstanceId());
+            if(context == null) {
+                if (log.isWarnEnabled()) {
+                    log.warn(String.format("Application Instance not exists in Group: [AppId] %s" +
+                                    "[instanceId] %s", event.getAppId(), event.getInstanceId()));
+                    return false;
+                }
+            }
+            ApplicationStatus status = ApplicationStatus.Active;
+            if (!context.isStateTransitionValid(status)) {
+                log.error("Invalid State transfer from [ " + context.getStatus() +
+                        " ] to [ " + status + " ]");
+            }
+            context.setStatus(status);
+
+        }
+
+        // Notify event listeners
+        notifyEventListeners(event);
+        return true;
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationInstanceInactivatedMessageProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationInstanceInactivatedMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationInstanceInactivatedMessageProcessor.java
new file mode 100644
index 0000000..e41905b
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationInstanceInactivatedMessageProcessor.java
@@ -0,0 +1,114 @@
+/*
+ * 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.messaging.message.processor.applications;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.messaging.domain.applications.Application;
+import org.apache.stratos.messaging.domain.applications.ApplicationStatus;
+import org.apache.stratos.messaging.domain.applications.Applications;
+import org.apache.stratos.messaging.domain.instance.ApplicationInstance;
+import org.apache.stratos.messaging.event.applications.ApplicationInstanceInactivatedEvent;
+import org.apache.stratos.messaging.message.processor.MessageProcessor;
+import org.apache.stratos.messaging.message.processor.applications.updater.ApplicationsUpdater;
+import org.apache.stratos.messaging.util.Util;
+
+/**
+ * This processor responsible to process the application Inactivation even and update the Topology.
+ */
+public class ApplicationInstanceInactivatedMessageProcessor extends MessageProcessor {
+    private static final Log log =
+            LogFactory.getLog(ApplicationInstanceInactivatedMessageProcessor.class);
+
+
+    private MessageProcessor nextProcessor;
+
+    @Override
+    public void setNext(MessageProcessor nextProcessor) {
+        this.nextProcessor = nextProcessor;
+    }
+
+
+    @Override
+    public boolean process(String type, String message, Object object) {
+        Applications applications = (Applications) object;
+
+        if (ApplicationInstanceInactivatedEvent.class.getName().equals(type)) {
+            // Return if applications has not been initialized
+            if (!applications.isInitialized())
+                return false;
+
+            // Parse complete message and build event
+            ApplicationInstanceInactivatedEvent event = (ApplicationInstanceInactivatedEvent) Util.
+                    jsonToObject(message, ApplicationInstanceInactivatedEvent.class);
+
+            ApplicationsUpdater.acquireWriteLockForApplication(event.getAppId());
+
+            try {
+                return doProcess(event, applications);
+
+            } finally {
+                ApplicationsUpdater.releaseWriteLockForApplication(event.getAppId());
+            }
+
+        } else {
+            if (nextProcessor != null) {
+                // ask the next processor to take care of the message.
+                return nextProcessor.process(type, message, applications);
+            } else {
+                throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message));
+            }
+        }
+    }
+
+    private boolean doProcess(ApplicationInstanceInactivatedEvent event, Applications applications) {
+
+        // Validate event against the existing applications
+        Application application = applications.getApplication(event.getAppId());
+        if (application == null) {
+            if (log.isWarnEnabled()) {
+                log.warn(String.format("Application does not exist: [service] %s",
+                        event.getAppId()));
+            }
+            return false;
+        } else {
+            // Apply changes to the applications
+            ApplicationInstance context = application.getInstanceContexts(event.getInstanceId());
+            if(context == null) {
+                if (log.isWarnEnabled()) {
+                    log.warn(String.format("Application Instance not exists in Group: [AppId] %s" +
+                            "[instanceId] %s", event.getAppId(), event.getInstanceId()));
+                    return false;
+                }
+            }
+            ApplicationStatus status = ApplicationStatus.Inactive;
+            if (!context.isStateTransitionValid(status)) {
+                log.error("Invalid State transfer from [ " + context.getStatus() +
+                        " ] to [ " + status + " ]");
+            }
+            context.setStatus(status);
+
+        }
+
+        // Notify event listeners
+        notifyEventListeners(event);
+        return true;
+
+    }
+}


[2/5] stratos git commit: adding instance prefix to events, , processor and listener

Posted by re...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationInstanceTerminatedMessageProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationInstanceTerminatedMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationInstanceTerminatedMessageProcessor.java
new file mode 100644
index 0000000..c7a39b5
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationInstanceTerminatedMessageProcessor.java
@@ -0,0 +1,97 @@
+/*
+ * 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.messaging.message.processor.applications;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.messaging.domain.applications.Applications;
+import org.apache.stratos.messaging.event.applications.ApplicationInstanceTerminatedEvent;
+import org.apache.stratos.messaging.message.processor.MessageProcessor;
+import org.apache.stratos.messaging.message.processor.applications.updater.ApplicationsUpdater;
+import org.apache.stratos.messaging.util.Util;
+
+/**
+ * This processor responsible to process the application Inactivation even and update the Topology.
+ */
+public class ApplicationInstanceTerminatedMessageProcessor extends MessageProcessor {
+    private static final Log log =
+            LogFactory.getLog(ApplicationInstanceTerminatedMessageProcessor.class);
+
+
+    private MessageProcessor nextProcessor;
+
+    @Override
+    public void setNext(MessageProcessor nextProcessor) {
+        this.nextProcessor = nextProcessor;
+    }
+
+
+    @Override
+    public boolean process(String type, String message, Object object) {
+        Applications applications = (Applications) object;
+
+        if (ApplicationInstanceTerminatedEvent.class.getName().equals(type)) {
+            // Return if applications has not been initialized
+            if (!applications.isInitialized())
+                return false;
+
+            // Parse complete message and build event
+            ApplicationInstanceTerminatedEvent event = (ApplicationInstanceTerminatedEvent) Util.
+                    jsonToObject(message, ApplicationInstanceTerminatedEvent.class);
+
+            ApplicationsUpdater.acquireWriteLockForApplications();
+
+            try {
+                return doProcess(event, applications);
+
+            } finally {
+                ApplicationsUpdater.releaseWriteLockForApplications();
+            }
+
+        } else {
+            if (nextProcessor != null) {
+                // ask the next processor to take care of the message.
+                return nextProcessor.process(type, message, applications);
+            } else {
+                throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message));
+            }
+        }
+    }
+
+    private boolean doProcess(ApplicationInstanceTerminatedEvent event, Applications applications) {
+
+        // check if required properties are available
+        if (event.getAppId() == null) {
+            String errorMsg = "Application Id of application removed event is invalid";
+            log.error(errorMsg);
+            throw new RuntimeException(errorMsg);
+        }
+
+        // check if an Application with same name exists in applications
+        String appId = event.getAppId();
+        if (applications.applicationExists(appId)) {
+            log.warn("Application with id [ " + appId + " ] still exists in Applications, removing it");
+            applications.removeApplication(appId);
+        }
+
+        notifyEventListeners(event);
+        return true;
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationInstanceTerminatingMessageProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationInstanceTerminatingMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationInstanceTerminatingMessageProcessor.java
new file mode 100644
index 0000000..7679091
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationInstanceTerminatingMessageProcessor.java
@@ -0,0 +1,113 @@
+/*
+ * 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.messaging.message.processor.applications;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.messaging.domain.applications.Application;
+import org.apache.stratos.messaging.domain.applications.ApplicationStatus;
+import org.apache.stratos.messaging.domain.applications.Applications;
+import org.apache.stratos.messaging.domain.instance.ApplicationInstance;
+import org.apache.stratos.messaging.event.applications.ApplicationInstanceTerminatingEvent;
+import org.apache.stratos.messaging.message.processor.MessageProcessor;
+import org.apache.stratos.messaging.message.processor.applications.updater.ApplicationsUpdater;
+import org.apache.stratos.messaging.util.Util;
+
+/**
+ * This processor responsible to process the application Inactivation even and update the Topology.
+ */
+public class ApplicationInstanceTerminatingMessageProcessor extends MessageProcessor {
+    private static final Log log =
+            LogFactory.getLog(ApplicationInstanceTerminatingMessageProcessor.class);
+
+
+    private MessageProcessor nextProcessor;
+
+    @Override
+    public void setNext(MessageProcessor nextProcessor) {
+        this.nextProcessor = nextProcessor;
+    }
+
+
+    @Override
+    public boolean process(String type, String message, Object object) {
+        Applications applications = (Applications) object;
+
+        if (ApplicationInstanceTerminatingEvent.class.getName().equals(type)) {
+            // Return if applications has not been initialized
+            if (!applications.isInitialized())
+                return false;
+
+            // Parse complete message and build event
+            ApplicationInstanceTerminatingEvent event = (ApplicationInstanceTerminatingEvent) Util.
+                    jsonToObject(message, ApplicationInstanceTerminatingEvent.class);
+
+            ApplicationsUpdater.acquireWriteLockForApplication(event.getAppId());
+
+            try {
+                return doProcess(event, applications);
+
+            } finally {
+                ApplicationsUpdater.releaseWriteLockForApplication(event.getAppId());
+            }
+
+        } else {
+            if (nextProcessor != null) {
+                // ask the next processor to take care of the message.
+                return nextProcessor.process(type, message, applications);
+            } else {
+                throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message));
+            }
+        }
+    }
+
+    private boolean doProcess(ApplicationInstanceTerminatingEvent event, Applications applications) {
+
+        // Validate event against the existing applications
+        Application application = applications.getApplication(event.getAppId());
+        if (application == null) {
+            if (log.isWarnEnabled()) {
+                log.warn(String.format("Application does not exist: [service] %s",
+                        event.getAppId()));
+            }
+            return false;
+        } else {
+            // Apply changes to the applications
+            ApplicationInstance context = application.getInstanceContexts(event.getInstanceId());
+            if(context == null) {
+                if (log.isWarnEnabled()) {
+                    log.warn(String.format("Application Instance not exists in Group: [AppId] %s" +
+                            "[instanceId] %s", event.getAppId(), event.getInstanceId()));
+                    return false;
+                }
+            }
+            ApplicationStatus status = ApplicationStatus.Terminating;
+            if (!context.isStateTransitionValid(status)) {
+                log.error("Invalid State transfer from [ " + context.getStatus() +
+                        " ] to [ " + status + " ]");
+            }
+            context.setStatus(status);
+        }
+
+        // Notify event listeners
+        notifyEventListeners(event);
+        return true;
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationTerminatedMessageProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationTerminatedMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationTerminatedMessageProcessor.java
deleted file mode 100644
index a6d2cd5..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationTerminatedMessageProcessor.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * 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.messaging.message.processor.applications;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.messaging.domain.applications.Applications;
-import org.apache.stratos.messaging.event.applications.ApplicationInstanceTerminatedEvent;
-import org.apache.stratos.messaging.message.processor.MessageProcessor;
-import org.apache.stratos.messaging.message.processor.applications.updater.ApplicationsUpdater;
-import org.apache.stratos.messaging.util.Util;
-
-/**
- * This processor responsible to process the application Inactivation even and update the Topology.
- */
-public class ApplicationTerminatedMessageProcessor extends MessageProcessor {
-    private static final Log log =
-            LogFactory.getLog(ApplicationTerminatedMessageProcessor.class);
-
-
-    private MessageProcessor nextProcessor;
-
-    @Override
-    public void setNext(MessageProcessor nextProcessor) {
-        this.nextProcessor = nextProcessor;
-    }
-
-
-    @Override
-    public boolean process(String type, String message, Object object) {
-        Applications applications = (Applications) object;
-
-        if (ApplicationInstanceTerminatedEvent.class.getName().equals(type)) {
-            // Return if applications has not been initialized
-            if (!applications.isInitialized())
-                return false;
-
-            // Parse complete message and build event
-            ApplicationInstanceTerminatedEvent event = (ApplicationInstanceTerminatedEvent) Util.
-                    jsonToObject(message, ApplicationInstanceTerminatedEvent.class);
-
-            ApplicationsUpdater.acquireWriteLockForApplications();
-
-            try {
-                return doProcess(event, applications);
-
-            } finally {
-                ApplicationsUpdater.releaseWriteLockForApplications();
-            }
-
-        } else {
-            if (nextProcessor != null) {
-                // ask the next processor to take care of the message.
-                return nextProcessor.process(type, message, applications);
-            } else {
-                throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message));
-            }
-        }
-    }
-
-    private boolean doProcess(ApplicationInstanceTerminatedEvent event, Applications applications) {
-
-        // check if required properties are available
-        if (event.getAppId() == null) {
-            String errorMsg = "Application Id of application removed event is invalid";
-            log.error(errorMsg);
-            throw new RuntimeException(errorMsg);
-        }
-
-        // check if an Application with same name exists in applications
-        String appId = event.getAppId();
-        if (applications.applicationExists(appId)) {
-            log.warn("Application with id [ " + appId + " ] still exists in Applications, removing it");
-            applications.removeApplication(appId);
-        }
-
-        notifyEventListeners(event);
-        return true;
-
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationTerminatingMessageProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationTerminatingMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationTerminatingMessageProcessor.java
deleted file mode 100644
index 33ad474..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationTerminatingMessageProcessor.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * 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.messaging.message.processor.applications;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.messaging.domain.applications.Application;
-import org.apache.stratos.messaging.domain.applications.ApplicationStatus;
-import org.apache.stratos.messaging.domain.applications.Applications;
-import org.apache.stratos.messaging.domain.instance.ApplicationInstance;
-import org.apache.stratos.messaging.event.applications.ApplicationInstanceTerminatingEvent;
-import org.apache.stratos.messaging.message.processor.MessageProcessor;
-import org.apache.stratos.messaging.message.processor.applications.updater.ApplicationsUpdater;
-import org.apache.stratos.messaging.util.Util;
-
-/**
- * This processor responsible to process the application Inactivation even and update the Topology.
- */
-public class ApplicationTerminatingMessageProcessor extends MessageProcessor {
-    private static final Log log =
-            LogFactory.getLog(ApplicationTerminatingMessageProcessor.class);
-
-
-    private MessageProcessor nextProcessor;
-
-    @Override
-    public void setNext(MessageProcessor nextProcessor) {
-        this.nextProcessor = nextProcessor;
-    }
-
-
-    @Override
-    public boolean process(String type, String message, Object object) {
-        Applications applications = (Applications) object;
-
-        if (ApplicationInstanceTerminatingEvent.class.getName().equals(type)) {
-            // Return if applications has not been initialized
-            if (!applications.isInitialized())
-                return false;
-
-            // Parse complete message and build event
-            ApplicationInstanceTerminatingEvent event = (ApplicationInstanceTerminatingEvent) Util.
-                    jsonToObject(message, ApplicationInstanceTerminatingEvent.class);
-
-            ApplicationsUpdater.acquireWriteLockForApplication(event.getAppId());
-
-            try {
-                return doProcess(event, applications);
-
-            } finally {
-                ApplicationsUpdater.releaseWriteLockForApplication(event.getAppId());
-            }
-
-        } else {
-            if (nextProcessor != null) {
-                // ask the next processor to take care of the message.
-                return nextProcessor.process(type, message, applications);
-            } else {
-                throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message));
-            }
-        }
-    }
-
-    private boolean doProcess(ApplicationInstanceTerminatingEvent event, Applications applications) {
-
-        // Validate event against the existing applications
-        Application application = applications.getApplication(event.getAppId());
-        if (application == null) {
-            if (log.isWarnEnabled()) {
-                log.warn(String.format("Application does not exist: [service] %s",
-                        event.getAppId()));
-            }
-            return false;
-        } else {
-            // Apply changes to the applications
-            ApplicationInstance context = application.getInstanceContexts(event.getInstanceId());
-            if(context == null) {
-                if (log.isWarnEnabled()) {
-                    log.warn(String.format("Application Instance not exists in Group: [AppId] %s" +
-                            "[instanceId] %s", event.getAppId(), event.getInstanceId()));
-                    return false;
-                }
-            }
-            ApplicationStatus status = ApplicationStatus.Terminating;
-            if (!context.isStateTransitionValid(status)) {
-                log.error("Invalid State transfer from [ " + context.getStatus() +
-                        " ] to [ " + status + " ]");
-            }
-            context.setStatus(status);
-        }
-
-        // Notify event listeners
-        notifyEventListeners(event);
-        return true;
-
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationsMessageProcessorChain.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationsMessageProcessorChain.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationsMessageProcessorChain.java
index a420eea..b88a3ec 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationsMessageProcessorChain.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/ApplicationsMessageProcessorChain.java
@@ -31,52 +31,52 @@ import org.apache.stratos.messaging.message.processor.MessageProcessorChain;
 public class ApplicationsMessageProcessorChain extends MessageProcessorChain {
     private static final Log log = LogFactory.getLog(ApplicationsMessageProcessorChain.class);
 
-    private GroupResetProcessor groupCreatedMessageProcessor;
-    private GroupActivatedProcessor groupActivatedMessageProcessor;
-    private GroupInActivateProcessor groupInActivateMessageProcessor;
-    private GroupTerminatedProcessor groupTerminatedProcessor;
-    private GroupTerminatingProcessor groupTerminatingProcessor;
-    private ApplicationActivatedMessageProcessor applicationActivatedMessageProcessor;
+    private GroupInstanceCreatedProcessor groupCreatedMessageProcessor;
+    private GroupInstanceActivatedProcessor groupActivatedMessageProcessor;
+    private GroupInstanceInActivateProcessor groupInActivateMessageProcessor;
+    private GroupInstanceTerminatedProcessor groupTerminatedProcessor;
+    private GroupInstanceTerminatingProcessor groupTerminatingProcessor;
+    private ApplicationInstanceActivatedMessageProcessor applicationActivatedMessageProcessor;
     private ApplicationCreatedMessageProcessor applicationCreatedMessageProcessor;
-    private ApplicationInactivatedMessageProcessor applicationInactivatedMessageProcessor;
-    private ApplicationTerminatedMessageProcessor applicationTerminatedMessageProcessor;
-    private ApplicationTerminatingMessageProcessor applicationTerminatingMessageProcessor;
+    private ApplicationInstanceInactivatedMessageProcessor applicationInactivatedMessageProcessor;
+    private ApplicationInstanceTerminatedMessageProcessor applicationTerminatedMessageProcessor;
+    private ApplicationInstanceTerminatingMessageProcessor applicationTerminatingMessageProcessor;
     private CompleteApplicationsMessageProcessor completeApplicationsMessageProcessor;
 
     public void initialize() {
         // Add instance notifier event processors
 
-        groupCreatedMessageProcessor = new GroupResetProcessor();
+        groupCreatedMessageProcessor = new GroupInstanceCreatedProcessor();
         add(groupCreatedMessageProcessor);
 
-        groupActivatedMessageProcessor = new GroupActivatedProcessor();
+        groupActivatedMessageProcessor = new GroupInstanceActivatedProcessor();
         add(groupActivatedMessageProcessor);
 
-        groupInActivateMessageProcessor = new GroupInActivateProcessor();
+        groupInActivateMessageProcessor = new GroupInstanceInActivateProcessor();
         add(groupInActivateMessageProcessor);
 
-        groupTerminatedProcessor = new GroupTerminatedProcessor();
+        groupTerminatedProcessor = new GroupInstanceTerminatedProcessor();
         add(groupTerminatedProcessor);
 
-        groupTerminatingProcessor = new GroupTerminatingProcessor();
+        groupTerminatingProcessor = new GroupInstanceTerminatingProcessor();
         add(groupTerminatingProcessor);
 
-        applicationActivatedMessageProcessor = new ApplicationActivatedMessageProcessor();
+        applicationActivatedMessageProcessor = new ApplicationInstanceActivatedMessageProcessor();
         add(applicationActivatedMessageProcessor);
 
         applicationCreatedMessageProcessor = new ApplicationCreatedMessageProcessor();
         add(applicationCreatedMessageProcessor);
 
-        applicationInactivatedMessageProcessor = new ApplicationInactivatedMessageProcessor();
+        applicationInactivatedMessageProcessor = new ApplicationInstanceInactivatedMessageProcessor();
         add(applicationInactivatedMessageProcessor);
 
-        applicationTerminatingMessageProcessor = new ApplicationTerminatingMessageProcessor();
+        applicationTerminatingMessageProcessor = new ApplicationInstanceTerminatingMessageProcessor();
         add(applicationTerminatingMessageProcessor);
 
         completeApplicationsMessageProcessor = new CompleteApplicationsMessageProcessor();
         add(completeApplicationsMessageProcessor);
 
-        applicationTerminatedMessageProcessor = new ApplicationTerminatedMessageProcessor();
+        applicationTerminatedMessageProcessor = new ApplicationInstanceTerminatedMessageProcessor();
         add(applicationTerminatedMessageProcessor);
 
         if (log.isDebugEnabled()) {
@@ -86,25 +86,25 @@ public class ApplicationsMessageProcessorChain extends MessageProcessorChain {
 
     public void addEventListener(EventListener eventListener) {
 
-        if (eventListener instanceof GroupResetEventListener) {
+        if (eventListener instanceof GroupInstanceCreatedEventListener) {
             groupCreatedMessageProcessor.addEventListener(eventListener);
-        } else if (eventListener instanceof GroupInactivateEventListener) {
+        } else if (eventListener instanceof GroupInstanceInactivateEventListener) {
             groupInActivateMessageProcessor.addEventListener(eventListener);
-        } else if (eventListener instanceof GroupActivatedEventListener) {
+        } else if (eventListener instanceof GroupInstanceActivatedEventListener) {
             groupActivatedMessageProcessor.addEventListener(eventListener);
-        } else if (eventListener instanceof GroupTerminatingEventListener) {
+        } else if (eventListener instanceof GroupInstanceTerminatingEventListener) {
             groupTerminatingProcessor.addEventListener(eventListener);
-        } else if (eventListener instanceof GroupTerminatedEventListener) {
+        } else if (eventListener instanceof GroupInstanceTerminatedEventListener) {
             groupTerminatedProcessor.addEventListener(eventListener);
         } else if (eventListener instanceof ApplicationCreatedEventListener) {
             applicationCreatedMessageProcessor.addEventListener(eventListener);
-        } else if (eventListener instanceof ApplicationActivatedEventListener) {
+        } else if (eventListener instanceof ApplicationInstanceActivatedEventListener) {
             applicationActivatedMessageProcessor.addEventListener(eventListener);
-        } else if (eventListener instanceof ApplicationInactivatedEventListener) {
+        } else if (eventListener instanceof ApplicationInstanceInactivatedEventListener) {
             applicationInactivatedMessageProcessor.addEventListener(eventListener);
-        } else if (eventListener instanceof ApplicationTerminatingEventListener) {
+        } else if (eventListener instanceof ApplicationInstanceTerminatingEventListener) {
             applicationTerminatingMessageProcessor.addEventListener(eventListener);
-        } else if (eventListener instanceof ApplicationTerminatedEventListener) {
+        } else if (eventListener instanceof ApplicationInstanceTerminatedEventListener) {
             applicationTerminatedMessageProcessor.addEventListener(eventListener);
         } else if (eventListener instanceof CompleteApplicationsEventListener) {
             completeApplicationsMessageProcessor.addEventListener(eventListener);

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupActivatedProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupActivatedProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupActivatedProcessor.java
deleted file mode 100644
index f37a7f4..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupActivatedProcessor.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * 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.messaging.message.processor.applications;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.messaging.domain.applications.Application;
-import org.apache.stratos.messaging.domain.applications.Applications;
-import org.apache.stratos.messaging.domain.applications.Group;
-import org.apache.stratos.messaging.domain.applications.GroupStatus;
-import org.apache.stratos.messaging.domain.instance.GroupInstance;
-import org.apache.stratos.messaging.event.applications.GroupActivatedEvent;
-import org.apache.stratos.messaging.message.processor.MessageProcessor;
-import org.apache.stratos.messaging.message.processor.applications.updater.ApplicationsUpdater;
-import org.apache.stratos.messaging.util.Util;
-
-/**
- * This processor will act upon the Group activation events
- */
-public class GroupActivatedProcessor extends MessageProcessor {
-    private static final Log log = LogFactory.getLog(GroupActivatedProcessor.class);
-    private MessageProcessor nextProcessor;
-
-    @Override
-    public void setNext(MessageProcessor nextProcessor) {
-        this.nextProcessor = nextProcessor;
-    }
-
-    @Override
-    public boolean process(String type, String message, Object object) {
-        Applications applications = (Applications) object;
-
-        if (GroupActivatedEvent.class.getName().equals(type)) {
-            // Return if applications has not been initialized
-            if (!applications.isInitialized())
-                return false;
-
-            // Parse complete message and build event
-            GroupActivatedEvent event = (GroupActivatedEvent) Util.
-                    jsonToObject(message, GroupActivatedEvent.class);
-
-            ApplicationsUpdater.acquireWriteLockForApplication(event.getAppId());
-
-            try {
-                return doProcess(event, applications);
-
-            } finally {
-                ApplicationsUpdater.releaseWriteLockForApplication(event.getAppId());
-            }
-
-        } else {
-            if (nextProcessor != null) {
-                // ask the next processor to take care of the message.
-                return nextProcessor.process(type, message, applications);
-            } else {
-                throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message));
-            }
-        }
-    }
-
-    private boolean doProcess(GroupActivatedEvent event, Applications applications) {
-
-        // Validate event against the existing topology
-        Application application = applications.getApplication(event.getAppId());
-        if (application == null) {
-            if (log.isWarnEnabled()) {
-                log.warn(String.format("Application does not exist: [service] %s",
-                        event.getAppId()));
-            }
-            return false;
-        }
-        Group group = application.getGroupRecursively(event.getGroupId());
-
-        if (group == null) {
-            if (log.isWarnEnabled()) {
-                log.warn(String.format("Group not exists in service: [AppId] %s [groupId] %s", event.getAppId(),
-                        event.getGroupId()));
-                return false;
-            }
-        } else {
-            GroupInstance context = group.getInstanceContexts(event.getInstanceId());
-            if(context == null) {
-                if (log.isWarnEnabled()) {
-                    log.warn(String.format("Group Instance not exists in Group: [AppId] %s [groupId] %s " +
-                                    "[instanceId] %s", event.getAppId(), event.getGroupId(),
-                            event.getInstanceId()));
-                    return false;
-                }
-            }
-            // Apply changes to the topology
-            GroupStatus status = GroupStatus.Active;
-            if (!context.isStateTransitionValid(status)) {
-                log.error("Invalid State Transition from " + context.getStatus() + " to " +
-                        status);
-                return false;
-            }
-            context.setStatus(status);
-        }
-
-        // Notify event listeners
-        notifyEventListeners(event);
-        return true;
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupInActivateProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupInActivateProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupInActivateProcessor.java
deleted file mode 100644
index 41a2881..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupInActivateProcessor.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * 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.messaging.message.processor.applications;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.messaging.domain.applications.Application;
-import org.apache.stratos.messaging.domain.applications.Applications;
-import org.apache.stratos.messaging.domain.applications.Group;
-import org.apache.stratos.messaging.domain.applications.GroupStatus;
-import org.apache.stratos.messaging.domain.instance.GroupInstance;
-import org.apache.stratos.messaging.event.applications.GroupInactivatedEvent;
-import org.apache.stratos.messaging.message.processor.MessageProcessor;
-import org.apache.stratos.messaging.message.processor.applications.updater.ApplicationsUpdater;
-import org.apache.stratos.messaging.util.Util;
-
-/**
- * This processor will act upon the Group activation events
- */
-public class GroupInActivateProcessor extends MessageProcessor {
-    private static final Log log = LogFactory.getLog(GroupInActivateProcessor.class);
-    private MessageProcessor nextProcessor;
-
-    @Override
-    public void setNext(MessageProcessor nextProcessor) {
-        this.nextProcessor = nextProcessor;
-    }
-
-    @Override
-    public boolean process(String type, String message, Object object) {
-        Applications applications = (Applications) object;
-
-        if (GroupInactivatedEvent.class.getName().equals(type)) {
-            // Return if applications has not been initialized
-            if (!applications.isInitialized())
-                return false;
-
-            // Parse complete message and build event
-            GroupInactivatedEvent event = (GroupInactivatedEvent) Util.
-                    jsonToObject(message, GroupInactivatedEvent.class);
-
-            ApplicationsUpdater.acquireWriteLockForApplication(event.getAppId());
-
-            try {
-                return doProcess(event, applications);
-
-            } finally {
-                ApplicationsUpdater.releaseWriteLockForApplication(event.getAppId());
-            }
-
-        } else {
-            if (nextProcessor != null) {
-                // ask the next processor to take care of the message.
-                return nextProcessor.process(type, message, applications);
-            } else {
-                throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message));
-            }
-        }
-    }
-
-    private boolean doProcess(GroupInactivatedEvent event, Applications applications) {
-
-        // Validate event against the existing applications
-        Application application = applications.getApplication(event.getAppId());
-        if (application == null) {
-            if (log.isWarnEnabled()) {
-                log.warn(String.format("Application does not exist: [service] %s",
-                        event.getAppId()));
-            }
-            return false;
-        }
-        Group group = application.getGroupRecursively(event.getGroupId());
-
-        if (group == null) {
-            if (log.isWarnEnabled()) {
-                log.warn(String.format("Group not exists in service: [AppId] %s [groupId] %s", event.getAppId(),
-                        event.getGroupId()));
-                return false;
-            }
-        } else {
-            GroupInstance context = group.getInstanceContexts(event.getInstanceId());
-            if(context == null) {
-                if (log.isWarnEnabled()) {
-                    log.warn(String.format("Group Instance not exists in Group: [AppId] %s [groupId] %s " +
-                                    "[instanceId] %s", event.getAppId(), event.getGroupId(),
-                            event.getInstanceId()));
-                    return false;
-                }
-            }
-            // Apply changes to the topology
-            GroupStatus status = GroupStatus.Inactive;
-            if (!context.isStateTransitionValid(status)) {
-                log.error("Invalid State Transition from " + context.getStatus() + " to " +
-                        status);
-                return false;
-            }
-            context.setStatus(status);
-        }
-
-        // Notify event listeners
-        notifyEventListeners(event);
-        return true;
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupInstanceActivatedProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupInstanceActivatedProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupInstanceActivatedProcessor.java
new file mode 100644
index 0000000..c74d176
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupInstanceActivatedProcessor.java
@@ -0,0 +1,120 @@
+/*
+ * 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.messaging.message.processor.applications;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.messaging.domain.applications.Application;
+import org.apache.stratos.messaging.domain.applications.Applications;
+import org.apache.stratos.messaging.domain.applications.Group;
+import org.apache.stratos.messaging.domain.applications.GroupStatus;
+import org.apache.stratos.messaging.domain.instance.GroupInstance;
+import org.apache.stratos.messaging.event.applications.GroupInstanceActivatedEvent;
+import org.apache.stratos.messaging.message.processor.MessageProcessor;
+import org.apache.stratos.messaging.message.processor.applications.updater.ApplicationsUpdater;
+import org.apache.stratos.messaging.util.Util;
+
+/**
+ * This processor will act upon the Group activation events
+ */
+public class GroupInstanceActivatedProcessor extends MessageProcessor {
+    private static final Log log = LogFactory.getLog(GroupInstanceActivatedProcessor.class);
+    private MessageProcessor nextProcessor;
+
+    @Override
+    public void setNext(MessageProcessor nextProcessor) {
+        this.nextProcessor = nextProcessor;
+    }
+
+    @Override
+    public boolean process(String type, String message, Object object) {
+        Applications applications = (Applications) object;
+
+        if (GroupInstanceActivatedEvent.class.getName().equals(type)) {
+            // Return if applications has not been initialized
+            if (!applications.isInitialized())
+                return false;
+
+            // Parse complete message and build event
+            GroupInstanceActivatedEvent event = (GroupInstanceActivatedEvent) Util.
+                    jsonToObject(message, GroupInstanceActivatedEvent.class);
+
+            ApplicationsUpdater.acquireWriteLockForApplication(event.getAppId());
+
+            try {
+                return doProcess(event, applications);
+
+            } finally {
+                ApplicationsUpdater.releaseWriteLockForApplication(event.getAppId());
+            }
+
+        } else {
+            if (nextProcessor != null) {
+                // ask the next processor to take care of the message.
+                return nextProcessor.process(type, message, applications);
+            } else {
+                throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message));
+            }
+        }
+    }
+
+    private boolean doProcess(GroupInstanceActivatedEvent event, Applications applications) {
+
+        // Validate event against the existing topology
+        Application application = applications.getApplication(event.getAppId());
+        if (application == null) {
+            if (log.isWarnEnabled()) {
+                log.warn(String.format("Application does not exist: [service] %s",
+                        event.getAppId()));
+            }
+            return false;
+        }
+        Group group = application.getGroupRecursively(event.getGroupId());
+
+        if (group == null) {
+            if (log.isWarnEnabled()) {
+                log.warn(String.format("Group not exists in service: [AppId] %s [groupId] %s", event.getAppId(),
+                        event.getGroupId()));
+                return false;
+            }
+        } else {
+            GroupInstance context = group.getInstanceContexts(event.getInstanceId());
+            if(context == null) {
+                if (log.isWarnEnabled()) {
+                    log.warn(String.format("Group Instance not exists in Group: [AppId] %s [groupId] %s " +
+                                    "[instanceId] %s", event.getAppId(), event.getGroupId(),
+                            event.getInstanceId()));
+                    return false;
+                }
+            }
+            // Apply changes to the topology
+            GroupStatus status = GroupStatus.Active;
+            if (!context.isStateTransitionValid(status)) {
+                log.error("Invalid State Transition from " + context.getStatus() + " to " +
+                        status);
+                return false;
+            }
+            context.setStatus(status);
+        }
+
+        // Notify event listeners
+        notifyEventListeners(event);
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupInstanceCreatedProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupInstanceCreatedProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupInstanceCreatedProcessor.java
new file mode 100644
index 0000000..aa17fbf
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupInstanceCreatedProcessor.java
@@ -0,0 +1,116 @@
+/*
+ * 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.messaging.message.processor.applications;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.messaging.domain.applications.Application;
+import org.apache.stratos.messaging.domain.applications.Applications;
+import org.apache.stratos.messaging.domain.applications.Group;
+import org.apache.stratos.messaging.domain.applications.GroupStatus;
+import org.apache.stratos.messaging.domain.instance.GroupInstance;
+import org.apache.stratos.messaging.event.applications.GroupInstanceCreatedEvent;
+import org.apache.stratos.messaging.message.processor.MessageProcessor;
+import org.apache.stratos.messaging.message.processor.applications.updater.ApplicationsUpdater;
+import org.apache.stratos.messaging.util.Util;
+
+/**
+ * This processor will act upon the Group activation events
+ */
+public class GroupInstanceCreatedProcessor extends MessageProcessor {
+    private static final Log log = LogFactory.getLog(GroupInstanceCreatedProcessor.class);
+    private MessageProcessor nextProcessor;
+
+    @Override
+    public void setNext(MessageProcessor nextProcessor) {
+        this.nextProcessor = nextProcessor;
+    }
+
+    @Override
+    public boolean process(String type, String message, Object object) {
+        Applications applications = (Applications) object;
+
+        if (GroupInstanceCreatedEvent.class.getName().equals(type)) {
+            // Return if applications has not been initialized
+            if (!applications.isInitialized())
+                return false;
+
+            // Parse complete message and build event
+            GroupInstanceCreatedEvent event = (GroupInstanceCreatedEvent) Util.
+                    jsonToObject(message, GroupInstanceCreatedEvent.class);
+
+            ApplicationsUpdater.acquireWriteLockForApplication(event.getAppId());
+
+            try {
+                return doProcess(event, applications);
+
+            } finally {
+                ApplicationsUpdater.releaseWriteLockForApplication(event.getAppId());
+            }
+
+        } else {
+            if (nextProcessor != null) {
+                // ask the next processor to take care of the message.
+                return nextProcessor.process(type, message, applications);
+            } else {
+                throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message));
+            }
+        }
+    }
+
+    private boolean doProcess(GroupInstanceCreatedEvent event, Applications applications) {
+
+        // Validate event against the existing applications
+        Application application = applications.getApplication(event.getAppId());
+        if (application == null) {
+            if (log.isWarnEnabled()) {
+                log.warn(String.format("Application does not exist: [service] %s",
+                        event.getAppId()));
+            }
+            return false;
+        }
+        Group group = application.getGroupRecursively(event.getGroupId());
+
+        if (group == null) {
+            if (log.isWarnEnabled()) {
+                log.warn(String.format("Group not exists in service: [AppId] %s [groupId] %s", event.getAppId(),
+                        event.getGroupId()));
+                return false;
+            }
+        } else {
+            // Apply changes to the applications
+            String instanceId = event.getGroupInstance().getInstanceId();
+            GroupInstance context = group.getInstanceContexts(instanceId);
+            if(context == null) {
+                if (log.isWarnEnabled()) {
+                    log.warn(String.format("Group Instance not exists in Group: [AppId] %s [groupId] %s " +
+                                    "[instanceId] %s", event.getAppId(), event.getGroupId(),
+                            instanceId));
+                    return false;
+                }
+            }
+            // Apply changes to the topology
+            group.addInstance(instanceId, event.getGroupInstance());
+        }
+
+        // Notify event listeners
+        notifyEventListeners(event);
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupInstanceInActivateProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupInstanceInActivateProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupInstanceInActivateProcessor.java
new file mode 100644
index 0000000..c1e00bf
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupInstanceInActivateProcessor.java
@@ -0,0 +1,120 @@
+/*
+ * 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.messaging.message.processor.applications;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.messaging.domain.applications.Application;
+import org.apache.stratos.messaging.domain.applications.Applications;
+import org.apache.stratos.messaging.domain.applications.Group;
+import org.apache.stratos.messaging.domain.applications.GroupStatus;
+import org.apache.stratos.messaging.domain.instance.GroupInstance;
+import org.apache.stratos.messaging.event.applications.GroupInstanceInactivatedEvent;
+import org.apache.stratos.messaging.message.processor.MessageProcessor;
+import org.apache.stratos.messaging.message.processor.applications.updater.ApplicationsUpdater;
+import org.apache.stratos.messaging.util.Util;
+
+/**
+ * This processor will act upon the Group activation events
+ */
+public class GroupInstanceInActivateProcessor extends MessageProcessor {
+    private static final Log log = LogFactory.getLog(GroupInstanceInActivateProcessor.class);
+    private MessageProcessor nextProcessor;
+
+    @Override
+    public void setNext(MessageProcessor nextProcessor) {
+        this.nextProcessor = nextProcessor;
+    }
+
+    @Override
+    public boolean process(String type, String message, Object object) {
+        Applications applications = (Applications) object;
+
+        if (GroupInstanceInactivatedEvent.class.getName().equals(type)) {
+            // Return if applications has not been initialized
+            if (!applications.isInitialized())
+                return false;
+
+            // Parse complete message and build event
+            GroupInstanceInactivatedEvent event = (GroupInstanceInactivatedEvent) Util.
+                    jsonToObject(message, GroupInstanceInactivatedEvent.class);
+
+            ApplicationsUpdater.acquireWriteLockForApplication(event.getAppId());
+
+            try {
+                return doProcess(event, applications);
+
+            } finally {
+                ApplicationsUpdater.releaseWriteLockForApplication(event.getAppId());
+            }
+
+        } else {
+            if (nextProcessor != null) {
+                // ask the next processor to take care of the message.
+                return nextProcessor.process(type, message, applications);
+            } else {
+                throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message));
+            }
+        }
+    }
+
+    private boolean doProcess(GroupInstanceInactivatedEvent event, Applications applications) {
+
+        // Validate event against the existing applications
+        Application application = applications.getApplication(event.getAppId());
+        if (application == null) {
+            if (log.isWarnEnabled()) {
+                log.warn(String.format("Application does not exist: [service] %s",
+                        event.getAppId()));
+            }
+            return false;
+        }
+        Group group = application.getGroupRecursively(event.getGroupId());
+
+        if (group == null) {
+            if (log.isWarnEnabled()) {
+                log.warn(String.format("Group not exists in service: [AppId] %s [groupId] %s", event.getAppId(),
+                        event.getGroupId()));
+                return false;
+            }
+        } else {
+            GroupInstance context = group.getInstanceContexts(event.getInstanceId());
+            if(context == null) {
+                if (log.isWarnEnabled()) {
+                    log.warn(String.format("Group Instance not exists in Group: [AppId] %s [groupId] %s " +
+                                    "[instanceId] %s", event.getAppId(), event.getGroupId(),
+                            event.getInstanceId()));
+                    return false;
+                }
+            }
+            // Apply changes to the topology
+            GroupStatus status = GroupStatus.Inactive;
+            if (!context.isStateTransitionValid(status)) {
+                log.error("Invalid State Transition from " + context.getStatus() + " to " +
+                        status);
+                return false;
+            }
+            context.setStatus(status);
+        }
+
+        // Notify event listeners
+        notifyEventListeners(event);
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupInstanceTerminatingProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupInstanceTerminatingProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupInstanceTerminatingProcessor.java
new file mode 100644
index 0000000..e3a8708
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupInstanceTerminatingProcessor.java
@@ -0,0 +1,122 @@
+/*
+ * 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.messaging.message.processor.applications;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.messaging.domain.applications.Application;
+import org.apache.stratos.messaging.domain.applications.Applications;
+import org.apache.stratos.messaging.domain.applications.Group;
+import org.apache.stratos.messaging.domain.applications.GroupStatus;
+import org.apache.stratos.messaging.domain.instance.GroupInstance;
+import org.apache.stratos.messaging.event.applications.GroupInstanceTerminatingEvent;
+import org.apache.stratos.messaging.message.processor.MessageProcessor;
+import org.apache.stratos.messaging.message.processor.applications.updater.ApplicationsUpdater;
+import org.apache.stratos.messaging.util.Util;
+
+/**
+ * This processor will act upon the Group activation events
+ */
+public class GroupInstanceTerminatingProcessor extends MessageProcessor {
+    private static final Log log = LogFactory.getLog(GroupInstanceTerminatingProcessor.class);
+    private MessageProcessor nextProcessor;
+
+    @Override
+    public void setNext(MessageProcessor nextProcessor) {
+        this.nextProcessor = nextProcessor;
+    }
+
+    @Override
+    public boolean process(String type, String message, Object object) {
+        Applications applications = (Applications) object;
+
+        if (GroupInstanceTerminatingEvent.class.getName().equals(type)) {
+            // Return if applications has not been initialized
+            if (!applications.isInitialized())
+                return false;
+
+            // Parse complete message and build event
+            GroupInstanceTerminatingEvent event = (GroupInstanceTerminatingEvent) Util.
+                    jsonToObject(message, GroupInstanceTerminatingEvent.class);
+
+            ApplicationsUpdater.acquireWriteLockForApplication(event.getAppId());
+
+            try {
+                return doProcess(event, applications);
+
+            } finally {
+                ApplicationsUpdater.releaseWriteLockForApplication(event.getAppId());
+            }
+
+        } else {
+            if (nextProcessor != null) {
+                // ask the next processor to take care of the message.
+                return nextProcessor.process(type, message, applications);
+            } else {
+                throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message));
+            }
+        }
+    }
+
+    private boolean doProcess(GroupInstanceTerminatingEvent event, Applications applications) {
+
+        // Validate event against the existing applications
+        Application application = applications.getApplication(event.getAppId());
+        if (application == null) {
+            if (log.isWarnEnabled()) {
+                log.warn(String.format("Application does not exist: [service] %s",
+                        event.getAppId()));
+            }
+            return false;
+        }
+        Group group = application.getGroupRecursively(event.getGroupId());
+
+        if (group == null) {
+            if (log.isWarnEnabled()) {
+                log.warn(String.format("Group not exists in service: [AppId] %s [groupId] %s", event.getAppId(),
+                        event.getGroupId()));
+                return false;
+            }
+        } else {
+            // Apply changes to the applications
+            GroupInstance context = group.getInstanceContexts(event.getInstanceId());
+            if(context == null) {
+                if (log.isWarnEnabled()) {
+                    log.warn(String.format("Group Instance not exists in Group: [AppId] %s [groupId] %s " +
+                                    "[instanceId] %s", event.getAppId(), event.getGroupId(),
+                            event.getInstanceId()));
+                    return false;
+                }
+            }
+            // Apply changes to the topology
+            GroupStatus status = GroupStatus.Terminating;
+            if (!context.isStateTransitionValid(status)) {
+                log.error("Invalid State Transition from " + context.getStatus() + " to " +
+                        status);
+                return false;
+            }
+            context.setStatus(status);
+
+        }
+
+        // Notify event listeners
+        notifyEventListeners(event);
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupResetProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupResetProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupResetProcessor.java
deleted file mode 100644
index f999ff3..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupResetProcessor.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * 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.messaging.message.processor.applications;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.messaging.domain.applications.Application;
-import org.apache.stratos.messaging.domain.applications.Applications;
-import org.apache.stratos.messaging.domain.applications.Group;
-import org.apache.stratos.messaging.domain.applications.GroupStatus;
-import org.apache.stratos.messaging.domain.instance.GroupInstance;
-import org.apache.stratos.messaging.event.applications.GroupResetEvent;
-import org.apache.stratos.messaging.message.processor.MessageProcessor;
-import org.apache.stratos.messaging.message.processor.applications.updater.ApplicationsUpdater;
-import org.apache.stratos.messaging.util.Util;
-
-/**
- * This processor will act upon the Group activation events
- */
-public class GroupResetProcessor extends MessageProcessor {
-    private static final Log log = LogFactory.getLog(GroupResetProcessor.class);
-    private MessageProcessor nextProcessor;
-
-    @Override
-    public void setNext(MessageProcessor nextProcessor) {
-        this.nextProcessor = nextProcessor;
-    }
-
-    @Override
-    public boolean process(String type, String message, Object object) {
-        Applications applications = (Applications) object;
-
-        if (GroupResetEvent.class.getName().equals(type)) {
-            // Return if applications has not been initialized
-            if (!applications.isInitialized())
-                return false;
-
-            // Parse complete message and build event
-            GroupResetEvent event = (GroupResetEvent) Util.
-                    jsonToObject(message, GroupResetEvent.class);
-
-            ApplicationsUpdater.acquireWriteLockForApplication(event.getAppId());
-
-            try {
-                return doProcess(event, applications);
-
-            } finally {
-                ApplicationsUpdater.releaseWriteLockForApplication(event.getAppId());
-            }
-
-        } else {
-            if (nextProcessor != null) {
-                // ask the next processor to take care of the message.
-                return nextProcessor.process(type, message, applications);
-            } else {
-                throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message));
-            }
-        }
-    }
-
-    private boolean doProcess(GroupResetEvent event, Applications applications) {
-
-        // Validate event against the existing applications
-        Application application = applications.getApplication(event.getAppId());
-        if (application == null) {
-            if (log.isWarnEnabled()) {
-                log.warn(String.format("Application does not exist: [service] %s",
-                        event.getAppId()));
-            }
-            return false;
-        }
-        Group group = application.getGroupRecursively(event.getGroupId());
-
-        if (group == null) {
-            if (log.isWarnEnabled()) {
-                log.warn(String.format("Group not exists in service: [AppId] %s [groupId] %s", event.getAppId(),
-                        event.getGroupId()));
-                return false;
-            }
-        } else {
-            // Apply changes to the applications
-            GroupInstance context = group.getInstanceContexts(event.getInstanceId());
-            if(context == null) {
-                if (log.isWarnEnabled()) {
-                    log.warn(String.format("Group Instance not exists in Group: [AppId] %s [groupId] %s " +
-                                    "[instanceId] %s", event.getAppId(), event.getGroupId(),
-                            event.getInstanceId()));
-                    return false;
-                }
-            }
-            // Apply changes to the topology
-            GroupStatus status = GroupStatus.Inactive;
-            if (!context.isStateTransitionValid(status)) {
-                log.error("Invalid State Transition from " + context.getStatus() + " to " +
-                        status);
-                return false;
-            }
-            context.setStatus(status);
-        }
-
-        // Notify event listeners
-        notifyEventListeners(event);
-        return true;
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupTerminatedProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupTerminatedProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupTerminatedProcessor.java
deleted file mode 100644
index d263174..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupTerminatedProcessor.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * 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.messaging.message.processor.applications;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.messaging.domain.applications.Application;
-import org.apache.stratos.messaging.domain.applications.Applications;
-import org.apache.stratos.messaging.domain.applications.Group;
-import org.apache.stratos.messaging.domain.applications.GroupStatus;
-import org.apache.stratos.messaging.domain.instance.GroupInstance;
-import org.apache.stratos.messaging.event.applications.GroupTerminatedEvent;
-import org.apache.stratos.messaging.message.processor.MessageProcessor;
-import org.apache.stratos.messaging.message.processor.applications.updater.ApplicationsUpdater;
-import org.apache.stratos.messaging.util.Util;
-
-/**
- * This processor will act upon the Group activation events
- */
-public class GroupTerminatedProcessor extends MessageProcessor {
-    private static final Log log = LogFactory.getLog(GroupTerminatedProcessor.class);
-    private MessageProcessor nextProcessor;
-
-    @Override
-    public void setNext(MessageProcessor nextProcessor) {
-        this.nextProcessor = nextProcessor;
-    }
-
-    @Override
-    public boolean process(String type, String message, Object object) {
-        Applications applications = (Applications) object;
-
-        if (GroupTerminatedEvent.class.getName().equals(type)) {
-            // Return if applications has not been initialized
-            if (!applications.isInitialized())
-                return false;
-
-            // Parse complete message and build event
-            GroupTerminatedEvent event = (GroupTerminatedEvent) Util.
-                    jsonToObject(message, GroupTerminatedEvent.class);
-
-            ApplicationsUpdater.acquireWriteLockForApplication(event.getAppId());
-
-            try {
-                return doProcess(event, applications);
-
-            } finally {
-                ApplicationsUpdater.releaseWriteLockForApplication(event.getAppId());
-            }
-
-        } else {
-            if (nextProcessor != null) {
-                // ask the next processor to take care of the message.
-                return nextProcessor.process(type, message, applications);
-            } else {
-                throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message));
-            }
-        }
-    }
-
-    private boolean doProcess(GroupTerminatedEvent event, Applications applications) {
-
-        // Validate event against the existing applications
-        Application application = applications.getApplication(event.getAppId());
-        if (application == null) {
-            if (log.isWarnEnabled()) {
-                log.warn(String.format("Application does not exist: [service] %s",
-                        event.getAppId()));
-            }
-            return false;
-        }
-        Group group = application.getGroupRecursively(event.getGroupId());
-
-        if (group == null) {
-            if (log.isWarnEnabled()) {
-                log.warn(String.format("Group not exists in service: [AppId] %s [groupId] %s", event.getAppId(),
-                        event.getGroupId()));
-                return false;
-            }
-        } else {
-            GroupInstance context = group.getInstanceContexts(event.getInstanceId());
-            if(context == null) {
-                if (log.isWarnEnabled()) {
-                    log.warn(String.format("Group Instance not exists in Group: [AppId] %s [groupId] %s " +
-                                    "[instanceId] %s", event.getAppId(), event.getGroupId(),
-                            event.getInstanceId()));
-                    return false;
-                }
-            }
-            // Apply changes to the topology
-            GroupStatus status = GroupStatus.Terminated;
-            if (!context.isStateTransitionValid(status)) {
-                log.error("Invalid State Transition from " + context.getStatus() + " to " +
-                        status);
-                return false;
-            }
-            context.setStatus(status);
-
-        }
-
-        // Notify event listeners
-        notifyEventListeners(event);
-        return true;
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupTerminatingProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupTerminatingProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupTerminatingProcessor.java
deleted file mode 100644
index 69df56b..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/GroupTerminatingProcessor.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * 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.messaging.message.processor.applications;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.messaging.domain.applications.Application;
-import org.apache.stratos.messaging.domain.applications.Applications;
-import org.apache.stratos.messaging.domain.applications.Group;
-import org.apache.stratos.messaging.domain.applications.GroupStatus;
-import org.apache.stratos.messaging.domain.instance.GroupInstance;
-import org.apache.stratos.messaging.event.applications.GroupTerminatingEvent;
-import org.apache.stratos.messaging.message.processor.MessageProcessor;
-import org.apache.stratos.messaging.message.processor.applications.updater.ApplicationsUpdater;
-import org.apache.stratos.messaging.util.Util;
-
-/**
- * This processor will act upon the Group activation events
- */
-public class GroupTerminatingProcessor extends MessageProcessor {
-    private static final Log log = LogFactory.getLog(GroupTerminatingProcessor.class);
-    private MessageProcessor nextProcessor;
-
-    @Override
-    public void setNext(MessageProcessor nextProcessor) {
-        this.nextProcessor = nextProcessor;
-    }
-
-    @Override
-    public boolean process(String type, String message, Object object) {
-        Applications applications = (Applications) object;
-
-        if (GroupTerminatingEvent.class.getName().equals(type)) {
-            // Return if applications has not been initialized
-            if (!applications.isInitialized())
-                return false;
-
-            // Parse complete message and build event
-            GroupTerminatingEvent event = (GroupTerminatingEvent) Util.
-                    jsonToObject(message, GroupTerminatingEvent.class);
-
-            ApplicationsUpdater.acquireWriteLockForApplication(event.getAppId());
-
-            try {
-                return doProcess(event, applications);
-
-            } finally {
-                ApplicationsUpdater.releaseWriteLockForApplication(event.getAppId());
-            }
-
-        } else {
-            if (nextProcessor != null) {
-                // ask the next processor to take care of the message.
-                return nextProcessor.process(type, message, applications);
-            } else {
-                throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message));
-            }
-        }
-    }
-
-    private boolean doProcess(GroupTerminatingEvent event, Applications applications) {
-
-        // Validate event against the existing applications
-        Application application = applications.getApplication(event.getAppId());
-        if (application == null) {
-            if (log.isWarnEnabled()) {
-                log.warn(String.format("Application does not exist: [service] %s",
-                        event.getAppId()));
-            }
-            return false;
-        }
-        Group group = application.getGroupRecursively(event.getGroupId());
-
-        if (group == null) {
-            if (log.isWarnEnabled()) {
-                log.warn(String.format("Group not exists in service: [AppId] %s [groupId] %s", event.getAppId(),
-                        event.getGroupId()));
-                return false;
-            }
-        } else {
-            // Apply changes to the applications
-            GroupInstance context = group.getInstanceContexts(event.getInstanceId());
-            if(context == null) {
-                if (log.isWarnEnabled()) {
-                    log.warn(String.format("Group Instance not exists in Group: [AppId] %s [groupId] %s " +
-                                    "[instanceId] %s", event.getAppId(), event.getGroupId(),
-                            event.getInstanceId()));
-                    return false;
-                }
-            }
-            // Apply changes to the topology
-            GroupStatus status = GroupStatus.Terminating;
-            if (!context.isStateTransitionValid(status)) {
-                log.error("Invalid State Transition from " + context.getStatus() + " to " +
-                        status);
-                return false;
-            }
-            context.setStatus(status);
-
-        }
-
-        // Notify event listeners
-        notifyEventListeners(event);
-        return true;
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cf1b3727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterActivatedProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterActivatedProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterActivatedProcessor.java
deleted file mode 100644
index 56f98cc..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterActivatedProcessor.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * 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.messaging.message.processor.topology;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.messaging.domain.instance.ClusterInstance;
-import org.apache.stratos.messaging.domain.topology.Cluster;
-import org.apache.stratos.messaging.domain.topology.ClusterStatus;
-import org.apache.stratos.messaging.domain.topology.Service;
-import org.apache.stratos.messaging.domain.topology.Topology;
-import org.apache.stratos.messaging.event.topology.ClusterActivatedEvent;
-import org.apache.stratos.messaging.message.filter.topology.TopologyClusterFilter;
-import org.apache.stratos.messaging.message.filter.topology.TopologyServiceFilter;
-import org.apache.stratos.messaging.message.processor.MessageProcessor;
-import org.apache.stratos.messaging.message.processor.topology.updater.TopologyUpdater;
-import org.apache.stratos.messaging.util.Util;
-
-/**
- * This processor will act upon the cluster activated event
- */
-public class ClusterActivatedProcessor extends MessageProcessor {
-    private static final Log log = LogFactory.getLog(ClusterActivatedProcessor.class);
-    private MessageProcessor nextProcessor;
-
-    @Override
-    public void setNext(MessageProcessor nextProcessor) {
-        this.nextProcessor = nextProcessor;
-    }
-
-    @Override
-    public boolean process(String type, String message, Object object) {
-
-        Topology topology = (Topology) object;
-
-        if (ClusterActivatedEvent.class.getName().equals(type)) {
-            // Return if topology has not been initialized
-            if (!topology.isInitialized()) {
-                return false;
-            }
-
-            // Parse complete message and build event
-            ClusterActivatedEvent event = (ClusterActivatedEvent) Util.
-                    jsonToObject(message, ClusterActivatedEvent.class);
-
-            TopologyUpdater.acquireWriteLockForCluster(event.getServiceName(), event.getClusterId());
-            try {
-                return doProcess(event, topology);
-
-            } finally {
-                TopologyUpdater.releaseWriteLockForCluster(event.getServiceName(), event.getClusterId());
-            }
-
-        } else {
-            if (nextProcessor != null) {
-                // ask the next processor to take care of the message.
-                return nextProcessor.process(type, message, topology);
-            } else {
-                throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message));
-            }
-        }
-    }
-
-    private boolean doProcess(ClusterActivatedEvent event, Topology topology) {
-
-        // Apply service filter
-        if (TopologyServiceFilter.getInstance().isActive()) {
-            if (TopologyServiceFilter.getInstance().serviceNameExcluded(event.getServiceName())) {
-                // Service is excluded, do not update topology or fire event
-                if (log.isDebugEnabled()) {
-                    log.debug(String.format("Service is excluded: [service] %s", event.getServiceName()));
-                }
-                return false;
-            }
-        }
-
-        // Apply cluster filter
-        if (TopologyClusterFilter.getInstance().isActive()) {
-            if (TopologyClusterFilter.getInstance().clusterIdExcluded(event.getClusterId())) {
-                // Cluster is excluded, do not update topology or fire event
-                if (log.isDebugEnabled()) {
-                    log.debug(String.format("Cluster is excluded: [cluster] %s", event.getClusterId()));
-                }
-                return false;
-            }
-        }
-
-        // Validate event against the existing topology
-        Service service = topology.getService(event.getServiceName());
-        if (service == null) {
-            if (log.isWarnEnabled()) {
-                log.warn(String.format("Service does not exist: [service] %s",
-                        event.getServiceName()));
-            }
-            return false;
-        }
-        Cluster cluster = service.getCluster(event.getClusterId());
-
-        if (cluster == null) {
-            if (log.isDebugEnabled()) {
-                log.debug(String.format("Cluster not exists in service: [service] %s [cluster] %s", event.getServiceName(),
-                        event.getClusterId()));
-                return false;
-            }
-        } else {
-            // Apply changes to the topology
-            ClusterInstance context = cluster.getInstanceContexts(event.getInstanceId());
-            if(context == null) {
-                log.warn("Cluster Instance Context is not found for [cluster] " +
-                        event.getClusterId() + " [instance-id] " +
-                        event.getInstanceId());
-                return false;
-            }
-            ClusterStatus status = ClusterStatus.Active;
-            if (!context.isStateTransitionValid(status)) {
-                log.error("Invalid State Transition from " + context.getStatus() + " to " + status);
-            }
-            context.setStatus(status);
-
-        }
-
-        // Notify event listeners
-        notifyEventListeners(event);
-        return true;
-    }
-
-}