You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ni...@apache.org on 2009/04/17 11:38:43 UTC
svn commit: r765922 - in /commons/sandbox/monitoring/branches/modules: ./
instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/jdbc/
jdbc/src/main/java/org/apache/commons/monitoring/jdbc/
Author: nicolas
Date: Fri Apr 17 09:38:42 2009
New Revision: 765922
URL: http://svn.apache.org/viewvc?rev=765922&view=rev
Log:
jdbc monitoring
Added:
commons/sandbox/monitoring/branches/modules/jdbc/src/main/java/org/apache/commons/monitoring/jdbc/AbstractMonitoredDataSource.java
commons/sandbox/monitoring/branches/modules/jdbc/src/main/java/org/apache/commons/monitoring/jdbc/ConnectionClosedCallBack.java
commons/sandbox/monitoring/branches/modules/jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredDataSourceHandler.java
Removed:
commons/sandbox/monitoring/branches/modules/instrumentation/src/main/java/org/apache/commons/monitoring/instrumentation/jdbc/
Modified:
commons/sandbox/monitoring/branches/modules/jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredConnection.java
commons/sandbox/monitoring/branches/modules/jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredConnectionHandler.java
commons/sandbox/monitoring/branches/modules/jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredDataSource.java
commons/sandbox/monitoring/branches/modules/pom.xml
Added: commons/sandbox/monitoring/branches/modules/jdbc/src/main/java/org/apache/commons/monitoring/jdbc/AbstractMonitoredDataSource.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/jdbc/src/main/java/org/apache/commons/monitoring/jdbc/AbstractMonitoredDataSource.java?rev=765922&view=auto
==============================================================================
--- commons/sandbox/monitoring/branches/modules/jdbc/src/main/java/org/apache/commons/monitoring/jdbc/AbstractMonitoredDataSource.java (added)
+++ commons/sandbox/monitoring/branches/modules/jdbc/src/main/java/org/apache/commons/monitoring/jdbc/AbstractMonitoredDataSource.java Fri Apr 17 09:38:42 2009
@@ -0,0 +1,122 @@
+package org.apache.commons.monitoring.jdbc;
+
+import java.sql.Connection;
+
+import javax.sql.DataSource;
+
+import org.apache.commons.monitoring.Monitor;
+import org.apache.commons.monitoring.Repository;
+import org.apache.commons.monitoring.Role;
+import org.apache.commons.monitoring.StopWatch;
+import org.apache.commons.monitoring.Unit;
+import org.apache.commons.monitoring.Metric.Type;
+import org.apache.commons.monitoring.stopwatches.DefaultStopWatch;
+
+/**
+ * @author ndeloof
+ *
+ */
+public class AbstractMonitoredDataSource
+{
+ private final static Role OPEN_CONECTIONS =
+ new Role( "open connections", Unit.UNARY, Type.GAUGE );
+
+ private final static Role CONECTION_DURATION =
+ new Role( "connection duration", Unit.Time.NANOSECOND, Type.COUNTER );
+
+ /** delegate DataSource */
+ private DataSource dataSource;
+
+ /** dataSource name */
+ private String dataSourceName = DataSource.class.getName();
+
+ private Repository repository;
+
+ private Monitor monitor;
+
+ /**
+ * Constructor
+ * <p>
+ * Used to configure a dataSource via setter-based dependency injection
+ */
+ public AbstractMonitoredDataSource()
+ {
+ super();
+ }
+
+ /**
+ * Constructor
+ *
+ * @param dataSource the datasource to monitor
+ * @param repository the Monitoring repository
+ */
+ public AbstractMonitoredDataSource( DataSource dataSource, Repository repository )
+ {
+ this.setDataSource( dataSource );
+ this.repository = repository;
+ }
+
+ /**
+ * @param dataSource the dataSource to set
+ */
+ public void setDataSource( DataSource dataSource )
+ {
+ this.dataSource = dataSource;
+ }
+
+ /**
+ * @param dataSourceName the dataSourceName to set
+ */
+ public void setDataSourceName( String dataSourceName )
+ {
+ this.dataSourceName = dataSourceName;
+ }
+
+ /**
+ * required
+ *
+ * @param repository
+ */
+ public void setRepository( Repository repository )
+ {
+ this.repository = repository;
+ }
+
+ /**
+ * @param monitor the monitor to set
+ */
+ public void setMonitor( Monitor monitor )
+ {
+ this.monitor = monitor;
+ }
+
+ public void init()
+ {
+ if ( monitor == null )
+ {
+ monitor = repository.getMonitor( dataSourceName, "jdbc" );
+ }
+ }
+
+ protected Connection monitor( Connection connection )
+ {
+ // Computes the number of open connections and the connection duration
+ final StopWatch stopWatch = new DefaultStopWatch( monitor, OPEN_CONECTIONS, CONECTION_DURATION );
+ return new MonitoredConnection( connection, repository, new ConnectionClosedCallBack()
+ {
+ public void onConnectionClosed()
+ {
+ stopWatch.stop();
+ }
+ } );
+ }
+
+ /**
+ * @return the dataSource
+ */
+ protected DataSource getDataSource()
+ {
+ return dataSource;
+ }
+
+}
\ No newline at end of file
Added: commons/sandbox/monitoring/branches/modules/jdbc/src/main/java/org/apache/commons/monitoring/jdbc/ConnectionClosedCallBack.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/jdbc/src/main/java/org/apache/commons/monitoring/jdbc/ConnectionClosedCallBack.java?rev=765922&view=auto
==============================================================================
--- commons/sandbox/monitoring/branches/modules/jdbc/src/main/java/org/apache/commons/monitoring/jdbc/ConnectionClosedCallBack.java (added)
+++ commons/sandbox/monitoring/branches/modules/jdbc/src/main/java/org/apache/commons/monitoring/jdbc/ConnectionClosedCallBack.java Fri Apr 17 09:38:42 2009
@@ -0,0 +1,26 @@
+/*
+ * 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.jdbc;
+
+/**
+ * CallBack on connection beeing closed
+ */
+public interface ConnectionClosedCallBack
+{
+ void onConnectionClosed();
+}
\ No newline at end of file
Modified: commons/sandbox/monitoring/branches/modules/jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredConnection.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredConnection.java?rev=765922&r1=765921&r2=765922&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredConnection.java (original)
+++ commons/sandbox/monitoring/branches/modules/jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredConnection.java Fri Apr 17 09:38:42 2009
@@ -45,14 +45,6 @@
implements Connection
{
- /**
- * CallBack on connection beeing closed
- */
- public interface ConnectionClosedCallBack
- {
- void onConnectionClosed();
- }
-
/** target connection */
private Connection connection;
Modified: commons/sandbox/monitoring/branches/modules/jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredConnectionHandler.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredConnectionHandler.java?rev=765922&r1=765921&r2=765922&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredConnectionHandler.java (original)
+++ commons/sandbox/monitoring/branches/modules/jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredConnectionHandler.java Fri Apr 17 09:38:42 2009
@@ -1,3 +1,20 @@
+/*
+ * 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.jdbc;
import java.lang.reflect.InvocationHandler;
@@ -9,8 +26,6 @@
import java.sql.Statement;
import org.apache.commons.monitoring.Repository;
-import org.apache.commons.monitoring.jdbc.MonitoredConnection;
-import org.apache.commons.monitoring.jdbc.MonitoredConnection.ConnectionClosedCallBack;
/**
* @author ndeloof
Modified: commons/sandbox/monitoring/branches/modules/jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredDataSource.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredDataSource.java?rev=765922&r1=765921&r2=765922&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredDataSource.java (original)
+++ commons/sandbox/monitoring/branches/modules/jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredDataSource.java Fri Apr 17 09:38:42 2009
@@ -17,103 +17,38 @@
package org.apache.commons.monitoring.jdbc;
+
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
-import org.apache.commons.monitoring.Monitor;
import org.apache.commons.monitoring.Repository;
-import org.apache.commons.monitoring.Role;
-import org.apache.commons.monitoring.StopWatch;
-import org.apache.commons.monitoring.Unit;
-import org.apache.commons.monitoring.Metric.Type;
-import org.apache.commons.monitoring.stopwatches.DefaultStopWatch;
+
/**
* @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
*/
-public class MonitoredDataSource
+public class MonitoredDataSource extends AbstractMonitoredDataSource
implements DataSource
{
-
- private final static Role OPEN_CONECTIONS = new Role( "open connections", Unit.UNARY, Type.GAUGE );
-
- private final static Role CONECTION_DURATION = new Role( "connection duration", Unit.Time.NANOSECOND, Type.COUNTER );
-
- /** delegate DataSource */
- private DataSource dataSource;
-
- /** dataSource name */
- private String dataSourceName = DataSource.class.getName();
-
- private Repository repository;
-
- private Monitor monitor;
-
/**
* Constructor
*
* @param dataSource the datasource to monitor
*/
- public MonitoredDataSource( DataSource dataSource )
+ public MonitoredDataSource( DataSource dataSource, Repository repository )
{
- super();
- this.dataSource = dataSource;
+ super( dataSource, repository );
}
- /**
- *
- */
public MonitoredDataSource()
{
super();
}
/**
- * @param dataSource the dataSource to set
- */
- public void setDataSource( DataSource dataSource )
- {
- this.dataSource = dataSource;
- }
-
- /**
- * @param dataSourceName the dataSourceName to set
- */
- public void setDataSourceName( String dataSourceName )
- {
- this.dataSourceName = dataSourceName;
- }
-
- /**
- * required
- *
- * @param repository
- */
- public void setRepository( Repository repository )
- {
- this.repository = repository;
- }
-
- /**
- * @param monitor the monitor to set
- */
- public void setMonitor( Monitor monitor )
- {
- this.monitor = monitor;
- }
-
- public void init()
- {
- if ( monitor == null )
- {
- monitor = repository.getMonitor( dataSourceName, "jdbc" );
- }
- }
-
- /**
* {@inheritDoc}
*
* @see javax.sql.DataSource#getConnection()
@@ -121,7 +56,7 @@
public Connection getConnection()
throws SQLException
{
- Connection connection = dataSource.getConnection();
+ Connection connection = getDataSource().getConnection();
return monitor( connection );
}
@@ -133,48 +68,32 @@
public Connection getConnection( String username, String password )
throws SQLException
{
- Connection connection = dataSource.getConnection( username, password );
+ Connection connection = getDataSource().getConnection( username, password );
return monitor( connection );
}
- private Connection monitor( Connection connection )
- {
- // Computes the number of open connections and the connection duration
- final StopWatch stopWatch = new DefaultStopWatch( monitor, OPEN_CONECTIONS, CONECTION_DURATION );
- return new MonitoredConnection( connection, repository, new MonitoredConnection.ConnectionClosedCallBack()
- {
- public void onConnectionClosed()
- {
- stopWatch.stop();
- }
- } );
- }
-
-
- // --- delegate methods ---
-
public int getLoginTimeout()
throws SQLException
{
- return dataSource.getLoginTimeout();
+ return getDataSource().getLoginTimeout();
}
public PrintWriter getLogWriter()
throws SQLException
{
- return dataSource.getLogWriter();
+ return getDataSource().getLogWriter();
}
public void setLoginTimeout( int seconds )
throws SQLException
{
- dataSource.setLoginTimeout( seconds );
+ getDataSource().setLoginTimeout( seconds );
}
public void setLogWriter( PrintWriter out )
throws SQLException
{
- dataSource.setLogWriter( out );
+ getDataSource().setLogWriter( out );
}
// --- jdbc4 ----
@@ -182,13 +101,13 @@
public boolean isWrapperFor( Class<?> iface )
throws SQLException
{
- return dataSource.isWrapperFor( iface );
+ return getDataSource().isWrapperFor( iface );
}
public <T> T unwrap( Class<T> iface )
throws SQLException
{
- return dataSource.unwrap( iface );
+ return getDataSource().unwrap( iface );
}
}
Added: commons/sandbox/monitoring/branches/modules/jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredDataSourceHandler.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredDataSourceHandler.java?rev=765922&view=auto
==============================================================================
--- commons/sandbox/monitoring/branches/modules/jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredDataSourceHandler.java (added)
+++ commons/sandbox/monitoring/branches/modules/jdbc/src/main/java/org/apache/commons/monitoring/jdbc/MonitoredDataSourceHandler.java Fri Apr 17 09:38:42 2009
@@ -0,0 +1,62 @@
+/*
+ * 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.jdbc;
+
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.sql.Connection;
+
+import javax.sql.DataSource;
+
+import org.apache.commons.monitoring.Repository;
+
+/**
+ * @author ndeloof
+ */
+public class MonitoredDataSourceHandler
+ extends AbstractMonitoredDataSource
+ implements InvocationHandler
+{
+ public MonitoredDataSourceHandler( DataSource dataSource, Repository repository )
+ {
+ super( dataSource, repository );
+ }
+
+ public MonitoredDataSourceHandler()
+ {
+ super();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
+ */
+ public Object invoke( Object proxy, Method method, Object[] args )
+ throws Throwable
+ {
+ String name = method.getName();
+ if ( name.equals( "getConnection" ) )
+ {
+ Connection connection = (Connection) method.invoke( getDataSource(), args );
+ return monitor( connection );
+ }
+ return method.invoke( getDataSource(), args );
+ }
+}
Modified: commons/sandbox/monitoring/branches/modules/pom.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/branches/modules/pom.xml?rev=765922&r1=765921&r2=765922&view=diff
==============================================================================
--- commons/sandbox/monitoring/branches/modules/pom.xml (original)
+++ commons/sandbox/monitoring/branches/modules/pom.xml Fri Apr 17 09:38:42 2009
@@ -40,6 +40,7 @@
<module>instrumentation</module>
<module>spring</module>
<module>reporting</module>
+ <module>jdbc</module>
</modules>
<developers>
@@ -74,6 +75,13 @@
</executions>
</plugin>
</plugins>
+ <extensions>
+ <extension>
+ <groupId>org.apache.maven.wagon</groupId>
+ <artifactId>wagon-webdav</artifactId>
+ <version>1.0-beta-2</version>
+ </extension>
+ </extensions>
</build>
<distributionManagement>
@@ -104,4 +112,16 @@
</plugins>
</reporting>
+ <profiles>
+ <profile>
+ <id>nicolas</id>
+ <distributionManagement>
+ <snapshotRepository>
+ <id>archiva</id>
+ <url>dav:http://sai1rennes:8888/archiva/repository/snapshots</url>
+ </snapshotRepository>
+ </distributionManagement>
+ </profile>
+ </profiles>
+
</project>