[jboss-cvs] jboss-profiler/java/src/expansion/org/jboss/profiler/agent ...

Takuro Okada t2-okada at nri.co.jp
Wed Apr 11 07:13:11 EDT 2007


  User: tokada  
  Date: 07/04/11 07:13:11

  Added:       java/src/expansion/org/jboss/profiler/agent    Tag:
                        JBossProfiler_Expansion IProfilerService.java
                        DefaultProfilerServiceMBean.java
                        DefaultProfilerService.java
  Log:
  Moved to another directory
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +43 -0     jboss-profiler/java/src/expansion/org/jboss/profiler/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	11 Apr 2007 11:13:11 -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.agent;
  +
  +import org.jboss.profiler.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   +133 -0    jboss-profiler/java/src/expansion/org/jboss/profiler/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	11 Apr 2007 11:13:11 -0000	1.1.2.1
  @@ -0,0 +1,133 @@
  +/*
  + * 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.agent;
  +
  +import org.jboss.profiler.agent.collector.model.MetricsMap;
  +
  +/**
  + * The JMX interface of profiler 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 DefaultProfilerServiceMBean extends IProfilerService {
  +
  +    /**
  +     * Creates the service.
  +     */
  +    void create() throws Exception;
  +    
  +    /**
  +     * Starts the service.
  +     */
  +    void start() throws Exception;
  +    
  +    /**
  +     * Stops the service.
  +     */
  +    void stop();
  +    
  +    /**
  +     * Destroys the service
  +     */
  +    void destroy();
  +    
  +    /**
  +     * Sets the persistor class name.
  +     * @param persistorName - persistor class name
  +     */
  +    void setPersistorName(String persistorName);
  +    
  +    /**
  +     * Gets the persistor class name.
  +     * @return persistor class name
  +     */
  +    String getPersistorName();
  +    
  +    /**
  +     * Sets whether the metric data is stored.
  +     * @param storable - whether the metric data is stored
  +     */
  +    void setStorable(boolean storable);
  +    
  +    /**
  +     * Gets whether the metric data is stored.
  +     * @return whether the metric data is stored
  +     */
  +    boolean isStorable();
  +    
  +    /**
  +     * Sets a period to persist metrics data.
  +     * @param persistentPeriod - a period (minutes)
  +     */
  +    void setPersistentPeriod(long persistentPeriod);
  +    
  +    /**
  +     * Gets a period to persist metrics data.
  +     * @return a period (minutes)
  +     */
  +    long getPersistentPeriod();
  +    
  +    /**
  +     * Sets the path of persistent directory.
  +     * @param persistentPath the path of persistent directory
  +     */
  +    void setPersistentPath(String persistentPath);
  +    
  +    /**
  +     * Gets the path of persistent directory.
  +     * @return the path of persistent directory
  +     */
  +    String getPersistentPath();
  +    
  +    /**
  +     * Gets the size of the metrics data.
  +     * @return the size of the metrics data
  +     */
  +    int getMetricsSize();
  +    
  +    /**
  +     * Gets a snapshot of current metrics data.
  +     * @return metrics data
  +     */
  +    MetricsMap snapMetrics();
  +    
  +    /**
  +     * Gets a snapshot of specified metrics data.
  +     * @param metricClass - searching expression of class that extends Metric.
  +     * @param metricNames - searching array of MetricName(value)
  +     * @param fromDate - searching  date (from)
  +     * @param toDate - searching  date (to)
  +     * @return metrics data
  +     * @see org.jboss.profiler.agent.collector.model.MetricName
  +     */
  +    MetricsMap snapMetrics(String metricClassName, String[] metricNames, Long fromDate, Long toDate);
  +    
  +    /**
  +     * Resets the metrics data.
  +     */
  +    void resetMetrics();
  +
  +}
  
  
  
  1.1.2.1   +230 -0    jboss-profiler/java/src/expansion/org/jboss/profiler/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	11 Apr 2007 11:13:11 -0000	1.1.2.1
  @@ -0,0 +1,230 @@
  +/*
  + * 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.agent;
  +
  +import java.io.File;
  +import java.util.Date;
  +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.adaptor.ServiceManager;
  +import org.jboss.profiler.agent.collector.MetricCollector;
  +import org.jboss.profiler.agent.collector.model.Metric;
  +import org.jboss.profiler.agent.collector.model.MetricName;
  +import org.jboss.profiler.agent.collector.model.MetricsMap;
  +import org.jboss.profiler.agent.persistor.MetricsPersistor;
  +import org.jboss.profiler.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 MetricsMap metricsMap = new MetricsMap();
  +    
  +    /*
  +     * collector executor
  +     */
  +    private ExecutorService collectorExecutor;
  +    
  +    /*
  +     * persistor
  +     */
  +    private String persistorName;
  +    private MetricsPersistor metricsPersistor;
  +    private Timer persistentTimer;
  +    private long persistentPeriod = 1*60*60*1000;
  +    
  +    /*
  +     * parameters
  +     */
  +    private boolean storable = false;
  +    private String persistentPath;
  +
  +    public void create() throws Exception {
  +        logger.info("created");
  +    }
  +    
  +    public void start() throws Exception {
  +        //The executor gives priority to adding a new thread.
  +        collectorExecutor = Executors.newCachedThreadPool();
  +        
  +        if(storable) {
  +            try {
  +                metricsPersistor = (MetricsPersistor)Class.forName(persistorName).newInstance();
  +            } catch (Exception e) {
  +                logger.error("Persistor name is illegal.");
  +            }
  +            
  +            if(persistentPath==null) {
  +                // JBoss AS only
  +                File file = (File)ServiceManager.getAttributeLocal("jboss.system:type=ServerConfig", "ServerLogDir");
  +                persistentPath = file.getPath() + File.separator + "jboss-profiler"+ File.separator;
  +            }
  +            metricsPersistor.setPersistentPath(persistentPath);
  +            
  +            persistentTimer = new Timer("Persistent Timer", true);
  +            persistentTimer.scheduleAtFixedRate(new PersistentTask(), 10000, persistentPeriod);
  +        }
  +        
  +        logger.info("started");
  +    }
  +
  +    public void stop() {
  +        if(storable) {
  +            persistentTimer.cancel();
  +        }
  +        collectorExecutor.shutdown();
  +        logger.info("stoped");
  +    }
  +
  +    public void destroy() {
  +        logger.info("destroyed");
  +    }
  +
  +    public void submitMetric(MetricCollector collector) {
  +        collector.setMetricsMap(metricsMap);
  +        if(collectorExecutor == null) return;
  +        try {
  +            synchronized(metricsMap) {
  +                collectorExecutor.execute(collector);
  +            }
  +        } catch (Exception e) {
  +            logger.error("failed to run collector["+collector.getClass().getName()+"].");
  +        }
  +    }
  +
  +    public void setPersistorName(String persistorName) {
  +        this.persistorName = persistorName;
  +    }
  +
  +    public void setPersistentPeriod(long persistentPeriod) {
  +        this.persistentPeriod = persistentPeriod * 60 * 1000;
  +    }
  +
  +    public void setStorable(boolean storable) {
  +        this.storable = storable;
  +    }
  +
  +    public void setPersistentPath(String persistentPath) {
  +        this.persistentPath = persistentPath;
  +    }
  +
  +    public String getPersistentPath() {
  +        return persistentPath;
  +    }
  +
  +    public long getPersistentPeriod() {
  +        return persistentPeriod;
  +    }
  +
  +    public String getPersistorName() {
  +        return persistorName;
  +    }
  +
  +    public boolean isStorable() {
  +        return storable;
  +    }
  +
  +    public int getMetricsSize() {
  +        int result = 0;
  +        for(Map<String, Map<MetricName, Metric>> ov : metricsMap.values()) {
  +            for(Map<MetricName, Metric> mv : ov.values()) {
  +                result += mv.size();
  +            }
  +        }
  +        return result;
  +    }
  +
  +    private void saveMetrics() {
  +        if(!storable || metricsMap.size()==0) return;
  +        metricsPersistor.store(copyMetrics());
  +        resetMetrics();
  +        logger.info("saved current metrics data.");
  +    }
  +    
  +    public void resetMetrics() {
  +        synchronized(metricsMap) {
  +            metricsMap = new MetricsMap();
  +        }
  +    }
  +    
  +    public MetricsMap snapMetrics() {
  +        return copyMetrics();
  +    }
  +
  +    public MetricsMap snapMetrics(String metricClassName, String[] metricNameStrings, Long fromDate, Long toDate) {
  +        MetricsMap result = null;
  +        MetricName[] metricNames = new MetricName[metricNameStrings.length];
  +        for(int i=0; i<metricNameStrings.length; i++) {
  +            metricNames[i] = MetricName.valueOf(metricNameStrings[i]);
  +        }
  +        Date from = null;
  +        Date to = null;
  +        try {
  +            if(fromDate>0) from = new Date(fromDate);
  +            if(toDate>0) to = new Date(toDate);
  +            result = metricsPersistor.load(Class.forName(metricClassName), metricNames, from, to);
  +        } catch (ClassNotFoundException e) {
  +            logger.error("Metric class name is illegal.");
  +        }
  +        return result;
  +    }
  +
  +    @SuppressWarnings("unchecked")
  +    private MetricsMap copyMetrics() {
  +        MetricsMap result = null;
  +        try {
  +            synchronized(metricsMap) {
  +                // TODO use Metric#clone()
  +                result = (MetricsMap)CopyUtil.deepCopy(metricsMap);
  +            }
  +        } catch (Exception e) {
  +            logger.error("failed to copy the metrics data.");
  +        }
  +        return result;
  +    }
  +    
  +    private class PersistentTask extends TimerTask {
  +
  +        @Override
  +        public void run() {
  +            saveMetrics();
  +        }
  +    }
  +
  +}
  
  
  



More information about the jboss-cvs-commits mailing list