Example usage for org.apache.commons.pool ObjectPool getNumActive

List of usage examples for org.apache.commons.pool ObjectPool getNumActive

Introduction

In this page you can find the example usage for org.apache.commons.pool ObjectPool getNumActive.

Prototype

int getNumActive() throws UnsupportedOperationException;

Source Link

Usage

From source file:org.eclipse.osee.jdbc.internal.PoolFactory.java

public Map<String, String> getPoolStats() {
    Map<String, String> stats = new LinkedHashMap<String, String>();

    PoolingDriver driver = poolingDriver.get();

    stats.put("db.pool.driver", poolConfiguration.getPoolConnectionDriver());

    String poolVersion = String.format("%s.%s", driver.getMajorVersion(), driver.getMinorVersion());
    stats.put("db.pool.version", poolVersion);

    String[] names = driver.getPoolNames();
    int count = 0;
    for (String name : names) {

        try {//from   w  ww. j  a v  a 2  s  .co m
            ObjectPool<?> pool = driver.getConnectionPool(name);
            stats.put(String.format("db.pool.%s.id", count), name);
            stats.put(String.format("db.pool.%s.active", count), String.valueOf(pool.getNumActive()));
            stats.put(String.format("db.pool.%s.idle", count), String.valueOf(pool.getNumIdle()));
        } catch (SQLException ex) {
            // Do Nothing
        } finally {
            count++;
        }
    }
    return stats;
}

From source file:org.infoglue.cms.util.workflow.InfoGlueJDBCPropertySet.java

public void printDriverStats() throws Exception {
    PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");
    ObjectPool connectionPool = driver.getConnectionPool("infoGlueJDBCPropertySet");

    if (logger.isInfoEnabled()) {
        logger.info("NumActive: " + connectionPool.getNumActive());
        logger.info("NumIdle: " + connectionPool.getNumIdle());
    }//from w  w  w  .j av a2  s  . co m
}

From source file:org.jvoicexml.implementation.pool.KeyedResourcePool.java

/**
 * Type safe return of the object to borrow from the pool.
 * @param key the type of the object to borrow from the pool
 * @return borrowed object//from ww  w  .  j a va  2s  .  c  o m
 * @exception NoresourceError
 *            the object could not be borrowed
 */
@SuppressWarnings("unchecked")
public synchronized T borrowObject(final Object key) throws NoresourceError {
    final ObjectPool pool = pools.get(key);
    if (pool == null) {
        throw new NoresourceError("Pool of type '" + key + "' is unknown!");
    }
    T resource;
    try {
        resource = (T) pool.borrowObject();
    } catch (NoSuchElementException e) {
        throw new NoresourceError(e.getMessage(), e);
    } catch (IllegalStateException e) {
        throw new NoresourceError(e.getMessage(), e);
    } catch (Exception e) {
        throw new NoresourceError(e.getMessage(), e);
    }
    LOGGER.info("borrowed object of type '" + key + "' (" + resource.getClass().getCanonicalName() + ")");
    if (LOGGER.isDebugEnabled()) {
        final int active = pool.getNumActive();
        final int idle = pool.getNumIdle();
        LOGGER.debug("pool has now " + active + " active/" + idle + " idle for key '" + key + "' ("
                + resource.getClass().getCanonicalName() + ") after borrow");
    }

    return resource;
}

From source file:org.jvoicexml.implementation.pool.KeyedResourcePool.java

/**
 * Returns a previously borrowed resource to the pool.
 * @param key resource type./* ww w  .  j a v a  2  s .co m*/
 * @param resource resource to return.
 * @throws NoresourceError
 *         Error returning the object to the pool.
 * @since 0.6
 */
public synchronized void returnObject(final String key, final T resource) throws NoresourceError {
    final ObjectPool pool = pools.get(key);
    if (pool == null) {
        throw new NoresourceError("Pool of type '" + key + "' is unknown!");
    }
    try {
        pool.returnObject(resource);
    } catch (Exception e) {
        throw new NoresourceError(e.getMessage(), e);
    }
    LOGGER.info("returned object of type '" + key + "' (" + resource.getClass().getCanonicalName() + ")");

    if (LOGGER.isDebugEnabled()) {
        final int active = pool.getNumActive();
        final int idle = pool.getNumIdle();
        LOGGER.debug("pool has now " + active + " active/" + idle + " idle for key '" + key + "' ("
                + resource.getClass().getCanonicalName() + ") after return");
    }
}

