Package org.apache.commons.pool

Examples of org.apache.commons.pool.ObjectPool


   * Closes all pools held by this ServerSessionFactory.
   */
  public void close(ListenerSessionManager sessionManager) {
    synchronized (this.serverSessionPools) {
      for (Iterator it = this.serverSessionPools.values().iterator(); it.hasNext();) {
        ObjectPool pool = (ObjectPool) it.next();
        try {
          pool.close();
        }
        catch (Exception ex) {
          logger.error("Failed to close ServerSession pool", ex);
        }
      }
View Full Code Here


   * Returns a ServerSession from the pool, creating a new pool for the given
   * session manager if necessary.
   * @see #createObjectPool
   */
  public ServerSession getServerSession(ListenerSessionManager sessionManager) throws JMSException {
    ObjectPool pool = null;
    synchronized (this.serverSessionPools) {
      pool = (ObjectPool) this.serverSessionPools.get(sessionManager);
      if (pool == null) {
        if (logger.isInfoEnabled()) {
          logger.info("Creating Commons ServerSession pool for: " + sessionManager);
        }
        pool = createObjectPool(sessionManager);
        this.serverSessionPools.put(sessionManager, pool);
      }
    }
    try {
      return (ServerSession) pool.borrowObject();
    }
    catch (Exception ex) {
      JMSException jmsEx = new JMSException("Failed to borrow ServerSession from pool");
      jmsEx.setLinkedException(ex);
      throw jmsEx;
View Full Code Here

  /**
   * Returns the given ServerSession, which just finished an execution
   * of its listener, back to the pool.
   */
  protected void serverSessionFinished(ServerSession serverSession, ListenerSessionManager sessionManager) {
    ObjectPool pool = (ObjectPool) this.serverSessionPools.get(sessionManager);
    if (pool == null) {
      throw new IllegalStateException("No pool found for session manager [" + sessionManager + "]");
    }
    try {
      pool.returnObject(serverSession);
    }
    catch (Exception ex) {
      logger.error("Failed to return ServerSession to pool", ex);
    }
  }
View Full Code Here

  /**
   * Closes and removes the pool for the given session manager.
   */
  public void close(ListenerSessionManager sessionManager) {
    ObjectPool pool = (ObjectPool) this.serverSessionPools.remove(sessionManager);
    if (pool != null) {
      try {
        pool.close();
      }
      catch (Exception ex) {
        logger.error("Failed to close ServerSession pool", ex);
      }
    }
View Full Code Here

   * Returns a ServerSession from the pool, creating a new pool for the given
   * session manager if necessary.
   * @see #createObjectPool
   */
  public ServerSession getServerSession(ListenerSessionManager sessionManager) throws JMSException {
    ObjectPool pool = null;
    synchronized (this.serverSessionPools) {
      pool = (ObjectPool) this.serverSessionPools.get(sessionManager);
      if (pool == null) {
        if (logger.isInfoEnabled()) {
          logger.info("Creating Commons ServerSession pool for: " + sessionManager);
        }
        pool = createObjectPool(sessionManager);
        this.serverSessionPools.put(sessionManager, pool);
      }
    }
    try {
      return (ServerSession) pool.borrowObject();
    }
    catch (Exception ex) {
      JMSException jmsEx = new JMSException("Failed to borrow ServerSession from pool");
      jmsEx.setLinkedException(ex);
      throw jmsEx;
View Full Code Here

  /**
   * Returns the given ServerSession, which just finished an execution
   * of its listener, back to the pool.
   */
  protected void serverSessionFinished(ServerSession serverSession, ListenerSessionManager sessionManager) {
    ObjectPool pool = (ObjectPool) this.serverSessionPools.get(sessionManager);
    if (pool == null) {
      throw new IllegalStateException("No pool found for session manager [" + sessionManager + "]");
    }
    try {
      pool.returnObject(serverSession);
    }
    catch (Exception ex) {
      logger.error("Failed to return ServerSession to pool", ex);
    }
  }
View Full Code Here

  /**
   * Closes and removes the pool for the given session manager.
   */
  public void close(ListenerSessionManager sessionManager) {
    ObjectPool pool = (ObjectPool) this.serverSessionPools.remove(sessionManager);
    if (pool != null) {
      try {
        pool.close();
      }
      catch (Exception ex) {
        logger.error("Failed to close ServerSession pool", ex);
      }
    }
View Full Code Here

        } catch(IllegalArgumentException e) {
            // expected
        }

        try {
            ObjectPool pool = new GenericObjectPool(
                new SimpleFactory(),
                GenericObjectPool.DEFAULT_MAX_ACTIVE,
                Byte.MAX_VALUE,
                GenericObjectPool.DEFAULT_MAX_WAIT,
                GenericObjectPool.DEFAULT_MAX_IDLE,
View Full Code Here

        assertEquals("should be one active", 1, pool.getNumActive());
        pool.returnObject(obj);
        assertEquals("should be one idle", 1, pool.getNumIdle());
        assertEquals("should be zero active", 0, pool.getNumActive());

        ObjectPool op = new GenericObjectPool();
        try {
            op.addObject();
            fail("Expected IllegalStateException when there is no factory.");
        } catch (IllegalStateException ise) {
            //expected
        }
        op.close();
    }
View Full Code Here

        DriverManager.deregisterDriver(driver);
    }

    /** @see http://issues.apache.org/bugzilla/show_bug.cgi?id=12400 */
    public void testReportedBug12400() throws Exception {
        ObjectPool connectionPool = new GenericObjectPool(
            null,
            70,
            GenericObjectPool.WHEN_EXHAUSTED_BLOCK,
            60000,
            10);
View Full Code Here

TOP

Related Classes of org.apache.commons.pool.ObjectPool

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.