List of usage examples for org.apache.commons.pool2.impl GenericObjectPool GenericObjectPool
public GenericObjectPool(PooledObjectFactory<T> factory)
GenericObjectPool
using defaults from GenericObjectPoolConfig . From source file:no.sr.ringo.persistence.jdbc.RingoDataSourceFactoryDbcpImpl.java
private PoolingDataSource getPoolingDataSource(JdbcConfiguration configuration, String connectURI, String userName, String password, Driver driver) { Properties properties = new Properties(); properties.put("user", userName); properties.put("password", password); // DBCP factory which will produce JDBC Driver instances ConnectionFactory driverConnectionFactory = new DriverConnectionFactory(driver, connectURI, properties); // DBCP Factory holding the pooled connection, which are created by the driver connection factory and held in the supplied pool ObjectName dataSourceJmxName; try {//from w w w . j a va 2s .c o m dataSourceJmxName = new ObjectName("no.difi.oxalis", "connectionPool", "OxalisDB"); } catch (MalformedObjectNameException e) { throw new IllegalStateException(e.getMessage(), e); } PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(driverConnectionFactory, dataSourceJmxName); if (configuration.getValidationQuery().isPresent()) { poolableConnectionFactory.setValidationQuery(configuration.getValidationQuery().get()); } // DBCP object pool holding our driver connections GenericObjectPool<PoolableConnection> genericObjectPool = new GenericObjectPool<PoolableConnection>( poolableConnectionFactory); poolableConnectionFactory.setPool(genericObjectPool); genericObjectPool.setMaxTotal(100); genericObjectPool.setMaxIdle(30); genericObjectPool.setMaxWaitMillis(10000); genericObjectPool.setTestOnBorrow(true); // Test the connection returned from the pool genericObjectPool.setTestWhileIdle(true); // Test idle instances visited by the pool maintenance thread and destroy any that fail validation genericObjectPool.setTimeBetweenEvictionRunsMillis(60 * 60 * 1000); // Test every hour // Creates the actual DataSource instance return new PoolingDataSource(genericObjectPool); }
From source file:org.aludratest.cloud.impl.app.LogDatabase.java
private Connection getConnection() throws SQLException { if (dataSource == null) { EmbeddedDataSource ds = new EmbeddedDataSource(); ds.setDatabaseName("acm"); ConnectionFactory connectionFactory = new DataSourceConnectionFactory(ds); PoolableConnectionFactory objFactory = new PoolableConnectionFactory(connectionFactory, null); objFactory.setValidationQuery("VALUES 1"); objFactory.setDefaultAutoCommit(true); // max 10 minutes lifetime objFactory.setMaxConnLifetimeMillis(1000l * 60 * 10); // must be fast, because is local objFactory.setValidationQueryTimeout(5); GenericObjectPool<PoolableConnection> pool = new GenericObjectPool<PoolableConnection>(objFactory); pool.setMaxIdle(2);// ww w .j av a2 s . c o m dataSource = new PoolingDataSource<PoolableConnection>(pool); } return dataSource.getConnection(); }
From source file:org.apache.james.backend.rabbitmq.RabbitChannelPool.java
@Inject public RabbitChannelPool(RabbitMQConnectionFactory factory) { pool = new GenericObjectPool<>(new ChannelBasePooledObjectFactory(factory)); }
From source file:org.apache.james.backend.rabbitmq.RabbitChannelPoolImpl.java
@Inject public RabbitChannelPoolImpl(RabbitMQConnectionFactory factory) { pooledChannelsFactory = new ChannelBasePooledObjectFactory(factory); pool = new GenericObjectPool<>(pooledChannelsFactory); }
From source file:org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcess.java
public int reference(InterpreterGroup interpreterGroup) { synchronized (referenceCount) { if (executor == null) { // start server process try { port = RemoteInterpreterUtils.findRandomAvailablePortOnAllLocalInterfaces(); } catch (IOException e1) { throw new InterpreterException(e1); }//from w ww . j a va 2s . c o m CommandLine cmdLine = CommandLine.parse(interpreterRunner); cmdLine.addArgument("-d", false); cmdLine.addArgument(interpreterDir, false); cmdLine.addArgument("-p", false); cmdLine.addArgument(Integer.toString(port), false); executor = new DefaultExecutor(); watchdog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT); executor.setWatchdog(watchdog); running = true; try { Map procEnv = EnvironmentUtils.getProcEnvironment(); procEnv.putAll(env); logger.info("Run interpreter process {}", cmdLine); executor.execute(cmdLine, procEnv, this); } catch (IOException e) { running = false; throw new InterpreterException(e); } long startTime = System.currentTimeMillis(); while (System.currentTimeMillis() - startTime < connectTimeout) { if (RemoteInterpreterUtils.checkIfRemoteEndpointAccessible("localhost", port)) { break; } else { try { Thread.sleep(500); } catch (InterruptedException e) { } } } clientPool = new GenericObjectPool<Client>(new ClientFactory("localhost", port)); remoteInterpreterEventPoller.setInterpreterGroup(interpreterGroup); remoteInterpreterEventPoller.setInterpreterProcess(this); remoteInterpreterEventPoller.start(); } return referenceCount.incrementAndGet(); } }
From source file:org.apache.zeppelin.jdbc.JDBCInterpreter.java
private void createConnectionPool(String url, String user, String propertyKey, Properties properties) throws SQLException, ClassNotFoundException { ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(url, properties); PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null);//from w w w .j a v a2s. co m ObjectPool connectionPool = new GenericObjectPool(poolableConnectionFactory); poolableConnectionFactory.setPool(connectionPool); Class.forName(properties.getProperty(DRIVER_KEY)); PoolingDriver driver = new PoolingDriver(); driver.registerPool(propertyKey + user, connectionPool); getJDBCConfiguration(user).saveDBDriverPool(propertyKey, driver); }
From source file:org.apdplat.superword.tools.MySQLUtils.java
private static DataSource setupDataSource(String connectUri, String uname, String passwd) { ///* w w w . j a va 2 s . com*/ // First, 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, uname, passwd); // // Next 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, null); // // Now 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. // ObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(poolableConnectionFactory); // Set the factory's pool property to the owning pool poolableConnectionFactory.setPool(connectionPool); // // Finally, we create the PoolingDriver itself, // passing in the object pool we created. // PoolingDataSource<PoolableConnection> dataSource = new PoolingDataSource<>(connectionPool); return dataSource; }
From source file:org.cloudgraph.state.PooledStateMarshallingContext.java
public PooledStateMarshallingContext(GenericObjectPoolConfig config, StateDataBindingFactory factory) { log.info("initializing data binding pool..."); this.pool = new GenericObjectPool<StateNonValidatingDataBinding>(factory); }
From source file:org.codelibs.fess.crawler.client.http.WebDriverClientTest.java
@Override protected void setUp() throws Exception { super.setUp(); CrawlerPooledObjectFactory<CrawlerWebDriver> pooledObjectFactory = new CrawlerPooledObjectFactory<>(); pooledObjectFactory.setComponentName("webDriver"); pooledObjectFactory.setOnDestroyListener(p -> { final CrawlerWebDriver driver = p.getObject(); driver.quit();/*from www. j a va 2 s.c o m*/ }); final StandardCrawlerContainer container = new StandardCrawlerContainer(); container.prototype("webDriver", CrawlerWebDriver.class) .singleton("mimeTypeHelper", MimeTypeHelperImpl.class) .singleton("pooledObjectFactory", pooledObjectFactory) .singleton("webDriverPool", new GenericObjectPool<>(pooledObjectFactory), null, pool -> { pool.close(); }).<AOnClickAction>singleton("aOnClickAction", AOnClickAction.class) .<FormAction>singleton("formAction", FormAction.class) .<WebDriverClient>singleton("webDriverClient", WebDriverClient.class, client -> { AOnClickAction aOnClick = container.getComponent("aOnClickAction"); aOnClick.setName("aOnClick"); aOnClick.setCssQuery("a"); client.addUrlAction(aOnClick); FormAction formAction = container.getComponent("formAction"); formAction.setName("form"); formAction.setCssQuery("form"); client.addUrlAction(formAction); }); webDriverClient = container.getComponent("webDriverClient"); }
From source file:org.codelibs.robot.client.http.WebDriverClientTest.java
@Override protected void setUp() throws Exception { super.setUp(); S2PooledObjectFactory<S2WebDriver> pooledObjectFactory = new S2PooledObjectFactory<>(); pooledObjectFactory.setComponentName("webDriver"); pooledObjectFactory.setOnDestroyListener(p -> { final S2WebDriver driver = p.getObject(); driver.quit();//from w ww. j a va 2s .c o m }); final StandardRobotContainer container = new StandardRobotContainer(); container.prototype("webDriver", S2WebDriver.class).singleton("mimeTypeHelper", MimeTypeHelperImpl.class) .singleton("pooledObjectFactory", pooledObjectFactory) .singleton("webDriverPool", new GenericObjectPool<>(pooledObjectFactory), null, pool -> { pool.close(); }).<AOnClickAction>singleton("aOnClickAction", AOnClickAction.class) .<FormAction>singleton("formAction", FormAction.class) .<WebDriverClient>singleton("webDriverClient", WebDriverClient.class, client -> { AOnClickAction aOnClick = container.getComponent("aOnClickAction"); aOnClick.setName("aOnClick"); aOnClick.setCssQuery("a"); client.addUrlAction(aOnClick); FormAction formAction = container.getComponent("formAction"); formAction.setName("form"); formAction.setCssQuery("form"); client.addUrlAction(formAction); }); webDriverClient = container.getComponent("webDriverClient"); }