Package org.apache.commons.pool.impl

Examples of org.apache.commons.pool.impl.GenericObjectPool$Config


    conf.testOnBorrow = PropertyUtils.getBooleanProperty(Properties.SIPATRA_POOL_TEST_BORROW, false, servletContext);
    conf.testOnReturn = PropertyUtils.getBooleanProperty(Properties.SIPATRA_POOL_TEST_RETURN, false, servletContext);
    conf.testWhileIdle = PropertyUtils.getBooleanProperty(Properties.SIPATRA_POOL_TEST_IDLE, false, servletContext);
    conf.timeBetweenEvictionRunsMillis = PropertyUtils.getLongProperty(Properties.SIPATRA_POOL_TIME_EVICTION, -1L, servletContext);
   
    GenericObjectPool pool = new GenericObjectPool(new JRubyRuntimeFactory(appPath, scriptPath), conf);
    startPool(pool, PropertyUtils.getIntegerProperty(Properties.SIPATRA_POOL_INIT_POOL_SIZE, 1, servletContext));
    servletContext.setAttribute(Attributes.POOL, pool);
  }
View Full Code Here


    servletContext.setAttribute(Attributes.POOL, pool);
  }
 
  public void contextDestroyed(ServletContextEvent sce)
  {
    GenericObjectPool pool = (GenericObjectPool) sce.getServletContext().getAttribute(Attributes.POOL);
    stopPool(pool);
  }
