commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nico...@apache.org
Subject svn commit: r739997 - in /commons/sandbox/monitoring/branches/modules: core/src/main/java/org/apache/commons/monitoring/ core/src/main/java/org/apache/commons/monitoring/stopwatches/ reporting/src/main/java/org/apache/commons/monitoring/reporting/ spri...
Date Mon, 02 Feb 2009 14:57:20 GMT
Author: nicolas
Date: Mon Feb  2 14:57:19 2009
New Revision: 739997

URL: http://svn.apache.org/viewvc?rev=739997&view=rev
Log:
API change : StopWatch returns itself to allow method call chaining

Added:
    commons/sandbox/monitoring/branches/modules/spring/src/main/java/org/apache/commons/monitoring/spring/config/
    commons/sandbox/monitoring/branches/modules/spring/src/main/java/org/apache/commons/monitoring/spring/config/RepositoryFactoryBean.java
    commons/sandbox/monitoring/branches/modules/spring/src/main/java/org/apache/commons/monitoring/spring/config/WebappRepositoryFactoryBean.java
Modified:
    commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/StopWatch.java
    commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/stopwatches/DefaultStopWatch.java
    commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/stopwatches/SimpleStopWatch.java
    commons/sandbox/monitoring/branches/modules/reporting/src/main/java/org/apache/commons/monitoring/reporting/AbstractPeriodicLogger.java
    commons/sandbox/monitoring/branches/modules/spring/pom.xml

Modified: commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/StopWatch.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/StopWatch.java?rev=739997&r1=739996&r2=739997&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/StopWatch.java
(original)
+++ commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/StopWatch.java
Mon Feb  2 14:57:19 2009
@@ -37,18 +37,19 @@
      * Temporary stop the StopWatch. Elapsed time calculation will not include
      * time spent in paused mode.
      */
-    public abstract void pause();
+    public abstract StopWatch pause();
 
     /**
      * Resume the StopWatch after a pause.
      */
-    public abstract void resume();
+    public abstract StopWatch resume();
 
     /**
      * Stop monitoring the process. A StopWatch created with
      * {@link #start(Monitor)} cannot be re-used after stopped has been called.
+     * @return TODO
      */
-    public abstract void stop();
+    public abstract StopWatch stop();
 
     /**
      * Convenience method to stop or cancel a Stopwatch depending on success of
@@ -57,7 +58,7 @@
      * @param canceled
      * @return time elapsed since the probe has been started
      */
-    public abstract void stop( boolean canceled );
+    public abstract StopWatch stop( boolean canceled );
 
     /**
      * Cancel monitoring. Elapsed time will not be computed and will not be
@@ -72,7 +73,7 @@
      * In any way, the probe will still report thread concurrency even if
      * canceled.
      */
-    public abstract void cancel();
+    public abstract StopWatch cancel();
 
     /**
      * @return <code>true</code> if the StopWatch has been stopped

Modified: commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/stopwatches/DefaultStopWatch.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/stopwatches/DefaultStopWatch.java?rev=739997&r1=739996&r2=739997&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/stopwatches/DefaultStopWatch.java
(original)
+++ commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/stopwatches/DefaultStopWatch.java
Mon Feb  2 14:57:19 2009
@@ -1,7 +1,6 @@
 package org.apache.commons.monitoring.stopwatches;
 
 import org.apache.commons.monitoring.Monitor;
-import org.apache.commons.monitoring.StopWatch;
 import org.apache.commons.monitoring.Unit;
 
 /**
@@ -10,7 +9,6 @@
  * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
  */
 public class DefaultStopWatch extends SimpleStopWatch