From source file:org.jvoicexml.implementation.pool.KeyedResourcePool.java

/**
 * Retrieves the number of active resources in all pools.
 * @return number of active resources//www  .java2s  . c  o  m
 * @since 0.7.3
 */
public synchronized int getNumActive() {
    int active = 0;
    final Collection<ObjectPool> col = pools.values();
    for (ObjectPool pool : col) {
        active += pool.getNumActive();
    }
    return active;
}

From source file:org.jvoicexml.implementation.pool.KeyedResourcePool.java

/**
 * Retrieves the number of active resources in the pool for the given key.
 * @param key the key// ww  w . ja va 2 s  . c o m
 * @return number of active resources
 * @since 0.7.3
 */
public synchronized int getNumActive(final String key) {
    final ObjectPool pool = pools.get(key);
    return pool.getNumActive();
}

From source file:org.kitodo.data.database.persistence.apache.ConnectionManager.java

/**
 * Print Driver Stats.//from  w  w w .  j a  v  a2s  .  com
 */
public static void printDriverStats() throws Exception {
    ObjectPool connectionPool = ConnectionManager._pool;
    if (logger.isDebugEnabled()) {
        logger.debug("NumActive: " + connectionPool.getNumActive());
        logger.debug("NumIdle: " + connectionPool.getNumIdle());
    }
}

From source file:org.opencms.db.CmsDriverManager.java

/** 
 * Returns the number of active connections managed by a pool.<p> 
 * /* www .j av  a2  s . c o  m*/
 * @param dbPoolUrl the url of a pool 
 * @return the number of active connections 
 * @throws CmsDbException if something goes wrong 
 */
public int getActiveConnections(String dbPoolUrl) throws CmsDbException {

    try {
        for (Iterator<PoolingDriver> i = m_connectionPools.iterator(); i.hasNext();) {
            PoolingDriver d = i.next();
            ObjectPool p = d.getConnectionPool(dbPoolUrl);
            return p.getNumActive();
        }
    } catch (Exception exc) {
        CmsMessageContainer message = Messages.get().container(Messages.ERR_ACCESSING_POOL_1, dbPoolUrl);
        throw new CmsDbException(message, exc);
    }

    CmsMessageContainer message = Messages.get().container(Messages.ERR_UNKNOWN_POOL_URL_1, dbPoolUrl);
    throw new CmsDbException(message);
}

From source file:org.plasma.sdo.jdbc.connect.RDBConnectionManager.java

public static void printDriverStats() throws Exception {
    ObjectPool connectionPool = RDBConnectionManager._pool;
    log.debug("NumActive: " + connectionPool.getNumActive());
    log.debug("NumIdle: " + connectionPool.getNumIdle());
}

From source file:org.wso2.carbon.webapp.authenticator.framework.test.WebappAuthenticatorFrameworkUtilTest.java

@Test
public void testOAuthTokenValidatorStubPool() {
    ObjectPool stubs = null;
    OAuth2TokenValidationServiceStub stub = null;

    try {//from   w w w. j a v  a 2  s.c o m
        stubs = new GenericObjectPool(new OAuthTokenValidationStubFactory(TOKEN_VALIDATION_SERVICE_URL,
                ADMIN_USERNAME, ADMIN_PASSWORD, PROPERTIES));

        stub = (OAuth2TokenValidationServiceStub) stubs.borrowObject();
        Assert.assertNotNull(stub);
    } catch (Exception e) {
        String msg = "Error occurred while borrowing an oauth validator service stub instance from the pool";
        log.error(msg, e);
        Assert.fail(msg, e);
    } finally {
        if (stubs != null) {
            try {
                if (stub != null) {
                    stubs.returnObject(stub);
                }
            } catch (Exception e) {
                log.warn("Error occurred while returning oauth validator service stub instance to the pool", e);
            }

            /* Checks if the stub instance used above has been properly returned to the pool */
            Assert.assertEquals(stubs.getNumIdle(), 1);
            /* Verifies that there's no hanging connections after the operation performed above */
            Assert.assertEquals(stubs.getNumActive(), 0);

            try {
                stubs.close();
            } catch (Exception e) {
                log.warn("Error occurred while closing the object pool", e);
            }
        }
    }
}