Example usage for org.apache.commons.pool.impl GenericObjectPool GenericObjectPool

List of usage examples for org.apache.commons.pool.impl GenericObjectPool GenericObjectPool

Introduction

In this page you can find the example usage for org.apache.commons.pool.impl GenericObjectPool GenericObjectPool.

Prototype

public GenericObjectPool(PoolableObjectFactory factory) 

Source Link

Document

Create a new GenericObjectPool using the specified factory.

Usage

From source file:org.wso2.carbon.device.mgt.output.adapter.websocket.authentication.oauth.OAuthTokenValdiator.java

public OAuthTokenValdiator(Map<String, String> globalProperties) {
    this.stubs = new GenericObjectPool(new OAuthTokenValidaterStubFactory(globalProperties));
}

From source file:org.wso2.carbon.identity.entitlement.proxy.soap.basicAuth.BasicAuthEntitlementServiceClient.java

private EntitlementServiceStub getEntitlementStub(String serverUrl) throws Exception {

    if (configurationContext == null) {
        throw new EntitlementProxyException(
                "Cannot initialize EntitlementServiceStub with null Axis2 " + "configuration context.");
    }//from   www  .  j a  va2 s.c  o  m
    if (serviceStubPool == null) {
        serviceStubPool = new GenericObjectPool(new EntitlementServiceStubFactory(configurationContext,
                serverUrl + ENTITLEMENT_SERVICE_NAME, authenticator));
    }
    return (EntitlementServiceStub) serviceStubPool.borrowObject();
}

From source file:org.wso2.carbon.identity.samples.entitlement.kmarket.trading.WSO2IdentityAgent.java

private EntitlementServiceStub getEntitlementServiceStub() throws Exception {

    if (entitlementServiceStubPool == null) {
        entitlementServiceStubPool = new GenericObjectPool(
                new EntitlementServiceStubFactory(configurationContext, serverUrl + ENTITLEMENT_SERVICE, auth));
    }/*from   ww  w.  j  a v  a 2  s  .c o  m*/

    return (EntitlementServiceStub) entitlementServiceStubPool.borrowObject();

}

From source file:org.wso2.carbon.identity.samples.entitlement.kmarket.trading.WSO2IdentityAgent.java

private EntitlementPolicyAdminServiceStub getEntitlementPolicyAdminServiceStub() throws Exception {

    if (entitlementPolicyAdminServiceStubPool == null) {
        entitlementPolicyAdminServiceStubPool = new GenericObjectPool(
                new EntitlementPolicyAdminServiceStubFactory(configurationContext,
                        serverUrl + ENTITLEMENT_POLICY_ADMIN_SERVICE, auth));
    }/*w w  w  .j ava  2 s .  com*/

    return (EntitlementPolicyAdminServiceStub) entitlementPolicyAdminServiceStubPool.borrowObject();

}

From source file:org.wso2.carbon.identity.samples.entitlement.kmarket.trading.WSO2IdentityAgent.java

private RemoteUserStoreManagerServiceStub getRemoteUserStoreManagerServiceStub() throws Exception {

    if (remoteUserStoreManagerServiceStubPool == null) {
        remoteUserStoreManagerServiceStubPool = new GenericObjectPool(
                new RemoteUserStoreManagerServiceStubFactory(configurationContext,
                        serverUrl + REMOTE_USER_STORE_MANAGER_SERVICE, auth));
    }/*from w  w  w .  j a  v a  2s. c  o m*/

    return (RemoteUserStoreManagerServiceStub) remoteUserStoreManagerServiceStubPool.borrowObject();

}

From source file:org.wso2.carbon.webapp.authenticator.framework.authenticator.oauth.impl.RemoteOAuthValidator.java

public RemoteOAuthValidator(String hostURL, String adminUserName, String adminPassword, Properties properties) {
    this.stubs = new GenericObjectPool(
            new OAuthTokenValidationStubFactory(hostURL, adminUserName, adminPassword, properties));
}

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

@Test
public void testOAuthTokenValidatorStubPool() {
    ObjectPool stubs = null;/*from www. ja va 2s . c om*/
    OAuth2TokenValidationServiceStub stub = null;

    try {
        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);
            }
        }
    }
}

From source file:org.xlcloud.ssh.SshPoolableSessionFactory.java

@PostConstruct
public void init() {
    GenericObjectPool genericPool = new GenericObjectPool(new SshSessionPoolableObjectFactory());
    genericPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_GROW);
    genericPool.setTestOnBorrow(true);/* w w  w.j a v a 2s  .c  om*/
    genericPool.setMaxActive(maxActive);
    this.sessionPool = genericPool;
}

From source file:paqueteClases.DBConnector.java

private DBConnector(String url, String user, String password) throws Exception {
    ////  ww w. java 2s  .  com
    // First, we'll need a ObjectPool that serves as the
    // actual pool of connections.
    //
    // We'll use a GenericObjectPool instance, although
    // any ObjectPool implementation will suffice.
    //
    Class.forName("com.mysql.jdbc.Driver");
    GenericObjectPool connectionPool = new GenericObjectPool(null);
    connectionPool.setMaxActive(5);
    connectionPool.setMaxWait(2);
    connectionPool.setMaxIdle(2);

    //
    // 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(url, user, password);

    //
    // 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,
    // passing in the object pool we created.
    //
    dataSource_ = new PoolingDataSource(connectionPool);

}

From source file:storm.scheduler.DataManager.java

private DataManager() {
    logger = Logger.getLogger(DataManager.class);
    logger.info("Starting DataManager (working directory: " + System.getProperty("user.dir") + ")");

    try {//from ww  w  .  j a va2  s  . co  m
        // load configuration from file
        logger.debug("Loading configuration from file");
        Properties properties = new Properties();
        properties.load(new FileInputStream("/home/miller/research/storm/apache-storm-0.9.3/db.ini"));
        logger.debug("Configuration loaded");

        // load JDBC driver
        logger.debug("Loading JDBC driver");
        String jdbc_driver = properties.getProperty("jdbc.driver").trim();
        Class.forName(jdbc_driver);
        logger.debug("Driver loaded");

        // set up data source
        logger.debug("Setting up pooling data source");
        String connection_uri = properties.getProperty("data.connection.uri");
        String validation_query = properties.getProperty("validation.query");
        ObjectPool connectionPool = new GenericObjectPool(null);
        ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connection_uri, properties);
        PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,
                connectionPool, null, validation_query, false, true);
        poolableConnectionFactory.hashCode();
        dataSource = new PoolingDataSource(connectionPool);
        logger.debug("Data source set up");

        nodeName = properties.getProperty("node-name");
        if (properties.getProperty("capacity") != null) {
            capacity = Integer.parseInt(properties.getProperty("capacity"));
            if (capacity < 1 || capacity > 100)
                throw new RuntimeException("Wrong capacity: " + capacity + ", expected in the range [1, 100]");
        }

        logger.info("DataManager started");
    } catch (Exception e) {
        logger.error("Error starting DataManager", e);
    }
}