-    implements StopWatch
 {
 
     /**

Modified: commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/stopwatches/SimpleStopWatch.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/stopwatches/SimpleStopWatch.java?rev=739997&r1=739996&r2=739997&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/stopwatches/SimpleStopWatch.java
(original)
+++ commons/sandbox/monitoring/branches/modules/core/src/main/java/org/apache/commons/monitoring/stopwatches/SimpleStopWatch.java
Mon Feb  2 14:57:19 2009
@@ -1,6 +1,7 @@
 package org.apache.commons.monitoring.stopwatches;
 
 import org.apache.commons.monitoring.Monitor;
+import org.apache.commons.monitoring.StopWatch;
 import org.apache.commons.monitoring.Unit;
 
 /**
@@ -9,6 +10,7 @@
  * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
  */
 public class SimpleStopWatch
+    implements StopWatch
 {
     /** Monitor that is notified of process execution state */
     public final Monitor monitor;
@@ -87,13 +89,14 @@
      * 
      * @see org.apache.commons.monitoring.StopWatch#pause()
      */
-    public void pause()
+    public StopWatch pause()
     {
         if ( !paused && !stoped )
         {
             stopedAt = nanotime();
             paused = true;
         }
+        return this;
     }
 
     /**
@@ -101,7 +104,7 @@
      * 
      * @see org.apache.commons.monitoring.StopWatch#resume()
      */
-    public void resume()
+    public StopWatch resume()
     {
         if ( paused && !stoped )
         {
@@ -109,14 +112,16 @@
             paused = false;
             stopedAt = 0;
         }
+        return this;
     }
 
     /**
      * {@inheritDoc}
      * 
+     * @return TODO
      * @see org.apache.commons.monitoring.StopWatch#stop()
      */
-    public void stop()
+    public StopWatch stop()
     {
         if ( !stoped )
         {
@@ -129,6 +134,7 @@
             stoped = true;
             doStop();
         }
+        return this;
     }
 
     protected void doStop()
@@ -141,7 +147,7 @@
      * 
      * @see org.apache.commons.monitoring.StopWatch#stop(boolean)
      */
-    public void stop( boolean canceled )
+    public StopWatch stop( boolean canceled )
     {
         if ( canceled )
         {
@@ -151,6 +157,7 @@
         {
             stop();
         }
+        return this;
     }
 
     /**
@@ -158,13 +165,14 @@
      * 
      * @see org.apache.commons.monitoring.StopWatch#cancel()
      */
-    public void cancel()
+    public StopWatch cancel()
     {
         if ( !stoped )
         {
             stoped = true;
             doCancel();
         }
+        return this;
     }
 
     protected void doCancel()

Modified: commons/sandbox/monitoring/branches/modules/reporting/src/main/java/org/apache/commons/monitoring/reporting/AbstractPeriodicLogger.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/reporting/src/main/java/org/apache/commons/monitoring/reporting/AbstractPeriodicLogger.java?rev=739997&r1=739996&r2=739997&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/reporting/src/main/java/org/apache/commons/monitoring/reporting/AbstractPeriodicLogger.java
(original)
+++ commons/sandbox/monitoring/branches/modules/reporting/src/main/java/org/apache/commons/monitoring/reporting/AbstractPeriodicLogger.java
Mon Feb  2 14:57:19 2009
@@ -49,13 +49,26 @@
      */
     public AbstractPeriodicLogger( int period, Repository.Observable repository )
     {
+        this();
         this.repository = repository;
         this.period = period;
+    }
+
+    public AbstractPeriodicLogger()
+    {
         this.scheduler = Executors.newSingleThreadScheduledExecutor();
     }
 
     public void init()
     {
+        if ( period <= 0 )
+        {
+            throw new IllegalStateException( "A positive period must be set" );
+        }
+        if ( repository == null )
+        {
+            throw new IllegalStateException( "A Repository must be set" );
+        }
         observeRepositoryForPeriod();
         scheduler.scheduleAtFixedRate( new Runnable()
         {
@@ -97,4 +110,14 @@
      * @param observeRepositoryForPeriod
      */
     protected abstract void log( Repository repositoryForPeriod );
+
+    public void setRepository( Repository.Observable repository )
+    {
+        this.repository = repository;
+    }
+
+    public void setPeriod( int period )
+    {
+        this.period = period;
+    }
 }

Modified: commons/sandbox/monitoring/branches/modules/spring/pom.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/spring/pom.xml?rev=739997&r1=739996&r2=739997&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/spring/pom.xml (original)
+++ commons/sandbox/monitoring/branches/modules/spring/pom.xml Mon Feb  2 14:57:19 2009
@@ -29,5 +29,18 @@
   		<artifactId>spring-aop</artifactId>
   		<version>2.5.5</version>
   	</dependency>
+  	<dependency>
+  		<groupId>org.springframework</groupId>
+  		<artifactId>spring-web</artifactId>
+  		<version>2.5.5</version>
+  		<optional>true</optional>
+  	</dependency>
+  	<dependency>
+  		<groupId>javax.servlet</groupId>
+  		<artifactId>servlet-api</artifactId>
+  		<version>2.3</version>
+  		<scope>provided</scope>
+  		<optional>true</optional>
+  	</dependency>
   </dependencies>
 </project>
\ No newline at end of file

Added: commons/sandbox/monitoring/branches/modules/spring/src/main/java/org/apache/commons/monitoring/spring/config/RepositoryFactoryBean.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/spring/src/main/java/org/apache/commons/monitoring/spring/config/RepositoryFactoryBean.java?rev=739997&view=auto
==============================================================================
--- commons/sandbox/monitoring/branches/modules/spring/src/main/java/org/apache/commons/monitoring/spring/config/RepositoryFactoryBean.java
(added)
+++ commons/sandbox/monitoring/branches/modules/spring/src/main/java/org/apache/commons/monitoring/spring/config/RepositoryFactoryBean.java
Mon Feb  2 14:57:19 2009
@@ -0,0 +1,71 @@
+package org.apache.commons.monitoring.spring.config;
+
+import org.apache.commons.monitoring.Repository;
+import org.apache.commons.monitoring.repositories.DefaultRepository;
+import org.springframework.beans.factory.FactoryBean;
+import org.springframework.beans.factory.InitializingBean;
+
+/**
+ * @author ndeloof
+ *
+ */
+public class RepositoryFactoryBean
+    implements FactoryBean, InitializingBean
+{
+    /** The object build by this factoryBean */
+    private Repository repository;
+
+    /** The configured implementation class */
+    private Class<? extends Repository> clazz = DefaultRepository.class;
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.springframework.beans.factory.FactoryBean#getObject()
+     */
+    public Object getObject()
+        throws Exception
+    {
+        return repository;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.springframework.beans.factory.FactoryBean#getObjectType()
+     */
+    public Class<? extends Repository> getObjectType()
+    {
+        return clazz;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.springframework.beans.factory.FactoryBean#isSingleton()
+     */
+    public boolean isSingleton()
+    {
+        return true;
+    }
+
+    /**
+     * @param clazz Repository implementation to use
+     */
+    public void setImplementation( Class<? extends Repository> clazz )
+    {
+        this.clazz = clazz;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
+     */
+    public void afterPropertiesSet()
+        throws Exception
+    {
+        this.repository = clazz.newInstance();
+    }
+
+}
\ No newline at end of file

Added: commons/sandbox/monitoring/branches/modules/spring/src/main/java/org/apache/commons/monitoring/spring/config/WebappRepositoryFactoryBean.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/spring/src/main/java/org/apache/commons/monitoring/spring/config/WebappRepositoryFactoryBean.java?rev=739997&view=auto
==============================================================================
--- commons/sandbox/monitoring/branches/modules/spring/src/main/java/org/apache/commons/monitoring/spring/config/WebappRepositoryFactoryBean.java
(added)
+++ commons/sandbox/monitoring/branches/modules/spring/src/main/java/org/apache/commons/monitoring/spring/config/WebappRepositoryFactoryBean.java
Mon Feb  2 14:57:19 2009
@@ -0,0 +1,61 @@
+/*
+ * 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.commons.monitoring.spring.config;
+
+import javax.servlet.ServletContext;
+
+import org.apache.commons.monitoring.instrumentation.servlet.ServletContextUtil;
+import org.springframework.web.context.ServletContextAware;
+
+/**
+ * Creates monitored proxies for beans that match a pointcut.
+ * 
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class WebappRepositoryFactoryBean extends RepositoryFactoryBean
+    implements ServletContextAware
+{
+    /** The web application context */
+    private ServletContext servletContext;
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.springframework.web.context.ServletContextAware#setServletContext(javax.servlet.ServletContext)
+     */
+    public void setServletContext( ServletContext servletContext )
+    {
+        this.servletContext = servletContext;
+    };
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
+     */
+    public void afterPropertiesSet()
+        throws Exception
+    {
+        super.afterPropertiesSet();
+        if ( servletContext != null )
+        {
+            servletContext.setAttribute( ServletContextUtil.REPOSITORY_KEY, getObject() );
+        }
+    }
+
+}



Mime
View raw message