use of org.apache.tomcat.jdbc.pool.ConnectionPool in project platformlayer by platformlayer.
the class TomcatJdbcPoolMetricsReporter method addMetrics.
@Override
public void addMetrics(MetricTreeObject tree) {
ConnectionPool pool = getPool();
if (pool == null) {
// TODO: Should we handle this properly??
return;
}
MetricTreeObject subtree = tree.getSubtree(key);
// Statistics stats = pool.getStatistics();
// subtree.addInt("hitCount", stats.getCacheHits());
// subtree.addInt("missCount", stats.getCacheMiss());
// subtree.addInt("connectionsRequested", stats.getConnectionsRequested());
// subtree.addInt("statementsCached", stats.getStatementsCached());
// subtree.addInt("statementsExecuted", stats.getStatementsExecuted());
// subtree.addInt("statementsPrepared", stats.getStatementsPrepared());
// subtree.addInt("cumulativeConnectionWaitTime", stats.getCumulativeConnectionWaitTime());
// subtree.addInt("cumulativeStatementExecutionTime", stats.getCumulativeStatementExecutionTime());
// subtree.addInt("cumulativeStatementPrepareTime", stats.getCumulativeStatementPrepareTime());
//
subtree.addInt("activeConnections", pool.getActive());
subtree.addInt("idleConnections", pool.getIdle());
subtree.addInt("waitCount", pool.getWaitCount());
}
use of org.apache.tomcat.jdbc.pool.ConnectionPool in project tomee by apache.
the class TomEEDataSourceCreator method pool.
@Override
public DataSource pool(final String name, final DataSource ds, final Properties properties) {
final PoolConfiguration config = build(TomEEPoolProperties.class, createProperties(name, properties));
config.setDataSource(ds);
final ConnectionPool pool;
try {
pool = new ConnectionPool(config);
} catch (final SQLException e) {
throw new IllegalStateException(e);
}
final TomEEDataSource dataSource = new TomEEDataSource(config, pool, name);
// transfer unset props for correct logging
recipes.put(dataSource, recipes.remove(config));
return dataSource;
}
use of org.apache.tomcat.jdbc.pool.ConnectionPool in project dal by ctripcorp.
the class DefaultDataSourceTerminateTask method closeTomcatDataSource.
private boolean closeTomcatDataSource() {
boolean success = true;
LOGGER.info(String.format("Error retry times for datasource %s:%s", name, retryTimes));
int abandonedTimeout = getAbandonedTimeout();
LOGGER.info(String.format("Abandoned timeout for datasource %s:%s", name, abandonedTimeout));
int elapsedSeconds = getElapsedSeconds();
LOGGER.info(String.format("Elapsed seconds for datasource %s:%s", name, elapsedSeconds));
org.apache.tomcat.jdbc.pool.DataSource ds = (org.apache.tomcat.jdbc.pool.DataSource) dataSource;
if (retryTimes > MAX_RETRY_TIMES) {
LOGGER.info(String.format("Force closing datasource %s,retry times:%s,max retry times:%s.", name, retryTimes, MAX_RETRY_TIMES));
ds.close(true);
isForceClosing = true;
return success;
} else if (elapsedSeconds >= abandonedTimeout) {
LOGGER.info(String.format("Force closing datasource %s,elapsed seconds:%s,abandoned timeout:%s.", name, elapsedSeconds, abandonedTimeout));
ds.close(true);
isForceClosing = true;
return success;
}
ConnectionPool pool = ds.getPool();
if (pool == null)
return success;
int idle = pool.getIdle();
if (idle > 0) {
pool.purge();
LOGGER.info(String.format("Idle connections of datasource %s have been closed.", name));
}
int active = pool.getActive();
if (active == 0) {
ds.close();
LOGGER.info(String.format("Active connections of datasource %s is zero, datasource has been closed.", name));
} else if (active > 0) {
LOGGER.info(String.format("Active connections of datasource %s is %s.", name, active));
success = false;
}
return success;
}
Aggregations