diff --git a/pom.xml b/pom.xml index 5d74592..115a363 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ de.jlo.talendcomp jlo-talendcomp-karaf-jmx - 3.1 + 3.2 jar jlo-karaf-jmx diff --git a/src/main/components/tKarafServiceMetricInput/tKarafServiceMetricInput_begin.javajet b/src/main/components/tKarafServiceMetricInput/tKarafServiceMetricInput_begin.javajet index f41051f..1ab4e55 100644 --- a/src/main/components/tKarafServiceMetricInput/tKarafServiceMetricInput_begin.javajet +++ b/src/main/components/tKarafServiceMetricInput/tKarafServiceMetricInput_begin.javajet @@ -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%>); <% } %> diff --git a/src/main/java/de/jlo/talendcomp/karaf/jmx/CXFMetricsCollector.java b/src/main/java/de/jlo/talendcomp/karaf/jmx/CXFMetricsCollector.java index 958386a..92a6288 100644 --- a/src/main/java/de/jlo/talendcomp/karaf/jmx/CXFMetricsCollector.java +++ b/src/main/java/de/jlo/talendcomp/karaf/jmx/CXFMetricsCollector.java @@ -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() {