View Full Code Here

  private void invokeMethod(SipServletMessage message, String methodName)
  {
    ScriptingContainer container = null;
    try
    {
      GenericObjectPool pool = (GenericObjectPool) message.getSession().getServletContext().getAttribute(Attributes.POOL);
      container = (ScriptingContainer) pool.borrowObject();
            long beginTime = System.currentTimeMillis();
      try
      {
        Object app = container.runScriptlet("Sipatra::Application::new");

        container.callMethod(app, "set_bindings", new Object[] {
            message.getSession().getServletContext()
            message.getSession().getServletContext().getAttribute(SipServlet.SIP_FACTORY),
            message.getSession(),
            message, _log});
        container.callMethod(app, methodName);
      }
      catch(Exception e)
      {
        pool.invalidateObject(container);
        container = null;
      }
      finally
      {
        if(container != null)
        {
          pool.returnObject(container);
        }
                _log.trace("Processed '%s' (%s, %s) in %dms", new Object[] {
                           message.getMethod(), message.getSession().getId(),
                           message.getCallId(), System.currentTimeMillis() - beginTime });
      }
View Full Code Here

        final List calledMethods = new ArrayList();

        // Test that the minIdle check doesn't add too many idle objects
        final PoolableObjectFactory pof = (PoolableObjectFactory)createProxy(PoolableObjectFactory.class, calledMethods);
        final ObjectPool op = new GenericObjectPool(pof);
        PoolUtils.checkMinIdle(op, 2, 100);
        Thread.sleep(400);
        assertEquals(2, op.getNumIdle());
        op.close();
        int makeObjectCount = 0;
        final Iterator iter = calledMethods.iterator();
        while (iter.hasNext()) {
            final String methodName = (String)iter.next();
            if ("makeObject".equals(methodName)) {
View Full Code Here

   * @return a new SQL data source
   */
  static DataSource newDataSource(String uri,
                                  String user,
                                  String password) {
    GenericObjectPool connectionPool = new GenericObjectPool();
    connectionPool.setMaxActive(256);
    connectionPool.setMaxIdle(256);
    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
        uri, user, password);
    //
    // This constructor modifies the connection pool, setting its connection
    // factory to this.  (So despite how it may appear, all of the objects
View Full Code Here

    // actual pool of connections.
    //
    // We'll use a GenericObjectPool instance, although
    // any ObjectPool implementation will suffice.
    //
    ObjectPool connectionPool = new GenericObjectPool(null);

    //
    // Next, we'll create a ConnectionFactory that the
    // pool will use to create Connections.
    // We'll use the DriverManagerConnectionFactory,
    // using the connect string passed in the command line
    // arguments.
    //
    //ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI,null);
    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(url, "admin_user", "client00");

    //
    // Now we'll create the PoolableConnectionFactory, which wraps
    // the "real" Connections created by the ConnectionFactory with
    // the classes that implement the pooling functionality.
    //
    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true);

    //
    // Finally, we create the PoolingDriver itself...
    //
    PoolingDriver driver = new PoolingDriver();

    //
    // ...and register our pool with it.
    //
    driver.registerPool("example",connectionPool);

    //
    // Now we can just use the connect string "jdbc:apache:commons:dbcp:example"
    // to access our pool of Connections.
    //
    System.out.println("Setting up driver: Done.");

    //
    // Now, we can use JDBC as we normally would.
    // Using the connect string
    //  jdbc:apache:commons:dbcp:example
    // The general form being:
    //  jdbc:apache:commons:dbcp:<name-of-pool>
    //

    Connection conn = null;
    PreparedStatement pstmt = null;
    Statement stmt = null;
    ResultSet rset = null;

    // Check to see if connection is pooled
    long startTime = new Date().getTime();
    long currentTime;
    System.out.println("Creating connection.");
    try {
      conn = DriverManager.getConnection("jdbc:apache:commons:dbcp:example");
      conn.setAutoCommit(false);
      System.out.println("Connection time=" + (new Date().getTime() - startTime));
      System.out.println("Creating statement.");

      // Clean table
      stmt = conn.createStatement();
      rset = stmt.executeQuery("delete from Test;");
     
      sql = "insert into APP.Test " +
        "set TestID=? " +
        ", TextField=?";
      pstmt = conn.prepareStatement(sql);
      System.out.println("Executing statement.");
    } catch(SQLException e) {
      e.printStackTrace();
      try { pstmt.close(); } catch(Exception e1) { }
      try { conn.close(); } catch(Exception e2) { }
    }
   
    for (int n=1; n <101; n++) {
      System.out.println("=======");
      System.out.println("n=" + n);

      try {
        pstmt.setInt(1, n);
        pstmt.setString(2, "This is field " + n);
        rset = pstmt.executeQuery();
      } catch(SQLException e) {
        e.printStackTrace();
        try { pstmt.close(); } catch(Exception e2) { }
        try { conn.close(); } catch(Exception e2) { }
      }
      // Reset time
      startTime = new Date().getTime();
    }
   
    try {
      conn.commit();
    } catch(SQLException e) {
      e.printStackTrace();
    }
   
    try { pstmt.close(); } catch(Exception e2) { }
    try { conn.close(); } catch(Exception e2) { }

    System.out.println("DBCP example: sql done");
   
    // Close connection pool
    try {
      connectionPool.close();
    } catch (Exception e) {
      System.out.println("Exception thrown closing connection pool:");
      System.out.println(e.getMessage());
    }
   
View Full Code Here

    // actual pool of connections.
    //
    // We'll use a GenericObjectPool instance, although
    // any ObjectPool implementation will suffice.
    //
    connectionPool = new GenericObjectPool(null);
    connectionPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_GROW);
    connectionPool.setMaxActive(Integer.parseInt(Configuration.getProperty("dbcp.maxactive", Constants.DBCP_MAX_ACTIVE)));
    connectionPool.setMaxWait(Integer.parseInt(Configuration.getProperty("dbcp.maxwait", Constants.DBCP_MAX_WAIT)));
    connectionPool.setMaxIdle(Integer.parseInt(Configuration.getProperty("dbcp.maxidle", Constants.DBCP_MAX_IDLE)));
    connectionPool.setMinIdle(Integer.parseInt(Configuration.getProperty("dbcp.minidle", Constants.DBCP_MIN_IDLE)));
View Full Code Here

    //
    // We'll use a GenericObjectPool instance, although
    // any ObjectPool implementation will suffice.
    //
    //ObjectPool connectionPool = new GenericObjectPool(null);
    GenericObjectPool connectionPool = new GenericObjectPool(null);
    connectionPool.setMaxActive(-1);

    //
    // Next, we'll create a ConnectionFactory that the
    // pool will use to create Connections.
    // We'll use the DriverManagerConnectionFactory,
    // using the connect string passed in the command line
    // arguments.
    //
    //ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI,null);

    String url;
    String sql;
    boolean serverMode = true;
   
    if (serverMode) {
      url = "jdbc:mckoi://localhost";
    } else {
      url = "jdbc:mckoi:local://resource/nz.co.transparent.client.db.conf";
    }

    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(url, "admin_user", "client00");
    //
    // Now we'll create the PoolableConnectionFactory, which wraps
    // the "real" Connections created by the ConnectionFactory with
    // the classes that implement the pooling functionality.
    //
    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true);
    //
    // Finally, we create the PoolingDriver itself...
    //
    PoolingDriver driver = new PoolingDriver();

    //
    // ...and register our pool with it.
    //
    driver.registerPool("example",connectionPool);

    //
    // Now we can just use the connect string "jdbc:apache:commons:dbcp:example"
    // to access our pool of Connections.
    //
    System.out.println("Setting up driver: Done.");

    //
    // Now, we can use JDBC as we normally would.
    // Using the connect string
    //  jdbc:apache:commons:dbcp:example
    // The general form being:
    //  jdbc:apache:commons:dbcp:<name-of-pool>
    //

    Connection conn = null;
    PreparedStatement pstmt = null;
    Statement stmt = null;
    ResultSet rset = null;
    boolean closeConnection = false;
    long startTime;
    long currentTime;
    // DBCP can handle a maximum of 8 connections
    // DBCP hangs at connection number 9
    int loopCount = 20;

    System.out.println("==> START");
    for (int i=1; i<=loopCount; i++) {
      System.out.println("==> i = " + i);
      startTime = new Date().getTime();
      try {
        conn = DriverManager.getConnection("jdbc:apache:commons:dbcp:example");
        conn.setAutoCommit(false);
        System.out.println("Connection time=" + (new Date().getTime() - startTime));
 
        System.out.println("Executing statement.");
        sql = "select * from Client where (ClientID=1)";
        stmt = conn.createStatement();
        rset = stmt.executeQuery(sql);
        rset.next();
        System.out.println("LastName=" + rset.getString("LastName"));
       
        if (closeConnection) {
          try {stmt.close();
          } catch(Exception e1) {
            System.out.println("Error closing statement: " + e1.getMessage());
            return;
          }
          try {conn.close();
          } catch(Exception e2) {
            System.out.println("Error closing connection: " + e2.getMessage());
            return;
          }
        }
      } catch(SQLException e) {
        e.printStackTrace();
        try {stmt.close(); } catch(Exception e1) { }
        try { conn.close(); } catch(Exception e2) { }
      }
    }
   
    try { stmt.close(); } catch(Exception e2) { }
    try { pstmt.close(); } catch(Exception e2) { }
    try { conn.close(); } catch(Exception e2) { }

    System.out.println("DBCP example: sql done");
   
    // Close connection pool
    try {
      connectionPool.close();
    } catch (Exception e) {
      System.out.println("Exception thrown closing connection pool:");
      System.out.println(e.getMessage());
    }
   
View Full Code Here

    // actual pool of connections.
    //
    // We'll use a GenericObjectPool instance, although
    // any ObjectPool implementation will suffice.
    //
    ObjectPool connectionPool = new GenericObjectPool(null);

    //
    // Next, we'll create a ConnectionFactory that the
    // pool will use to create Connections.
    // We'll use the DriverManagerConnectionFactory,
View Full Code Here

  public ConnectionPoolDataSource(DataSource underlyingDataSource) {
    if (underlyingDataSource == null) {
      throw new IllegalArgumentException("underlyingDataSource is null");
    }
    ConnectionFactory connectionFactory = new ConfiguringConnectionFactory(underlyingDataSource);
    GenericObjectPool objectPool = new GenericObjectPool();
    objectPool.setTestOnBorrow(false);
    objectPool.setTestOnReturn(false);
    objectPool.setTestWhileIdle(true);
    objectPool.setTimeBetweenEvictionRunsMillis(60 * 1000L);
    PoolableObjectFactory factory = new PoolableConnectionFactory(connectionFactory, objectPool, null,
        "SELECT 1", false, false);
    objectPool.setFactory(factory);
    delegate = new PoolingDataSource(objectPool);
  }
View Full Code Here

TOP

Related Classes of org.apache.commons.pool.impl.GenericObjectPool$Config

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.