You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2013/11/22 07:00:48 UTC
git commit: Moved statistics publisher initialization logic to init()
method
Updated Branches:
refs/heads/master e93bb7c93 -> 4df9f714c
Moved statistics publisher initialization logic to init() method
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/4df9f714
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/4df9f714
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/4df9f714
Branch: refs/heads/master
Commit: 4df9f714c24f7f6e7e3134034c879397e1eec601
Parents: e93bb7c
Author: Imesh Gunaratne <im...@apache.org>
Authored: Fri Nov 22 11:30:35 2013 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Fri Nov 22 11:30:35 2013 +0530
----------------------------------------------------------------------
.../statistics/WSO2CEPStatsPublisher.java | 29 +++++++++++++++-----
1 file changed, 22 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4df9f714/components/org.apache.stratos.load.balancer.common/src/main/java/org/apache/stratos/load/balancer/common/statistics/WSO2CEPStatsPublisher.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.load.balancer.common/src/main/java/org/apache/stratos/load/balancer/common/statistics/WSO2CEPStatsPublisher.java b/components/org.apache.stratos.load.balancer.common/src/main/java/org/apache/stratos/load/balancer/common/statistics/WSO2CEPStatsPublisher.java
index a781fba..0cb250e 100644
--- a/components/org.apache.stratos.load.balancer.common/src/main/java/org/apache/stratos/load/balancer/common/statistics/WSO2CEPStatsPublisher.java
+++ b/components/org.apache.stratos.load.balancer.common/src/main/java/org/apache/stratos/load/balancer/common/statistics/WSO2CEPStatsPublisher.java
@@ -38,24 +38,32 @@ import java.util.Map;
*/
public class WSO2CEPStatsPublisher implements LoadBalancerStatsPublisher {
private static final Log log = LogFactory.getLog(WSO2CEPStatsPublisher.class);
+
private static final String CALL_CENTER_DATA_STREAM = "stratos.lb.stats";
private static final String VERSION = "1.0.0";
private AsyncDataPublisher asyncDataPublisher;
+ private String ip;
+ private String port;
private boolean enabled = true;
public WSO2CEPStatsPublisher() {
- AgentConfiguration agentConfiguration = new AgentConfiguration();
- Agent agent = new Agent(agentConfiguration);
-
- //TODO read following from a config file?
- String ip = System.getProperty("thrift.receiver.ip");
- String port = System.getProperty("thrift.receiver.port");
+ //TODO: Move system properties to a config file
+ ip = System.getProperty("thrift.receiver.ip");
+ port = System.getProperty("thrift.receiver.port");
String enabledStr = System.getProperty("load.balancer.stats.publisher.enabled");
if(StringUtils.isNotBlank(enabledStr)) {
enabled = Boolean.getBoolean(enabledStr);
}
+ if(enabled) {
+ init();
+ }
+ }
- // Using asynchronous data publisher
+ private void init() {
+ AgentConfiguration agentConfiguration = new AgentConfiguration();
+ Agent agent = new Agent(agentConfiguration);
+
+ // Initialize asynchronous data publisher
asyncDataPublisher = new AsyncDataPublisher("tcp://"+ip+":"+port+"", "admin", "admin", agent);
String streamDefinition = "{" +
" 'name':'" + CALL_CENTER_DATA_STREAM + "'," +
@@ -74,6 +82,9 @@ public class WSO2CEPStatsPublisher implements LoadBalancerStatsPublisher {
@Override
public void setEnabled(boolean enabled) {
this.enabled = enabled;
+ if(this.enabled) {
+ init();
+ }
}
@Override
@@ -83,6 +94,10 @@ public class WSO2CEPStatsPublisher implements LoadBalancerStatsPublisher {
@Override
public void publish(Map<String, Integer> stats) {
+ if(!isEnabled()) {
+ throw new RuntimeException("Statistics publisher is not enabled");
+ }
+
for (Map.Entry<String, Integer> entry : stats.entrySet()) {
Object[] payload = new Object[]{entry.getKey(), entry.getValue()};