|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectde.is24.util.monitoring.database.MonitoringDataSource
public class MonitoringDataSource
The MonitoringDataSource wraps a given DataSource
and the subsequently returned Connections. The combination of
MonitoringDataSource and MonitoringDataSource.MonitoringConnection monitor
getConnection()) andgetConnection(String, String)
Additionally, the returned Statements are wrapped and attempt to log
the SQL being executed in case an exception is thrown.
getConnection(),
getConnection(String, String)| Nested Class Summary | |
|---|---|
private class |
MonitoringDataSource.MonitoringConnection
The MonitoringConnection is integral part of the MonitoringDataSource. |
(package private) static class |
MonitoringDataSource.SqlExceptionPredicate
|
private static class |
MonitoringDataSource.SqlLoggingInvocationHandler
|
| Field Summary | |
|---|---|
private AtomicInteger |
currentConnections
This field is a helper to determine the correct for maxConnections. |
private static org.apache.log4j.Logger |
LOGGER
|
(package private) Set<com.google.common.base.Predicate<SQLException>> |
loggingFilters
These predicates indicate if a the executed SQL should be logged at INFO level. |
private AtomicInteger |
maxConnections
This field is used to trace the maximum number of connections being use in parallel. |
private String |
monitorBaseName
The base name for all monitor values. |
private DataSource |
original
The wrapped DataSource. |
| Constructor Summary | |
|---|---|
MonitoringDataSource(DataSource dataSource)
Creates a new instance of MonitoringDataSource
without a specific monitoring base name. |
|
MonitoringDataSource(DataSource dataSource,
String monitorBaseName)
Creates a new instance of MonitoringDataSource. |
|
| Method Summary | ||
|---|---|---|
void |
addExceptionLogFilter(com.google.common.base.Predicate<SQLException> predicate)
|
|
private void |
configureSqlExceptionPredicates(String configuration)
|
|
private
|
delegateViaReflectionDuringMigrationFromJava6ToJava7(String methodName,
Object target,
Class<T> expectedReturnType,
Object... args)
|
|
private void |
doConnectionMonitoring(long startingInstant,
String monitorSuffix)
Handles the monitoring for retrieving connections and adapts the max connection counter if appropriate. |
|
Connection |
getConnection()
Delegates the call to the wrapped data source, wraps the returned connection and counts the connections returned. |
|
private Connection |
getConnection(Callable<Connection> callable,
String monitorSuffix)
Executes the specified Callable to fetch a connection. |
|
Connection |
getConnection(String username,
String password)
Delegates the call to the wrapped data source, wraps the returned connection and counts the connections returned. |
|
int |
getLoginTimeout()
|
|
PrintWriter |
getLogWriter()
|
|
Logger |
getParentLogger()
|
|
boolean |
isWrapperFor(Class<?> iface)
|
|
private void |
monitorFailedConnectionAttempt()
Increases the error count for the getConnection method. |
|
void |
setExceptionLogFilters(String configuration)
|
|
void |
setLoginTimeout(int seconds)
|
|
void |
setLogWriter(PrintWriter out)
|
|
String |
toString()
Returns a String representation of this object. |
|
|
unwrap(Class<T> iface)
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private static final org.apache.log4j.Logger LOGGER
private final DataSource original
DataSource.
private final String monitorBaseName
private final AtomicInteger maxConnections
private final AtomicInteger currentConnections
maxConnections.
final Set<com.google.common.base.Predicate<SQLException>> loggingFilters
| Constructor Detail |
|---|
public MonitoringDataSource(DataSource dataSource,
String monitorBaseName)
MonitoringDataSource.
dataSource - the DataSource to wrapmonitorBaseName - the monitor name to insert such that "de.is24.common.database.MonitoringDataSource.monitorBaseName.monitoringKey" is reported
IllegalArgumentException - if dataSource is nullpublic MonitoringDataSource(DataSource dataSource)
MonitoringDataSource
without a specific monitoring base name.
dataSource - the DataSource to wrap
IllegalArgumentException - if dataSource is null| Method Detail |
|---|
public void addExceptionLogFilter(com.google.common.base.Predicate<SQLException> predicate)
public void setExceptionLogFilters(String configuration)
private void configureSqlExceptionPredicates(String configuration)
private void doConnectionMonitoring(long startingInstant,
String monitorSuffix)
startingInstant - the instant a database connection was requestedmonitorSuffix - the suffix for the monitor name to increaseprivate void monitorFailedConnectionAttempt()
private Connection getConnection(Callable<Connection> callable,
String monitorSuffix)
throws SQLException
Callable to fetch a connection.
Monitors occurring exceptions/errors.
callable - the Callable that actually fetches a ConnectionmonitorSuffix - the suffix for the monitor name to increase (forwarded to doConnectionMonitoring(long, String))
Connection
SQLException - if fetching a Connection fails
RuntimeExceptionpublic String toString()
toString in class ObjectString representing this instance
public Connection getConnection()
throws SQLException
Delegates the call to the wrapped data source, wraps the returned connection and counts the connections returned.
getConnection in interface DataSourceConnection
SQLException - as a result of the delegation
public Connection getConnection(String username,
String password)
throws SQLException
Delegates the call to the wrapped data source, wraps the returned connection and counts the connections returned.
getConnection in interface DataSourceusername - the name of the database user on whose behalf the connection isbeing madepassword - the user's password
Connection
SQLException - as a result of the delegation
public PrintWriter getLogWriter()
throws SQLException
getLogWriter in interface CommonDataSourceSQLException
public int getLoginTimeout()
throws SQLException
getLoginTimeout in interface CommonDataSourceSQLException
public Logger getParentLogger()
throws SQLFeatureNotSupportedException
SQLFeatureNotSupportedException
public void setLogWriter(PrintWriter out)
throws SQLException
setLogWriter in interface CommonDataSourceSQLException
public void setLoginTimeout(int seconds)
throws SQLException
setLoginTimeout in interface CommonDataSourceSQLException
public boolean isWrapperFor(Class<?> iface)
throws SQLException
isWrapperFor in interface WrapperSQLException
public <T> T unwrap(Class<T> iface)
throws SQLException
unwrap in interface WrapperSQLException
private <T> T delegateViaReflectionDuringMigrationFromJava6ToJava7(String methodName,
Object target,
Class<T> expectedReturnType,
Object... args)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||