You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2006/12/05 22:46:50 UTC
svn commit: r482795 [2/2] - in
/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix:
jbi/container/ jbi/event/ jbi/framework/ jbi/jmx/ jbi/management/stats/
jbi/messaging/ jbi/monitoring/ jbi/monitoring/stats/ jbi/nmr/fl...
Added: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/StatisticsService.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/StatisticsService.java?view=auto&rev=482795
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/StatisticsService.java (added)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/StatisticsService.java Tue Dec 5 13:46:47 2006
@@ -0,0 +1,352 @@
+/*
+ * 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.servicemix.jbi.monitoring;
+
+import java.util.Iterator;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessageExchange.Role;
+import javax.jbi.servicedesc.ServiceEndpoint;
+import javax.management.JMException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanOperationInfo;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.JbiConstants;
+import org.apache.servicemix.jbi.container.JBIContainer;
+import org.apache.servicemix.jbi.event.ComponentAdapter;
+import org.apache.servicemix.jbi.event.ComponentEvent;
+import org.apache.servicemix.jbi.event.ComponentListener;
+import org.apache.servicemix.jbi.event.EndpointAdapter;
+import org.apache.servicemix.jbi.event.EndpointEvent;
+import org.apache.servicemix.jbi.event.EndpointListener;
+import org.apache.servicemix.jbi.event.ExchangeEvent;
+import org.apache.servicemix.jbi.event.ExchangeListener;
+import org.apache.servicemix.jbi.framework.ComponentMBeanImpl;
+import org.apache.servicemix.jbi.management.AttributeInfoHelper;
+import org.apache.servicemix.jbi.management.BaseSystemService;
+import org.apache.servicemix.jbi.management.ManagementContext;
+import org.apache.servicemix.jbi.management.OperationInfoHelper;
+import org.apache.servicemix.jbi.messaging.MessageExchangeImpl;
+import org.apache.servicemix.jbi.servicedesc.AbstractServiceEndpoint;
+import org.apache.servicemix.jbi.servicedesc.EndpointSupport;
+
+public class StatisticsService extends BaseSystemService implements StatisticsServiceMBean {
+
+ private static final Log log = LogFactory.getLog(StatisticsService.class);
+
+ private ConcurrentHashMap componentStats = new ConcurrentHashMap();
+ private ConcurrentHashMap endpointStats = new ConcurrentHashMap();
+
+ private ComponentListener componentListener;
+ private EndpointListener endpointListener;
+ private ExchangeListener exchangeListener;
+ private boolean dumpStats = true;
+ private long statsInterval = 5;
+ private Timer statsTimer;
+ private TimerTask timerTask;
+
+ /**
+ * @return the statsInterval
+ */
+ public long getStatsInterval() {
+ return statsInterval;
+ }
+
+ /**
+ * @param statsInterval the statsInterval to set
+ */
+ public void setStatsInterval(long statsInterval) {
+ this.statsInterval = statsInterval;
+ }
+
+ /**
+ * @return the dumpStats
+ */
+ public boolean isDumpStats() {
+ return dumpStats;
+ }
+
+ /**
+ * @param dumpStats the dumpStats to set
+ */
+ public void setDumpStats(boolean value) {
+ if (dumpStats && !value) {
+ if (timerTask != null) {
+ timerTask.cancel();
+ }
+ }
+ else if (!dumpStats && value) {
+ dumpStats = value;//scheduleStatsTimer relies on dumpStats value
+ scheduleStatsTimer();
+ }
+ dumpStats = value;
+ }
+
+ protected Class getServiceMBean() {
+ return StatisticsServiceMBean.class;
+ }
+
+ public String getDescription() {
+ return "EndpointStats service";
+ }
+
+ public void resetAllStats() {
+ for (Iterator it = componentStats.values().iterator(); it.hasNext();) {
+ ComponentStats stats = (ComponentStats) it.next();
+ stats.reset();
+ }
+ for (Iterator it = endpointStats.values().iterator(); it.hasNext();) {
+ EndpointStats stats = (EndpointStats) it.next();
+ stats.reset();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see javax.jbi.management.LifeCycleMBean#start()
+ */
+ public void start() throws javax.jbi.JBIException {
+ super.start();
+ this.container.addListener(exchangeListener);
+ if (isDumpStats()) {
+ scheduleStatsTimer();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see javax.jbi.management.LifeCycleMBean#stop()
+ */
+ public void stop() throws javax.jbi.JBIException {
+ this.container.removeListener(exchangeListener);
+ super.stop();
+ for (Iterator it = componentStats.values().iterator(); it.hasNext();) {
+ ComponentStats stats = (ComponentStats) it.next();
+ stats.close();
+ }
+ if (timerTask != null) {
+ timerTask.cancel();
+ }
+ if (statsTimer != null) {
+ statsTimer.cancel();
+ }
+ }
+
+ public void init(JBIContainer container) throws JBIException {
+ endpointListener = new EndpointAdapter() {
+ public void internalEndpointRegistered(EndpointEvent event) {
+ onEndpointRegistered(event);
+ }
+ public void internalEndpointUnregistered(EndpointEvent event) {
+ onEndpointUnregistered(event);
+ }
+ public void externalEndpointRegistered(EndpointEvent event) {
+ onEndpointRegistered(event);
+ }
+ public void externalEndpointUnregistered(EndpointEvent event) {
+ onEndpointUnregistered(event);
+ }
+ };
+ componentListener = new ComponentAdapter() {
+ public void componentInitialized(ComponentEvent event) {
+ onComponentInitialized(event);
+ }
+ public void componentShutDown(ComponentEvent event) {
+ onComponentShutDown(event);
+ }
+ };
+ exchangeListener = new ExchangeListener() {
+ public void exchangeSent(ExchangeEvent event) {
+ onExchangeSent(event);
+ }
+ public void exchangeAccepted(ExchangeEvent event) {
+ onExchangeAccepted(event);
+ }
+ };
+ container.addListener(componentListener);
+ container.addListener(endpointListener);
+ super.init(container);
+ }
+
+ protected void onComponentInitialized(ComponentEvent event) {
+ ComponentMBeanImpl component = event.getComponent();
+ String key = component.getName();
+ ComponentStats stats = new ComponentStats(component);
+ componentStats.putIfAbsent(key, stats);
+ // Register MBean
+ ManagementContext context= container.getManagementContext();
+ try {
+ context.registerMBean(context.createObjectName(context.createObjectNameProps(stats, true)),
+ stats,
+ ComponentStatsMBean.class);
+ } catch (Exception e) {
+ log.info("Unable to register component statistics MBean: " + e.getMessage());
+ if (log.isDebugEnabled()) {
+ log.debug("Unable to register component statistics MBean", e);
+ }
+ }
+ }
+
+ protected void onComponentShutDown(ComponentEvent event) {
+ ComponentMBeanImpl component = event.getComponent();
+ String key = component.getName();
+ ComponentStats stats = (ComponentStats) componentStats.remove(key);
+ // Register MBean
+ ManagementContext context= container.getManagementContext();
+ try {
+ context.unregisterMBean(context.createObjectName(context.createObjectNameProps(stats, true)));
+ } catch (Exception e) {
+ log.info("Unable to unregister component statistics MBean: " + e.getMessage());
+ if (log.isDebugEnabled()) {
+ log.debug("Unable to unregister component statistics MBean", e);
+ }
+ }
+ }
+
+ protected void onEndpointRegistered(EndpointEvent event) {
+ AbstractServiceEndpoint endpoint = (AbstractServiceEndpoint) event.getEndpoint();
+ String key = EndpointSupport.getUniqueKey(endpoint);
+ ComponentStats compStats = (ComponentStats) componentStats.get(endpoint.getComponentNameSpace().getName());
+ EndpointStats stats = new EndpointStats(endpoint, compStats.getMessagingStats());
+ endpointStats.putIfAbsent(key, stats);
+ // Register MBean
+ ManagementContext context= container.getManagementContext();
+ try {
+ context.registerMBean(context.createObjectName(context.createObjectNameProps(stats, true)),
+ stats,
+ EndpointStatsMBean.class);
+ } catch (Exception e) {
+ log.info("Unable to register endpoint statistics MBean: " + e.getMessage());
+ if (log.isDebugEnabled()) {
+ log.debug("Unable to register endpoint statistics MBean", e);
+ }
+ }
+ }
+
+ protected void onEndpointUnregistered(EndpointEvent event) {
+ AbstractServiceEndpoint endpoint = (AbstractServiceEndpoint) event.getEndpoint();
+ String key = EndpointSupport.getUniqueKey(endpoint);
+ EndpointStats stats = (EndpointStats) endpointStats.remove(key);
+ // Register MBean
+ ManagementContext context= container.getManagementContext();
+ try {
+ context.unregisterMBean(context.createObjectName(context.createObjectNameProps(stats, true)));
+ } catch (Exception e) {
+ log.info("Unable to unregister endpoint statistics MBean: " + e.getMessage());
+ if (log.isDebugEnabled()) {
+ log.debug("Unable to unregister endpoint statistics MBean", e);
+ }
+ }
+ }
+
+ protected void onExchangeSent(ExchangeEvent event) {
+ MessageExchange me = event.getExchange();
+ // This is a new exchange sent by a consumer
+ if (me.getStatus() == ExchangeStatus.ACTIVE &&
+ me.getRole() == Role.CONSUMER &&
+ me.getMessage("out") == null &&
+ me.getFault() == null &&
+ me instanceof MessageExchangeImpl)
+ {
+ MessageExchangeImpl mei = (MessageExchangeImpl) me;
+ String source = (String) me.getProperty(JbiConstants.SENDER_ENDPOINT);
+ if (source == null) {
+ source = mei.getSourceId().getName();
+ ComponentStats stats = (ComponentStats) componentStats.get(source);
+ stats.incrementOutbound();
+ } else {
+ ServiceEndpoint[] ses = getContainer().getRegistry().getEndpointRegistry().getAllEndpointsForComponent(mei.getSourceId());
+ for (int i = 0; i < ses.length; i++) {
+ if (EndpointSupport.getKey(ses[i]).equals(source)) {
+ source = EndpointSupport.getUniqueKey(ses[i]);
+ EndpointStats stats = (EndpointStats) endpointStats.get(source);
+ stats.incrementOutbound();
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ protected void onExchangeAccepted(ExchangeEvent event) {
+ MessageExchange me = event.getExchange();
+ // This is a new exchange sent by a consumer
+ if (me.getStatus() == ExchangeStatus.ACTIVE &&
+ me.getRole() == Role.PROVIDER &&
+ me.getMessage("out") == null &&
+ me.getFault() == null &&
+ me instanceof MessageExchangeImpl)
+ {
+ String source = EndpointSupport.getUniqueKey(me.getEndpoint());
+ EndpointStats stats = (EndpointStats) endpointStats.get(source);
+ stats.incrementInbound();
+ }
+ }
+
+ protected void scheduleStatsTimer() {
+ if (statsTimer == null) {
+ statsTimer = new Timer(true);
+ }
+ if (timerTask != null) {
+ timerTask.cancel();
+ }
+ timerTask = new TimerTask() {
+ public void run() {
+ doDumpStats();
+ }
+ };
+ long interval = statsInterval * 1000;
+ statsTimer.scheduleAtFixedRate(timerTask, interval, interval);
+ }
+
+ protected void doDumpStats() {
+ for (Iterator it = componentStats.values().iterator(); it.hasNext();) {
+ ComponentStats stats = (ComponentStats) it.next();
+ stats.dumpStats();
+ }
+ }
+
+ /**
+ * Get an array of MBeanAttributeInfo
+ *
+ * @return array of AttributeInfos
+ * @throws JMException
+ */
+ public MBeanAttributeInfo[] getAttributeInfos() throws JMException {
+ AttributeInfoHelper helper = new AttributeInfoHelper();
+ helper.addAttribute(getObjectToManage(), "dumpStats", "Periodically dump Component statistics");
+ helper.addAttribute(getObjectToManage(), "statsInterval", "Interval (secs) before dumping statistics");
+ return AttributeInfoHelper.join(super.getAttributeInfos(), helper.getAttributeInfos());
+ }
+
+ /**
+ * Get an array of MBeanOperationInfo
+ *
+ * @return array of OperationInfos
+ */
+ public MBeanOperationInfo[] getOperationInfos() throws JMException {
+ OperationInfoHelper helper = new OperationInfoHelper();
+ helper.addOperation(getObjectToManage(), "resetAllStats", "reset all statistics");
+ return OperationInfoHelper.join(super.getOperationInfos(), helper.getOperationInfos());
+ }
+
+}
Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/StatisticsService.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/StatisticsService.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/StatisticsService.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/StatisticsServiceMBean.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/StatisticsServiceMBean.java?view=auto&rev=482795
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/StatisticsServiceMBean.java (added)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/StatisticsServiceMBean.java Tue Dec 5 13:46:47 2006
@@ -0,0 +1,45 @@
+/*
+ * 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.servicemix.jbi.monitoring;
+
+public interface StatisticsServiceMBean {
+
+ /**
+ * @return the statsInterval
+ */
+ public long getStatsInterval();
+
+ /**
+ * @param statsInterval the statsInterval to set
+ */
+ public void setStatsInterval(long statsInterval);
+
+ /**
+ * @return the dumpStats
+ */
+ public boolean isDumpStats();
+
+ /**
+ * @param dumpStats the dumpStats to set
+ */
+ public void setDumpStats(boolean value);
+
+ /**
+ * Reset all statistics
+ */
+ public void resetAllStats();
+}
Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/StatisticsServiceMBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/StatisticsServiceMBean.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/StatisticsServiceMBean.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/CountStatisticImpl.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/CountStatisticImpl.java?view=auto&rev=482795
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/CountStatisticImpl.java (added)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/CountStatisticImpl.java Tue Dec 5 13:46:47 2006
@@ -0,0 +1,125 @@
+/*
+ * 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.servicemix.jbi.monitoring.stats;
+
+import javax.management.j2ee.statistics.CountStatistic;
+
+import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * A count statistic implementation
+ *
+ * @version $Revision$
+ */
+public class CountStatisticImpl extends StatisticImpl implements CountStatistic {
+
+ private final AtomicLong counter = new AtomicLong(0);
+ private CountStatisticImpl parent;
+
+ public CountStatisticImpl(CountStatisticImpl parent, String name, String description) {
+ this(name, description);
+ this.parent = parent;
+ }
+
+ public CountStatisticImpl(String name, String description) {
+ this(name, "count", description);
+ }
+
+ public CountStatisticImpl(String name, String unit, String description) {
+ super(name, unit, description);
+ }
+
+ public void reset() {
+ super.reset();
+ counter.set(0);
+ }
+
+ public long getCount() {
+ return counter.get();
+ }
+
+ public void setCount(long count) {
+ counter.set(count);
+ }
+
+ public void add(long amount) {
+ counter.addAndGet(amount);
+ updateSampleTime();
+ if (parent != null) {
+ parent.add(amount);
+ }
+ }
+
+ public void increment() {
+ counter.incrementAndGet();
+ updateSampleTime();
+ if (parent != null) {
+ parent.increment();
+ }
+ }
+
+ public void subtract(long amount) {
+ counter.addAndGet(-amount);
+ updateSampleTime();
+ if (parent != null) {
+ parent.subtract(amount);
+ }
+ }
+
+ public void decrement() {
+ counter.decrementAndGet();
+ updateSampleTime();
+ if (parent != null) {
+ parent.decrement();
+ }
+ }
+
+ public CountStatisticImpl getParent() {
+ return parent;
+ }
+
+ public void setParent(CountStatisticImpl parent) {
+ this.parent = parent;
+ }
+
+ protected void appendFieldDescription(StringBuffer buffer) {
+ buffer.append(" count: ");
+ buffer.append(Long.toString(counter.get()));
+ super.appendFieldDescription(buffer);
+ }
+
+ /**
+ * @return the average time period that elapses between counter increments since the last reset.
+ */
+ public double getPeriod() {
+ double count = counter.get();
+ if( count == 0 )
+ return 0;
+ double time = (System.currentTimeMillis() - getStartTime());
+ return (time/(count*1000.0));
+ }
+
+ /**
+ * @return the number of times per second that the counter is incrementing since the last reset.
+ */
+ public double getFrequency() {
+ double count = counter.get();
+ double time = (System.currentTimeMillis() - getStartTime());
+ return (count*1000.0/time);
+ }
+
+}
Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/CountStatisticImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/CountStatisticImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/CountStatisticImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/Resettable.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/Resettable.java?view=auto&rev=482795
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/Resettable.java (added)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/Resettable.java Tue Dec 5 13:46:47 2006
@@ -0,0 +1,30 @@
+/*
+ * 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.servicemix.jbi.monitoring.stats;
+
+/**
+ * Represents some statistic that is capable of being reset
+ *
+ * @version $Revision$
+ */
+public interface Resettable {
+
+ /**
+ * Reset the statistic
+ */
+ public void reset();
+}
Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/Resettable.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/Resettable.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/Resettable.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/StatisticImpl.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/StatisticImpl.java?view=auto&rev=482795
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/StatisticImpl.java (added)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/StatisticImpl.java Tue Dec 5 13:46:47 2006
@@ -0,0 +1,91 @@
+/*
+ * 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.servicemix.jbi.monitoring.stats;
+
+import javax.management.j2ee.statistics.Statistic;
+
+/**
+ * Base class for a Statistic implementation
+ *
+ * @version $Revision$
+ */
+public class StatisticImpl implements Statistic, Resettable {
+ private String name;
+ private String unit;
+ private String description;
+ private long startTime;
+ private long lastSampleTime;
+
+ public StatisticImpl(String name, String unit, String description) {
+ this.name = name;
+ this.unit = unit;
+ this.description = description;
+ startTime = System.currentTimeMillis();
+ lastSampleTime = startTime;
+ }
+
+ public synchronized void reset() {
+ startTime = System.currentTimeMillis();
+ lastSampleTime = startTime;
+ }
+
+ protected synchronized void updateSampleTime() {
+ lastSampleTime = System.currentTimeMillis();
+ }
+
+ public synchronized String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(name);
+ buffer.append("{");
+ appendFieldDescription(buffer);
+ buffer.append(" }");
+ return buffer.toString();
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getUnit() {
+ return unit;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public synchronized long getStartTime() {
+ return startTime;
+ }
+
+ public synchronized long getLastSampleTime() {
+ return lastSampleTime;
+ }
+
+ protected synchronized void appendFieldDescription(StringBuffer buffer) {
+ buffer.append(" unit: ");
+ buffer.append(unit);
+ buffer.append(" startTime: ");
+ //buffer.append(new Date(startTime));
+ buffer.append(startTime);
+ buffer.append(" lastSampleTime: ");
+ //buffer.append(new Date(lastSampleTime));
+ buffer.append(lastSampleTime);
+ buffer.append(" description: ");
+ buffer.append(description);
+ }
+}
Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/StatisticImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/StatisticImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/StatisticImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/StatsImpl.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/StatsImpl.java?view=auto&rev=482795
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/StatsImpl.java (added)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/StatsImpl.java Tue Dec 5 13:46:47 2006
@@ -0,0 +1,76 @@
+/*
+ * 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.servicemix.jbi.monitoring.stats;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import javax.management.j2ee.statistics.Statistic;
+import javax.management.j2ee.statistics.Stats;
+
+/**
+ * Base class for a Stats implementation
+ *
+ * @version $Revision$
+ */
+public class StatsImpl extends StatisticImpl implements Stats, Resettable {
+ private Map map;
+
+ public StatsImpl() {
+ this(new HashMap());
+ }
+
+ public StatsImpl(Map map) {
+ super("stats", "many", "Used only as container, not Statistic");
+ this.map = map;
+ }
+
+ public void reset() {
+ Statistic[] stats = getStatistics();
+ for (int i = 0, size = stats.length; i < size; i++) {
+ Statistic stat = stats[i];
+ if (stat instanceof Resettable) {
+ Resettable r = (Resettable) stat;
+ r.reset();
+ }
+ }
+ }
+
+ public Statistic getStatistic(String name) {
+ return (Statistic) map.get(name);
+ }
+
+ public String[] getStatisticNames() {
+ Set keys = map.keySet();
+ String[] answer = new String[keys.size()];
+ keys.toArray(answer);
+ return answer;
+ }
+
+ public Statistic[] getStatistics() {
+ Collection values = map.values();
+ Statistic[] answer = new Statistic[values.size()];
+ values.toArray(answer);
+ return answer;
+ }
+
+ protected void addStatistic(String name, StatisticImpl statistic) {
+ map.put(name, statistic);
+ }
+}
Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/StatsImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/StatsImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/StatsImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/TimeStatisticImpl.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/TimeStatisticImpl.java?view=auto&rev=482795
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/TimeStatisticImpl.java (added)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/TimeStatisticImpl.java Tue Dec 5 13:46:47 2006
@@ -0,0 +1,188 @@
+/*
+ * 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.servicemix.jbi.monitoring.stats;
+
+/**
+ * A time statistic implementation
+ *
+ * @version $Revision$
+ */
+public class TimeStatisticImpl extends StatisticImpl {
+ private long count;
+ private long maxTime;
+ private long minTime;
+ private long totalTime;
+ private TimeStatisticImpl parent;
+
+ public TimeStatisticImpl(String name, String description) {
+ this(name, "millis", description);
+ }
+
+ public TimeStatisticImpl(TimeStatisticImpl parent, String name, String description) {
+ this(name, description);
+ this.parent = parent;
+ }
+
+ public TimeStatisticImpl(String name, String unit, String description) {
+ super(name, unit, description);
+ }
+
+ public synchronized void reset() {
+ super.reset();
+ count = 0;
+ maxTime = 0;
+ minTime = 0;
+ totalTime = 0;
+ }
+
+ public synchronized long getCount() {
+ return count;
+ }
+
+ public synchronized void addTime(long time) {
+ updateSampleTime();
+ count++;
+ totalTime += time;
+ if (time > maxTime) {
+ maxTime = time;
+ }
+ if (time < minTime || minTime == 0) {
+ minTime = time;
+ }
+ if (parent != null) {
+ parent.addTime(time);
+ }
+ }
+
+ public synchronized void addTime() {
+ long time = getLastSampleTime();
+ updateSampleTime();
+ time = getLastSampleTime() - time;
+ count++;
+ totalTime += time;
+ if (time > maxTime) {
+ maxTime = time;
+ }
+ if (time < minTime || minTime == 0) {
+ minTime = time;
+ }
+ if (parent != null) {
+ parent.addTime(time);
+ }
+ }
+
+ /**
+ * @return the maximum time of any step
+ */
+ public long getMaxTime() {
+ return maxTime;
+ }
+
+ /**
+ * @return the minimum time of any step
+ */
+ public synchronized long getMinTime() {
+ return minTime;
+ }
+
+ /**
+ * @return the total time of all the steps added together
+ */
+ public synchronized long getTotalTime() {
+ return totalTime;
+ }
+
+ /**
+ * @return the average time calculated by dividing the
+ * total time by the number of counts
+ */
+ public synchronized double getAverageTime() {
+ if (count == 0) {
+ return 0;
+ }
+ double d = totalTime;
+ return d / count;
+ }
+
+
+ /**
+ * @return the average time calculated by dividing the
+ * total time by the number of counts but excluding the
+ * minimum and maximum times.
+ */
+ public synchronized double getAverageTimeExcludingMinMax() {
+ if (count <= 2) {
+ return 0;
+ }
+ double d = totalTime - minTime - maxTime;
+ return d / (count - 2);
+ }
+
+
+ /**
+ * @return the average number of steps per second
+ */
+ public double getAveragePerSecond() {
+ double d = 1000;
+ double averageTime = getAverageTime();
+ if (averageTime == 0) {
+ return 0;
+ }
+ return d / averageTime;
+ }
+
+ /**
+ * @return the average number of steps per second excluding the min & max values
+ */
+ public double getAveragePerSecondExcludingMinMax() {
+ double d = 1000;
+ double average = getAverageTimeExcludingMinMax();
+ if (average == 0) {
+ return 0;
+ }
+ return d / average;
+ }
+
+ public TimeStatisticImpl getParent() {
+ return parent;
+ }
+
+ public void setParent(TimeStatisticImpl parent) {
+ this.parent = parent;
+ }
+
+ protected synchronized void appendFieldDescription(StringBuffer buffer) {
+ buffer.append(" count: ");
+ buffer.append(Long.toString(count));
+ buffer.append(" maxTime: ");
+ buffer.append(Long.toString(maxTime));
+ buffer.append(" minTime: ");
+ buffer.append(Long.toString(minTime));
+ buffer.append(" totalTime: ");
+ buffer.append(Long.toString(totalTime));
+ buffer.append(" averageTime: ");
+ buffer.append(Double.toString(getAverageTime()));
+ buffer.append(" averageTimeExMinMax: ");
+ buffer.append(Double.toString(getAverageTimeExcludingMinMax()));
+ buffer.append(" averagePerSecond: ");
+ buffer.append(Double.toString(getAveragePerSecond()));
+ buffer.append(" averagePerSecondExMinMax: ");
+ buffer.append(Double.toString(getAveragePerSecondExcludingMinMax()));
+ super.appendFieldDescription(buffer);
+ }
+
+}
Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/TimeStatisticImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/TimeStatisticImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/monitoring/stats/TimeStatisticImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/nmr/flow/st/STFlow.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/nmr/flow/st/STFlow.java?view=diff&rev=482795&r1=482794&r2=482795
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/nmr/flow/st/STFlow.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/nmr/flow/st/STFlow.java Tue Dec 5 13:46:47 2006
@@ -20,10 +20,8 @@
import org.apache.servicemix.jbi.nmr.flow.AbstractFlow;
import org.apache.servicemix.jbi.servicedesc.AbstractServiceEndpoint;
-import javax.jbi.messaging.ExchangeStatus;
import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.MessagingException;
-import javax.jbi.messaging.MessageExchange.Role;
/**
* A simple Straight through flow.
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/view/DotViewEndpointListener.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/view/DotViewEndpointListener.java?view=diff&rev=482795&r1=482794&r2=482795
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/view/DotViewEndpointListener.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/view/DotViewEndpointListener.java Tue Dec 5 13:46:47 2006
@@ -18,8 +18,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.servicemix.jbi.container.ContainerAware;
import org.apache.servicemix.jbi.container.JBIContainer;
+import org.apache.servicemix.jbi.event.ContainerAware;
import org.apache.servicemix.jbi.framework.ComponentMBeanImpl;
import org.apache.servicemix.jbi.framework.Endpoint;
import org.apache.servicemix.jbi.framework.Registry;
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/view/DotViewFlowListener.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/view/DotViewFlowListener.java?view=diff&rev=482795&r1=482794&r2=482795
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/view/DotViewFlowListener.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/view/DotViewFlowListener.java Tue Dec 5 13:46:47 2006
@@ -166,6 +166,9 @@
}
}
+ public void exchangeAccepted(ExchangeEvent event) {
+ }
+
protected Map createSource(String name) {
synchronized (flow) {
Map componentFlow = (Map) flow.get(name);
@@ -198,9 +201,12 @@
public void componentInstalled(ComponentEvent event) {
createSource(event.getComponent().getName());
}
+
+ public void componentInitialized(ComponentEvent event) {
+ createSource(event.getComponent().getName());
+ }
public void componentStarted(ComponentEvent event) {
- createSource(event.getComponent().getName());
}
public void componentStopped(ComponentEvent event) {
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/tck/ExchangeCompletedListener.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/tck/ExchangeCompletedListener.java?view=diff&rev=482795&r1=482794&r2=482795
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/tck/ExchangeCompletedListener.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/tck/ExchangeCompletedListener.java Tue Dec 5 13:46:47 2006
@@ -48,6 +48,9 @@
exchanges.notify();
}
}
+
+ public void exchangeAccepted(ExchangeEvent event) {
+ }
public void assertExchangeCompleted() throws Exception {
long start = System.currentTimeMillis();