Example usage for org.apache.commons.dbcp BasicDataSource getNumActive

List of usage examples for org.apache.commons.dbcp BasicDataSource getNumActive

Introduction

In this page you can find the example usage for org.apache.commons.dbcp BasicDataSource getNumActive.

Prototype

public synchronized int getNumActive() 

Source Link

Document

[Read Only] The current number of active connections that have been allocated from this data source.

Usage

From source file:org.gvsig.fmap.dal.store.jdbc.JDBCResource.java

private void debugPoolStatus(String src) {
    if (logger.isDebugEnabled() && dataSource instanceof BasicDataSource) {
        BasicDataSource ds = (BasicDataSource) dataSource;
        logger.debug(src + "  actives:" + ds.getNumActive() + "(" + ds.getMaxActive() + ") idle:"
                + ds.getNumIdle() + "(" + ds.getMaxIdle() + ")");
    }/*from w w w . java  2 s  . c o  m*/

}

From source file:org.kuali.rice.web.health.DatabaseConnectionPoolMetricSet.java

private void installDBCPMetrics(final BasicDataSource dataSource, Map<String, Metric> metrics) {
    metrics.put(namePrefix + ACTIVE, new Gauge<Integer>() {
        @Override/*w  w  w.  j a  v a 2  s  .c o  m*/
        public Integer getValue() {
            return dataSource.getNumActive();
        }
    });
    metrics.put(namePrefix + MIN, new Gauge<Integer>() {
        @Override
        public Integer getValue() {
            return dataSource.getMinIdle();
        }
    });
    metrics.put(namePrefix + MAX, new Gauge<Integer>() {
        @Override
        public Integer getValue() {
            return dataSource.getMaxActive();
        }
    });
    metrics.put(namePrefix + USAGE, new RatioGauge() {
        @Override
        protected Ratio getRatio() {
            return Ratio.of(dataSource.getNumActive(), dataSource.getMaxActive());
        }
    });
}

From source file:org.kuali.rice.web.health.DatabaseConnectionPoolMetricSetTest.java

@Test
public void testGetMetrics_DBCP() throws Exception {
    BasicDataSource dataSource = mock(BasicDataSource.class);
    when(dataSource.getNumActive()).thenReturn(10);
    when(dataSource.getMinIdle()).thenReturn(5);
    when(dataSource.getMaxActive()).thenReturn(20);

    DatabaseConnectionPoolMetricSet metricSet = new DatabaseConnectionPoolMetricSet("dbcp:", dataSource);
    Map<String, Metric> metrics = metricSet.getMetrics();
    assertEquals(10, ((Gauge) metrics.get("dbcp:pool.active")).getValue());
    assertEquals(5, ((Gauge) metrics.get("dbcp:pool.min")).getValue());
    assertEquals(20, ((Gauge) metrics.get("dbcp:pool.max")).getValue());
    assertEquals(0.5, ((Gauge) metrics.get("dbcp:pool.usage")).getValue());
}

From source file:org.openkoala.koala.monitor.support.DbcpDataSourceCollector.java

public synchronized JdbcPoolStatusVo currentPoolStatus() {
    JdbcPoolStatusVo poolStatus = new JdbcPoolStatusVo();
    try {/*from   w ww  .j  a va  2  s  .co m*/
        BasicDataSource realDS = (BasicDataSource) dataSoure;

        poolStatus.setDriverName(realDS.getDriverClassName());
        //         poolStatus.setStartTime();
        poolStatus.setProvider(dataSoure.getClass().getName());
        poolStatus.setInitConnectionCount(realDS.getInitialSize());
        poolStatus.setMaxConnectionCount(realDS.getMaxActive());
        poolStatus.setMaxActiveTime(realDS.getMaxWait());

        poolStatus.setMaxOpenStatements(realDS.getMaxOpenPreparedStatements());
        poolStatus.setSnapshotTime(new Date());
        poolStatus.setIdleConnectionCount(realDS.getNumIdle());
        poolStatus.setActiveConnectionCount(realDS.getNumActive());
    } catch (Exception e) {
        poolStatus.setErrorTip("??");
    }

    return poolStatus;
}

From source file:org.sakaiproject.status.StatusServlet.java

protected void reportSakaiDatabaseStatus(HttpServletResponse response) throws Exception {
    PrintWriter pw = response.getWriter();

    BasicDataSource db = (BasicDataSource) ComponentManager.get("javax.sql.DataSource");
    if (db == null) {
        throw new Exception("No data source found.");
    }/*from  ww  w .ja v a2s. c  om*/

    pw.print(db.getNumActive() + "," + db.getNumIdle() + "\n");
}

From source file:psiprobe.beans.DbcpDatasourceAccessor.java

@Override
public DataSourceInfo getInfo(Object resource) throws Exception {
    DataSourceInfo dataSourceInfo = null;
    if (canMap(resource)) {
        BasicDataSource source = (BasicDataSource) resource;
        dataSourceInfo = new DataSourceInfo();
        dataSourceInfo.setBusyConnections(source.getNumActive());
        dataSourceInfo.setEstablishedConnections(source.getNumIdle() + source.getNumActive());
        dataSourceInfo.setMaxConnections(source.getMaxActive());
        dataSourceInfo.setJdbcUrl(source.getUrl());
        dataSourceInfo.setUsername(source.getUsername());
        dataSourceInfo.setResettable(false);
        dataSourceInfo.setType("commons-dbcp");
    }/*from w w w  . ja v  a2  s. c om*/
    return dataSourceInfo;
}

From source file:samples.BasicDataSourceExample.java

public static void printDataSourceStats(DataSource ds) throws SQLException {
    BasicDataSource bds = (BasicDataSource) ds;
    System.out.println("NumActive: " + bds.getNumActive());
    System.out.println("NumIdle: " + bds.getNumIdle());
}