Repository: stratos
Updated Branches:
  refs/heads/master 917be8eb2 -> 302c58b38


http://git-wip-us.apache.org/repos/asf/stratos/blob/ad66a0cd/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/util/Util.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/util/Util.java
 
b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/util/Util.java
index eb7f49a..d5df69d 100644
--- 
a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/util/Util.java
+++ 
b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/util/Util.java
@@ -32,18 +32,54 @@ import java.util.Properties;
 import java.util.UUID;
 
 /**
- *  Messaging module utility class
+ * Messaging module utility class
  */
 public class Util {
        private static final Log log = LogFactory.getLog(Util.class);
        public static final int BEGIN_INDEX = 35;
+       public static final String TENANT_RANGE_DELIMITER = "-";
+       public static final String AVERAGE_PING_INTERVAL_PROPERTY = 
"stratos.messaging.averagePingInterval";
+       public static final String FAILOVER_PING_INTERVAL_PROPERTY = 
"stratos.messaging.failoverPingInterval";
+       public static final int DEFAULT_AVERAGE_PING_INTERVAL = 1000;
+       public static final int DEFAULT_FAILOVER_PING_INTERVAL = 30000;
+
        // Time interval between each ping message sent to topic.
        private static int averagePingInterval;
        // Time interval between each ping message after an error had occurred.
        private static int failoverPingInterval;
 
        /**
+        * Enum for Messaging topics
+        */
+       public static enum Topics {
+               TOPOLOGY_TOPIC("topology/#"),
+               HEALTH_STAT_TOPIC("summarized-health-stats"),
+               INSTANCE_STATUS_TOPIC("instance/status/#"),
+               INSTANCE_NOTIFIER_TOPIC("instance/notifier/#"),
+               APPLICATIONS_TOPIC("applications/#"),
+               CLUSTER_STATUS_TOPIC("cluster/status/#"),
+               TENANT_TOPIC("tenant/#");
+
+               private String topicName;
+
+               private Topics(String topicName) {
+                       this.topicName = topicName;
+               }
+
+               /**
+                * Get the topic name
+                *
+                * @return topic name
+                */
+               public String getTopicName() {
+                       return topicName;
+               }
+
+       }
+
+       /**
         * Properties of the given file
+        *
         * @param filePath path of the property file
         * @return Properties of the given file
         */
@@ -70,11 +106,11 @@ public class Util {
                return props;
        }
 
-
        /**
         * Validate tenant range.
         * Valid formats: Integer-Integer, Integer-*
         * Examples: 1-100, 101-200, 201-*
+        *
         * @param tenantRange Tenant range
         */
        public static void validateTenantRange(String tenantRange) {
@@ -83,7 +119,7 @@ public class Util {
                        if (tenantRange.equals("*")) {
                                valid = true;
                        } else {
-                               String[] array = 
tenantRange.split(Constants.TENANT_RANGE_DELIMITER);
+                               String[] array = 
tenantRange.split(TENANT_RANGE_DELIMITER);
                                if (array.length == 2) {
                                        // Integer-Integer
                                        if (isNumber(array[0]) && 
(isNumber(array[1]))) {
@@ -103,72 +139,76 @@ public class Util {
 
        /**
         * Check given string is a number
+        *
         * @param inputStr String to be checked
         * @return Boolean of given string is a number
         */
-    public static boolean isNumber(String inputStr) {
-        try {
-            Integer.parseInt(inputStr);
-            return true;
-        }
-        catch (NumberFormatException ignore) {
-            // Not a valid number
-        }
-        return false;
-    }
-    
-    /**
-     * Transform json into an object of given type.
-     * @param json json string
-     * @param type type of the class
-     * @return Object of the json String
-     */
-    public static Object jsonToObject(String json, Class type) {
-        return (new JsonMessage(json, type)).getObject();
-    }
+       public static boolean isNumber(String inputStr) {
+               try {
+                       Integer.parseInt(inputStr);
+                       return true;
+               } catch (NumberFormatException ignore) {
+                       // Not a valid number
+               }
+               return false;
+       }
+
+       /**
+        * Transform json into an object of given type.
+        *
+        * @param json json string
+        * @param type type of the class
+        * @return Object of the json String
+        */
+       public static Object jsonToObject(String json, Class type) {
+               return (new JsonMessage(json, type)).getObject();
+       }
 
        /**
         * Create a JSON string
+        *
         * @param obj object
         * @return JSON string
         */
-    public static String ObjectToJson(Object obj) {
-       Gson gson = new Gson();
-       String result = gson.toJson(obj);
-       return result;
-    }
-
+       public static String ObjectToJson(Object obj) {
+               Gson gson = new Gson();
+               String result = gson.toJson(obj);
+               return result;
+       }
 
        /**
         * Fetch value from system param
+        *
         * @return Average ping interval
         */
        public static int getAveragePingInterval() {
                if (averagePingInterval <= 0) {
                        averagePingInterval =
-                                             
Util.getNumericSystemProperty(Constants.DEFAULT_AVERAGE_PING_INTERVAL,
-                                                                           
Constants.AVERAGE_PING_INTERVAL_PROPERTY);
+                                       
Util.getNumericSystemProperty(DEFAULT_AVERAGE_PING_INTERVAL,
+                                                                     
AVERAGE_PING_INTERVAL_PROPERTY);
                }
                return averagePingInterval;
        }
 
        /**
         * Fetch value from system param
+        *
         * @return Fail over ping interval
         */
        public static int getFailoverPingInterval() {
                if (failoverPingInterval <= 0) {
                        failoverPingInterval =
-                                              
Util.getNumericSystemProperty(Constants.DEFAULT_FAILOVER_PING_INTERVAL,
-                                                                            
Constants.FAILOVER_PING_INTERVAL_PROPERTY);
+                                       
Util.getNumericSystemProperty(DEFAULT_FAILOVER_PING_INTERVAL,
+                                                                     
FAILOVER_PING_INTERVAL_PROPERTY);
                }
                return failoverPingInterval;
        }
 
        /**
         * Method to safely access numeric system properties
+        *
         * @param defaultValue default value of the property
-        * @param propertyKey property key
+        * @param propertyKey  property key
         * @return Numeric system properties
         */
        public static Integer getNumericSystemProperty(Integer defaultValue, 
String propertyKey) {
@@ -181,6 +221,7 @@ public class Util {
 
        /**
         * Get the Message topic name for event
+        *
         * @param event event name
         * @return String topic name of the event
         */
@@ -190,6 +231,7 @@ public class Util {
 
        /**
         * Get the event name for topic
+        *
         * @param topic topic Name
         * @return String Event name for topic
         */
@@ -199,11 +241,12 @@ public class Util {
 
        /**
         * Get the random string with UUID
+        *
         * @param len length of the String
         * @return Random String
         */
-
        public static String getRandomString(int len) {
-               return 
UUID.randomUUID().toString().replace("-","").substring(0,len);
+               return UUID.randomUUID().toString().replace("-", 
"").substring(0, len);
        }
-}
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/ad66a0cd/components/org.apache.stratos.messaging/src/test/java/org/apache/stratos/Util/test/UtilTest.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.messaging/src/test/java/org/apache/stratos/Util/test/UtilTest.java
 
b/components/org.apache.stratos.messaging/src/test/java/org/apache/stratos/Util/test/UtilTest.java
new file mode 100644
index 0000000..c9ac744
--- /dev/null
+++ 
b/components/org.apache.stratos.messaging/src/test/java/org/apache/stratos/Util/test/UtilTest.java
@@ -0,0 +1,35 @@
+/*
+ *
+ *  * 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.Util.test;
+
+import org.apache.stratos.messaging.util.Util;
+
+/**
+ * Created by gayan on 11/25/14.
+ */
+public class UtilTest {
+
+       public static void main(String[] args) {
+               System.out.print(Util.getRandomString(10));
+       }
+
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/ad66a0cd/components/org.apache.stratos.messaging/src/test/java/org/apache/stratos/messaging/test/MessageFilterTest.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.messaging/src/test/java/org/apache/stratos/messaging/test/MessageFilterTest.java
 
b/components/org.apache.stratos.messaging/src/test/java/org/apache/stratos/messaging/test/MessageFilterTest.java
index 1dc3345..2dc3ff0 100755
--- 
a/components/org.apache.stratos.messaging/src/test/java/org/apache/stratos/messaging/test/MessageFilterTest.java
+++ 
b/components/org.apache.stratos.messaging/src/test/java/org/apache/stratos/messaging/test/MessageFilterTest.java
@@ -19,16 +19,12 @@
 package org.apache.stratos.messaging.test;
 
 import org.apache.stratos.messaging.message.filter.MessageFilter;
-import org.apache.stratos.messaging.util.Constants;
 import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.JUnit4;
 
-import java.lang.RuntimeException;
-import java.util.ArrayList;
 import java.util.Collection;
-import java.util.List;
 
 /**
  * Message filter tests.

http://git-wip-us.apache.org/repos/asf/stratos/blob/ad66a0cd/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV40Utils.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV40Utils.java
 
b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV40Utils.java
index 4c3e451..b15b620 100644
--- 
a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV40Utils.java
+++ 
b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV40Utils.java
@@ -49,7 +49,6 @@ import org.apache.stratos.messaging.domain.topology.Cluster;
 import org.apache.stratos.messaging.domain.topology.Member;
 import org.apache.stratos.messaging.domain.topology.MemberStatus;
 import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
-import org.apache.stratos.messaging.util.Constants;
 import org.apache.stratos.rest.endpoint.bean.StratosApiResponse;
 import org.apache.stratos.rest.endpoint.bean.SubscriptionDomainRequest;
 import org.apache.stratos.rest.endpoint.bean.autoscaler.partition.Partition;
@@ -79,6 +78,7 @@ public class StratosApiV40Utils {
     public static final String SHOULD_DELETE_VOLUME = 
"volume.delete.on.unsubscription";
     public static final String VOLUME_SIZE = "volume.size.gb";
     public static final String DEVICE_NAME = "volume.device.name";
+       public static final String TENANT_RANGE_ALL = "*";
 
     private static Log log = LogFactory.getLog(StratosApiV40Utils.class);
     private static CartridgeSubscriptionManager cartridgeSubsciptionManager = 
new CartridgeSubscriptionManager();
@@ -696,7 +696,7 @@ public class StratosApiV40Utils {
         //getting the services for the tenantId
         for(Service service : services) {
             String tenantRange = service.getTenantRange();
-            if(tenantRange.equals(Constants.TENANT_RANGE_ALL)) {
+            if(tenantRange.equals(TENANT_RANGE_ALL)) {
                 //check whether any active instances found for this service in 
the Topology
 
                 Cluster cluster = 
TopologyManager.getTopology().getService(service.getType()).

http://git-wip-us.apache.org/repos/asf/stratos/blob/ad66a0cd/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
 
b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
index fb007d5..a67c02b 100644
--- 
a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
+++ 
b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
@@ -62,7 +62,6 @@ import org.apache.stratos.messaging.domain.topology.Member;
 import org.apache.stratos.messaging.domain.topology.MemberStatus;
 import 
org.apache.stratos.messaging.message.receiver.applications.ApplicationManager;
 import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
-import org.apache.stratos.messaging.util.Constants;
 import org.apache.stratos.rest.endpoint.bean.ApplicationBean;
 import org.apache.stratos.rest.endpoint.bean.CartridgeInfoBean;
 import org.apache.stratos.rest.endpoint.bean.GroupBean;
@@ -94,6 +93,7 @@ public class StratosApiV41Utils {
     public static final String VOLUME_SIZE = "volume.size.gb";
     public static final String DEVICE_NAME = "volume.device.name";
     public static final String VOLUME_ID = "volume.id";
+       public static final String TENANT_RANGE_ALL = "*";
 
     private static Log log = LogFactory.getLog(StratosApiV41Utils.class);
     private static CartridgeSubscriptionManager cartridgeSubsciptionManager = 
new CartridgeSubscriptionManager();
@@ -876,7 +876,7 @@ public class StratosApiV41Utils {
         //getting the services for the tenantId
         for (Service service : services) {
             String tenantRange = service.getTenantRange();
-            if (tenantRange.equals(Constants.TENANT_RANGE_ALL)) {
+            if (tenantRange.equals(TENANT_RANGE_ALL)) {
                 //check whether any active instances found for this service in 
the Topology
 
                 Cluster cluster = 
TopologyManager.getTopology().getService(service.getType()).

http://git-wip-us.apache.org/repos/asf/stratos/blob/ad66a0cd/extensions/cep/stratos-cep-extension/src/main/java/org/apache/stratos/cep/extension/FaultHandlingWindowProcessor.java
----------------------------------------------------------------------
diff --git 
a/extensions/cep/stratos-cep-extension/src/main/java/org/apache/stratos/cep/extension/FaultHandlingWindowProcessor.java
 
b/extensions/cep/stratos-cep-extension/src/main/java/org/apache/stratos/cep/extension/FaultHandlingWindowProcessor.java
index a2b0904..0c7766d 100644
--- 
a/extensions/cep/stratos-cep-extension/src/main/java/org/apache/stratos/cep/extension/FaultHandlingWindowProcessor.java
+++ 
b/extensions/cep/stratos-cep-extension/src/main/java/org/apache/stratos/cep/extension/FaultHandlingWindowProcessor.java
@@ -33,7 +33,7 @@ import 
org.apache.stratos.messaging.listener.topology.MemberActivatedEventListen
 import 
org.apache.stratos.messaging.listener.topology.MemberTerminatedEventListener;
 import 
org.apache.stratos.messaging.message.receiver.topology.TopologyEventReceiver;
 import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
-import org.apache.stratos.messaging.util.Constants;
+import org.apache.stratos.messaging.util.Util;
 import org.wso2.siddhi.core.config.SiddhiContext;
 import org.wso2.siddhi.core.event.StreamEvent;
 import org.wso2.siddhi.core.event.in.InEvent;
@@ -70,7 +70,7 @@ public class FaultHandlingWindowProcessor extends 
WindowProcessor implements Run
     private ThreadBarrier threadBarrier;
     private long timeToKeep;
     private ISchedulerSiddhiQueue<StreamEvent> window;
-    private EventPublisher healthStatPublisher = 
EventPublisherPool.getPublisher(Constants.HEALTH_STAT_TOPIC);
+    private EventPublisher healthStatPublisher = 
EventPublisherPool.getPublisher(Util.Topics.HEALTH_STAT_TOPIC.getTopicName());
     private Map<String, Object> MemberFaultEventMap = new HashMap<String, 
Object>();
     private Map<String, Object> memberFaultEventMessageMap = new 
HashMap<String, Object>();
 

Reply via email to