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

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

Introduction

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

Prototype

public synchronized int getMaxActive() 

Source Link

Document

Returns the maximum number of active connections that can be allocated at the same time.

Usage

From source file:com.hangum.tadpole.engine.manager.TadpoleSQLManager.java

/**
 * dbcp pool info/*  www.  ja  v a2 s. c o  m*/
 * 
 * @return
 */
public static List<DBCPInfoDAO> getDBCPInfo() {
    List<DBCPInfoDAO> listDbcpInfo = new ArrayList<DBCPInfoDAO>();

    Set<String> setKeys = getDbManager().keySet();
    for (String stKey : setKeys) {

        SqlMapClient sqlMap = dbManager.get(stKey);
        DataSource ds = sqlMap.getDataSource();
        BasicDataSource bds = (BasicDataSource) ds;

        String[] strArryKey = StringUtils.splitByWholeSeparator(stKey, PublicTadpoleDefine.DELIMITER);
        if (!DBDefine.TADPOLE_SYSTEM_DEFAULT.getDBToString().equals(strArryKey[1])) {

            DBCPInfoDAO dao = new DBCPInfoDAO();
            dao.setDbSeq(Integer.parseInt(strArryKey[0]));
            dao.setDbType(strArryKey[1]);
            dao.setDisplayName(strArryKey[2]);

            dao.setNumberActive(bds.getNumActive());
            dao.setMaxActive(bds.getMaxActive());
            dao.setNumberIdle(bds.getNumIdle());
            dao.setMaxWait(bds.getMaxWait());

            listDbcpInfo.add(dao);
        }
    }

    return listDbcpInfo;
}

From source file:jeeves.server.resources.Stats.java

public Stats(final ServiceContext context) {
    DataSource source = context.getBean(DataSource.class);
    if (source instanceof BasicDataSource) {
        BasicDataSource basicDataSource = (BasicDataSource) source;
        numActive = basicDataSource.getNumActive();
        numIdle = basicDataSource.getNumIdle();
        maxActive = basicDataSource.getMaxActive();
    } else {/*from w  ww.j  a v  a2  s .  c o  m*/
        maxActive = numActive = numIdle = -1;
    }
    resourceSpecificStats = new HashMap<String, String>();
}

From source file:com.googlecode.psiprobe.beans.DbcpDatasourceAccessor.java

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. j a v  a 2  s . com
    return dataSourceInfo;
}

From source file:net.risesoft.soa.asf.web.controller.SystemController.java

private List<SysInfo> getDBInfo() {
    List list = new ArrayList();
    String group = "4. ??";
    try {/*from ww  w . j a  v a  2s.c om*/
        Connection conn = this.basicDataSource.getConnection();
        try {
            DatabaseMetaData dbmd = conn.getMetaData();
            list.add(new SysInfo("DatabaseProductName", dbmd.getDatabaseProductName(), group));
            list.add(new SysInfo("DatabaseProductVersion", dbmd.getDatabaseProductVersion(), group));
            list.add(new SysInfo("DatabaseMajorVersion", Integer.valueOf(dbmd.getDatabaseMajorVersion()),
                    group));
            list.add(new SysInfo("DatabaseMinorVersion", Integer.valueOf(dbmd.getDatabaseMinorVersion()),
                    group));
            list.add(new SysInfo("DriverName", dbmd.getDriverName(), group));
            list.add(new SysInfo("DriverVersion", dbmd.getDriverVersion(), group));
            list.add(new SysInfo("DriverMajorVersion", Integer.valueOf(dbmd.getDriverMajorVersion()), group));
            list.add(new SysInfo("DriverMinorVersion", Integer.valueOf(dbmd.getDriverMinorVersion()), group));
        } finally {
            conn.close();
        }
        group = "5. ?";
        BasicDataSource bds = this.basicDataSource;
        list.add(new SysInfo("InitialSize", Integer.valueOf(bds.getInitialSize()), group));
        list.add(new SysInfo("MaxActive", Integer.valueOf(bds.getMaxActive()), group));
        list.add(new SysInfo("MaxIdle", Integer.valueOf(bds.getMaxIdle()), group));
        list.add(new SysInfo("MinIdle", Integer.valueOf(bds.getMinIdle()), group));
        list.add(new SysInfo("MaxWait", Long.valueOf(bds.getMaxWait()), group));
        list.add(new SysInfo("NumActive", Integer.valueOf(bds.getNumActive()), group));
        list.add(new SysInfo("NumIdle", Integer.valueOf(bds.getNumIdle()), group));
        list.add(new SysInfo("DriverClass", bds.getDriverClassName(), group));
        list.add(new SysInfo("URL", bds.getUrl(), group));
        list.add(new SysInfo("Username", bds.getUsername(), group));
        list.add(new SysInfo("Password", "******", group));
    } catch (Exception ex) {
        log.warn("???: " + ex.getMessage(), ex);
    }
    return list;
}

