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

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

Introduction

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

Prototype

int getNumIdle() throws UnsupportedOperationException;

Source Link

Usage

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());
    }/* w  ww . jav  a 2  s.  c o 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 w w  w  .j  a va 2  s  .  c  om
 * @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./*from  w ww  .j  a  v a2s .  c  o  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 idle resources in all pools.
 * @return number of idle resources/* w ww  .j ava2 s.c  o m*/
 * @since 0.7.3
 */
public synchronized int getNumIdle() {
    int idle = 0;
    final Collection<ObjectPool> col = pools.values();
    for (ObjectPool pool : col) {
        idle += pool.getNumIdle();
    }
    return idle;
}

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

/**
 * Retrieves the number of idle resources in the pool for the given key.
 * @param key the key/* w w  w. j  a v  a2 s .co m*/
 * @return number of idle resources, <code>-1</code> if there is no resource
 *         with that key
 * @since 0.7.3
 */
public synchronized int getNumIdle(final String key) {
    final ObjectPool pool = pools.get(key);
    if (pool == null) {
        return -1;
    }
    return pool.getNumIdle();
}

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

/**
 * Print Driver Stats./*w  ww.  j a v a 2 s.c  om*/
 */
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 idle connections managed by a pool.<p> 
 * //from  ww  w.ja  va 2 s  .  c o  m
 * @param dbPoolUrl the url of a pool 
 * @return the number of idle connections 
 * @throws CmsDbException if something goes wrong 
 */
public int getIdleConnections(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.getNumIdle();
        }
    } 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.quickserver.net.server.impl.BasicPoolManager.java

public void initPool(ObjectPool objectPool, PoolConfig opConfig) {
    int initSize = opConfig.getInitSize();
    try {/*  ww  w. jav  a2  s  .  com*/
        while (objectPool.getNumIdle() < initSize)
            objectPool.addObject();
    } catch (Exception e) {
        logger.log(Level.FINE, "Error: {0}", e);
    }
}

From source file:org.quickserver.util.pool.PoolHelper.java

/**
 * Check if Pool is open.// ww  w  .ja v  a2s  .  c o  m
 */
public static boolean isPoolOpen(ObjectPool pool) {
    try {
        pool.getNumIdle();
    } catch (Exception e) {
        return false;
    }
    return true;
}