Skip to content

Commit

Permalink
caching the connection
Browse files Browse the repository at this point in the history
  • Loading branch information
jlolling committed Dec 3, 2018
1 parent 4a9a8e3 commit b6268ab
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>de.jlo.talendcomp</groupId>
<artifactId>jlo-talendcomp-karaf-jmx</artifactId>
<version>3.1</version>
<version>3.2</version>
<packaging>jar</packaging>

<name>jlo-karaf-jmx</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,33 @@
String interval = ElementParameterParser.getValue(node, "__TIME_INTERVAL__");
String intervalServiceRefresh = ElementParameterParser.getValue(node, "__TIME_INTERVAL_BETWEEN_SERVICE_REFRESH__");
%>
de.jlo.talendcomp.karaf.jmx.KarafClient client_<%=cid%> = new de.jlo.talendcomp.karaf.jmx.KarafClient();
client_<%=cid%>.setJmxUser(<%=jmxUser%>);
client_<%=cid%>.setJmxPassword(<%=jmxPassword%>);
de.jlo.talendcomp.karaf.jmx.KarafClient client_<%=cid%> = (de.jlo.talendcomp.karaf.jmx.KarafClient) globalMap.get("client_<%=cid%>");
if (client_<%=cid%> == null) {
client_<%=cid%> = new de.jlo.talendcomp.karaf.jmx.KarafClient();
client_<%=cid%>.setJmxUser(<%=jmxUser%>);
client_<%=cid%>.setJmxPassword(<%=jmxPassword%>);
<% if (isKaraf) { %>
client_<%=cid%>.setKarafRemoteJmxUrl(<%=server%>, <%=jmxPort%>, <%=instance%>, <%=jstatdPort%>);
client_<%=cid%>.setKarafRemoteJmxUrl(<%=server%>, <%=jmxPort%>, <%=instance%>, <%=jstatdPort%>);
<% } else { %>
client_<%=cid%>.setJmxUrl(<%=jmxUrl%>);
client_<%=cid%>.setJmxUrl(<%=jmxUrl%>);
<% } %>
try {
client_<%=cid%>.connect();
} catch (Exception e) {
globalMap.put("<%=cid%>_ERROR_MESSAGE", "Connect to jmx failed: " + e.getMessage());
throw new Exception("Connect to jmx failed: URL: " + client_<%=cid%>.getJmxServiceUrl(), e);
try {
client_<%=cid%>.connect();
} catch (Exception e) {
globalMap.put("<%=cid%>_ERROR_MESSAGE", "Connect to jmx failed: " + e.getMessage());
throw new Exception("Connect to jmx failed: URL: " + client_<%=cid%>.getJmxServiceUrl(), e);
}
globalMap.put("client_<%=cid%>", client_<%=cid%>);
}
de.jlo.talendcomp.karaf.jmx.CXFMetricsCollector <%=cid%> = (de.jlo.talendcomp.karaf.jmx.CXFMetricsCollector) globalMap.get("<%=cid%>");
if (<%=cid%> == null) {
<%=cid%> = new de.jlo.talendcomp.karaf.jmx.CXFMetricsCollector(client_<%=cid%>);
globalMap.put("client_<%=cid%>", client_<%=cid%>);
}
de.jlo.talendcomp.karaf.jmx.JVMMetricsCollector <%=cid%>_jvm = (de.jlo.talendcomp.karaf.jmx.JVMMetricsCollector) globalMap.get("<%=cid%>_jvm");
if (<%=cid%>_jvm == null) {
<%=cid%>_jvm = new de.jlo.talendcomp.karaf.jmx.JVMMetricsCollector(client_<%=cid%>);
}
globalMap.put("client_<%=cid%>", client_<%=cid%>);
de.jlo.talendcomp.karaf.jmx.CXFMetricsCollector <%=cid%> = new de.jlo.talendcomp.karaf.jmx.CXFMetricsCollector(client_<%=cid%>);
de.jlo.talendcomp.karaf.jmx.JVMMetricsCollector <%=cid%>_jvm = new de.jlo.talendcomp.karaf.jmx.JVMMetricsCollector(client_<%=cid%>);
<% if (interval != null && interval.trim().isEmpty() == false) { %>
<%=cid%>.setInterval(<%=interval%>);
<% } %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,13 @@ public boolean next() throws Exception {
return false;
}
}
boolean run = false;
if (interval > 0 || lastExecutionTime == 0l) {
run = true;
}
lastExecutionTime = System.currentTimeMillis();
return true;
// if the interval == 0 we want only one run
return run;
}

public long getInterval() {
Expand Down

0 comments on commit b6268ab

Please sign in to comment.