From source file:de.iteratec.iteraplan.persistence.RoutingDataSource.java

/**
 * Write current utilization values for the passed data source source to the log (on DEBUG level). Log entries are written in intervals of at least
 * five seconds. This is intended so that the log is not flooded.
 * //  w w  w  .j  a va2  s. c  om
 * @param ds
 *          The DataSource to inspect. Right now, only {@link BasicDataSource} is supported, other implementations will be silently skipped.
 * @param dbname
 *          The name of the DataSource, as it is registered in the RoutingDataSource.
 */
@SuppressWarnings("boxing")
protected void logPoolUtilization(DataSource ds, String dbname) {
    if (!(ds instanceof BasicDataSource)) {
        // cannot retrieve values from other types, so skip
        return;
    }

    long currentTime = System.currentTimeMillis();
    // log at most every five seconds
    if (currentTime - previousLoggingTimestamp < 5000) {
        return;
    }

    previousLoggingTimestamp = currentTime;
    BasicDataSource bds = (BasicDataSource) ds;
    int bdsNumActive = bds.getNumActive();
    int bdsMaxActive = bds.getMaxActive();
    int bdsNumIdle = bds.getNumIdle();

    LOGGER.debug("DS {0}, {1} active, {2} idle, {3} max total", dbname, bdsNumActive, bdsNumIdle, bdsMaxActive);
}

From source file:fr.cnes.sitools.datasource.jdbc.DataSourceMonitoringResource.java

/**
 * Trace informations for a sitoolsDataSource
 * /*from  ww w .  j a v  a2s  .  c om*/
 * @param sitoolsDataSource
 *          SitoolsDataSource
 * @param messages
 *          ArrayList<String> messages
 */
private void traceStatus(SitoolsSQLDataSource sitoolsDataSource, ArrayList<String> messages) {
    DataSource concreteDs = sitoolsDataSource.getDs();
    if ((concreteDs != null) && (concreteDs instanceof BasicDataSource)) {
        BasicDataSource bds = (BasicDataSource) concreteDs;
        messages.add("--------------------------------------------------");
        messages.add("Url: " + bds.getUrl());
        messages.add("User: " + bds.getUsername());
        messages.add("DefaultCatalog: " + bds.getDefaultCatalog());
        messages.add("InitialSize: " + bds.getInitialSize());
        messages.add("NumActive: " + bds.getNumActive());
        messages.add("MaxActive: " + bds.getMaxActive());
        messages.add("MaxIdl: " + bds.getMaxIdle());
        messages.add("MinIdl: " + bds.getMinIdle());
        messages.add("NumIdle: " + bds.getNumIdle());
    }

}

From source file:net.testdriven.psiprobe.beans.DbcpDatasourceAccessor.java

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);
    }/*from ww w.  j  av  a  2  s  .co m*/
    return dataSourceInfo;
}

From source file:onlinefrontlines.admin.web.ServerInfoAction.java

/**
 * Query data source status/*from  w ww . ja  va2s .co m*/
 * 
 * @param dataSourceName Name of the data source
 */
