[jboss-cvs] jboss-profiler/java/src/expansion/org/jboss/profiler/exp/agent ...
Takuro Okada
t2-okada at nri.co.jp
Thu Oct 26 04:58:56 EDT 2006
User: tokada
Date: 06/10/26 04:58:56
Added: java/src/expansion/org/jboss/profiler/exp/agent Tag:
JBossProfiler_Expansion
DefaultProfilerServiceMBean.java
IProfilerService.java DefaultProfilerService.java
Log:
Revision Changes Path
No revision
No revision
1.1.2.1 +98 -0 jboss-profiler/java/src/expansion/org/jboss/profiler/exp/agent/Attic/DefaultProfilerServiceMBean.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: DefaultProfilerServiceMBean.java
===================================================================
RCS file: DefaultProfilerServiceMBean.java
diff -N DefaultProfilerServiceMBean.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ DefaultProfilerServiceMBean.java 26 Oct 2006 08:58:56 -0000 1.1.2.1
@@ -0,0 +1,98 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.profiler.exp.agent;
+
+import java.util.Map;
+
+import org.jboss.profiler.exp.agent.collector.model.Metric;
+import org.jboss.profiler.exp.agent.collector.model.MetricName;
+
+/**
+ * The JMX interface of profiler service.
+ * <p>In default, the following map objects are created. </p>
+ * <p>
+ * <table border="1">
+ * <tr>
+ * <td colspan="4">Map</td>
+ * </tr>
+ * <tr>
+ * <td rowspan="3" valign="top">category : String</td>
+ * <td colspan="3">Map</td>
+ * </tr>
+ * <tr>
+ * <td rowspan="2" valign="top">operation name : String</td>
+ * <td colspan="3">Map</td>
+ * </tr>
+ * <tr>
+ * <td>MetricName</td>
+ * <td>Metric</td>
+ * </tr>
+ * </table>
+ * </p>
+ *
+ * @author Takuro Okada (Nomura Research Institute, Ltd.)
+ * Copyright 2006 Nomura Research Institute, Ltd. All Rights Reserved.
+ * Copyright(c) Information-technology Promotion Agency, Japan. All rights reserved 2006.
+ * Result of Open Source Software Development Activities of Information-technology Promotion Agency, Japan.
+ */
+public interface DefaultProfilerServiceMBean extends IProfilerService {
+
+ /**
+ * Starts the service.
+ */
+ void start() throws Exception;
+
+ /**
+ * Creates the service.
+ */
+ void create() throws Exception;
+
+ /**
+ * Destroys the service
+ */
+ void destroy() throws Exception;
+
+ /**
+ * Stops the service.
+ */
+ void stop() throws Exception;
+
+ /**
+ * Sets the persistor class name.
+ * @param persistorName - persistor class name
+ */
+ void setPersistorName(String persistorName);
+
+ /**
+ * Sets whether the metric data is stored.
+ * @param storable - whether the metric data is stored
+ */
+ void setStorable(boolean storable);
+
+ /**
+ * Gets a snapshot of metric data.
+ * @return
+ */
+ Map<String, Map<String, Map<MetricName, Metric>>> snapMetrics();
+
+}
1.1.2.1 +43 -0 jboss-profiler/java/src/expansion/org/jboss/profiler/exp/agent/Attic/IProfilerService.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: IProfilerService.java
===================================================================
RCS file: IProfilerService.java
diff -N IProfilerService.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ IProfilerService.java 26 Oct 2006 08:58:56 -0000 1.1.2.1
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.profiler.exp.agent;
+
+import org.jboss.profiler.exp.agent.collector.MetricCollector;
+
+/**
+ * The proxy interface for JMX service
+ *
+ * @author Takuro Okada (Nomura Research Institute, Ltd.)
+ * Copyright 2006 Nomura Research Institute, Ltd. All Rights Reserved.
+ * Copyright(c) Information-technology Promotion Agency, Japan. All rights reserved 2006.
+ * Result of Open Source Software Development Activities of Information-technology Promotion Agency, Japan.
+ */
+public interface IProfilerService {
+
+ /**
+ * Submits the collector object.
+ * @param collector - collector object
+ */
+ void submitMetric(MetricCollector collector);
+
+}
1.1.2.1 +165 -0 jboss-profiler/java/src/expansion/org/jboss/profiler/exp/agent/Attic/DefaultProfilerService.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: DefaultProfilerService.java
===================================================================
RCS file: DefaultProfilerService.java
diff -N DefaultProfilerService.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ DefaultProfilerService.java 26 Oct 2006 08:58:56 -0000 1.1.2.1
@@ -0,0 +1,165 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.profiler.exp.agent;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import org.apache.log4j.Logger;
+import org.jboss.profiler.exp.agent.collector.MetricCollector;
+import org.jboss.profiler.exp.agent.collector.model.Metric;
+import org.jboss.profiler.exp.agent.collector.model.MetricName;
+import org.jboss.profiler.exp.agent.persistor.MetricsPersistor;
+import org.jboss.profiler.exp.util.CopyUtil;
+
+/**
+ *
+ * @see org.jboss.profiler.production.service.ProductionProfilerService
+ * @author Takuro Okada (Nomura Research Institute, Ltd.)
+ * Copyright 2006 Nomura Research Institute, Ltd. All Rights Reserved.
+ * Copyright(c) Information-technology Promotion Agency, Japan. All rights reserved 2006.
+ * Result of Open Source Software Development Activities of Information-technology Promotion Agency, Japan.
+ */
+public class DefaultProfilerService implements DefaultProfilerServiceMBean {
+
+ private static Logger logger = Logger.getLogger(DefaultProfilerService.class);
+
+ /*
+ * metrics entity
+ */
+ private Map<String, Map<String, Map<MetricName, Metric>>> metricsMap = new HashMap<String, Map<String,Map<MetricName, Metric>>>();
+
+ /*
+ * collector executor
+ */
+ private ExecutorService collectorExecutor = null;
+
+ /*
+ * persistor
+ */
+ private MetricsPersistor metricsPersistor = null;
+ private Timer persistentTimer = null;
+
+ /*
+ * parameters
+ */
+ private boolean storable = false;
+
+ public void start() throws Exception {
+ persistentTimer = new Timer("Persistent Timer", true);
+ persistentTimer.scheduleAtFixedRate(new PersistentTask(), 10000, 1*60*60*1000);
+
+ collectorExecutor = Executors.newSingleThreadExecutor();
+
+ logger.info("started");
+ }
+
+ public void create() throws Exception {
+ logger.info("created");
+ }
+
+ public void destroy() throws Exception {
+ logger.info("destroyed");
+ }
+
+ public void stop() throws Exception {
+ collectorExecutor.shutdown();
+ persistentTimer.cancel();
+ logger.info("stoped");
+ }
+
+ public void submitMetric(MetricCollector collector) {
+ collector.setMetricsMap(metricsMap);
+ if(collectorExecutor == null) return;
+ try {
+ collectorExecutor.execute(collector);
+ } catch (Exception e) {
+ logger.error("failed to run collector["+collector.getClass().getName()+"].");
+ }
+ }
+
+ public void setPersistorName(String persistorName) {
+ try {
+ metricsPersistor = (MetricsPersistor)Class.forName(persistorName).newInstance();
+ } catch (Exception e) {
+ logger.error("Persistor name is illegal.");
+ }
+ }
+
+ private void saveMetrics() {
+ if(!storable) return;
+ metricsPersistor.store(copyMetrics());
+ resetMetrics();
+ }
+
+ public void resetMetrics() {
+ synchronized(metricsMap) {
+ for(Map<String, Map<MetricName, Metric>> omap : metricsMap.values()) {
+ synchronized(omap) {
+ for(Map<MetricName, Metric> mmap : omap.values()) {
+ synchronized(mmap) {
+ for(Metric metric : mmap.values()) {
+ metric.reset();
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public Map<String, Map<String, Map<MetricName, Metric>>> snapMetrics() {
+ return copyMetrics();
+ }
+
+ @SuppressWarnings("unchecked")
+ private Map<String, Map<String, Map<MetricName, Metric>>> copyMetrics() {
+ Map result = null;
+ synchronized(metricsMap) {
+ try {
+ // TODO use Metric#clone()
+ result = (Map)CopyUtil.deepCopy((HashMap)metricsMap);
+ } catch (Exception e) {
+ logger.error("failed to copy the metrics data.");
+ }
+ }
+ return result;
+ }
+
+ public void setStorable(boolean storable) {
+ this.storable = storable;
+ }
+
+ private class PersistentTask extends TimerTask {
+
+ @Override
+ public void run() {
+ saveMetrics();
+ }
+ }
+
+}
More information about the jboss-cvs-commits
mailing list