private String getDataSourceStatus(String dataSourceName) {
    DataSource dataSource = (DataSource) DbConnectionPool.getInstance().getDataSources().get(dataSourceName);
    if (dataSource.getClass().getName().equals("org.apache.commons.dbcp.BasicDataSource")
            && dataSource instanceof org.apache.commons.dbcp.BasicDataSource) {
        org.apache.commons.dbcp.BasicDataSource s = (org.apache.commons.dbcp.BasicDataSource) dataSource;
        return "Busy: " + s.getNumActive() + " (" + (int) (s.getNumActive() * 100 / s.getMaxActive())
                + "%), Connections: " + (s.getNumIdle() + s.getNumActive()) + ", Max: " + s.getMaxActive();
    } else if (dataSource.getClass().getName().equals("org.apache.tomcat.dbcp.dbcp.BasicDataSource")
            && dataSource instanceof org.apache.tomcat.dbcp.dbcp.BasicDataSource) {
        org.apache.tomcat.dbcp.dbcp.BasicDataSource s = (org.apache.tomcat.dbcp.dbcp.BasicDataSource) dataSource;
        return "Busy: " + s.getNumActive() + " (" + (int) (s.getNumActive() * 100 / s.getMaxActive())
                + "%), Connections: " + (s.getNumIdle() + s.getNumActive()) + ", Max: " + s.getMaxActive();
    } else {
        return "Unknown datasource: " + dataSource.getClass().getName();
    }
}

From source file:org.alfresco.repo.tenant.TenantBasicDataSource.java

public TenantBasicDataSource(BasicDataSource bds, String tenantUrl, int tenantMaxActive) throws SQLException {
    // tenant-specific
    this.setUrl(tenantUrl);
    this.setMaxActive(tenantMaxActive == -1 ? bds.getMaxActive() : tenantMaxActive);

    // defaults/overrides - see also 'baseDefaultDataSource' (core-services-context.xml + repository.properties)

    this.setDriverClassName(bds.getDriverClassName());
    this.setUsername(bds.getUsername());
    this.setPassword(bds.getPassword());

    this.setInitialSize(bds.getInitialSize());
    this.setMinIdle(bds.getMinIdle());
    this.setMaxIdle(bds.getMaxIdle());
    this.setDefaultAutoCommit(bds.getDefaultAutoCommit());
    this.setDefaultTransactionIsolation(bds.getDefaultTransactionIsolation());
    this.setMaxWait(bds.getMaxWait());
    this.setValidationQuery(bds.getValidationQuery());
    this.setTimeBetweenEvictionRunsMillis(bds.getTimeBetweenEvictionRunsMillis());
    this.setMinEvictableIdleTimeMillis(bds.getMinEvictableIdleTimeMillis());
    this.setNumTestsPerEvictionRun(bds.getNumTestsPerEvictionRun());
    this.setTestOnBorrow(bds.getTestOnBorrow());
    this.setTestOnReturn(bds.getTestOnReturn());
    this.setTestWhileIdle(bds.getTestWhileIdle());
    this.setRemoveAbandoned(bds.getRemoveAbandoned());
    this.setRemoveAbandonedTimeout(bds.getRemoveAbandonedTimeout());
    this.setPoolPreparedStatements(bds.isPoolPreparedStatements());
    this.setMaxOpenPreparedStatements(bds.getMaxOpenPreparedStatements());
    this.setLogAbandoned(bds.getLogAbandoned());
}

From source file:org.apache.cayenne.configuration.server.DBCPDataSourceFactoryTest.java

@Test
public void testGetDataSource() throws Exception {

    String baseUrl = getClass().getPackage().getName().replace('.', '/');
    URL url = getClass().getClassLoader().getResource(baseUrl + "/");
    assertNotNull(url);/*  w w  w.j  a v a2  s.  c o  m*/

    DataNodeDescriptor nodeDescriptor = new DataNodeDescriptor();
    nodeDescriptor.setConfigurationSource(new URLResource(url));
    nodeDescriptor.setParameters("testDBCP.properties");

    DBCPDataSourceFactory factory = new DBCPDataSourceFactory();
    DataSource dataSource = factory.getDataSource(nodeDescriptor);
    assertNotNull(dataSource);

    assertTrue(dataSource instanceof BasicDataSource);
    BasicDataSource basicDataSource = (BasicDataSource) dataSource;
    assertEquals("com.example.jdbc.Driver", basicDataSource.getDriverClassName());
    assertEquals("jdbc:somedb://localhost/cayenne", basicDataSource.getUrl());
    assertEquals("john", basicDataSource.getUsername());
    assertEquals("secret", basicDataSource.getPassword());
    assertEquals(20, basicDataSource.getMaxActive());
    assertEquals(5, basicDataSource.getMinIdle());
    assertEquals(8, basicDataSource.getMaxIdle());
    assertEquals(10000, basicDataSource.getMaxWait());
    assertEquals("select 1 from xyz;", basicDataSource.getValidationQuery());
}