List of usage examples for org.apache.commons.pool.impl GenericObjectPool GenericObjectPool
public GenericObjectPool(PoolableObjectFactory factory, int maxActive)
From source file:org.apache.ojb.broker.accesslayer.ConnectionFactoryPooledImpl.java
/** * Create the pool for pooling the connections of the given connection descriptor. * Override this method to implement your on {@link org.apache.commons.pool.ObjectPool}. *//*from w w w. j a va 2 s. c om*/ public ObjectPool createConnectionPool(JdbcConnectionDescriptor jcd) { if (log.isDebugEnabled()) log.debug("createPool was called"); PoolableObjectFactory pof = new ConPoolFactory(this, jcd); GenericObjectPool.Config conf = jcd.getConnectionPoolDescriptor().getObjectPoolConfig(); return (ObjectPool) new GenericObjectPool(pof, conf); }
From source file:org.artifactory.storage.db.itest.spring.DbTestConfigFactory.java
/** * @return Auto-commit datasource for the unique ids generator. * @see org.artifactory.storage.db.spring.DbConfigFactory#createUniqueIdsDataSource() *//*www . j ava 2 s .c om*/ @Bean(name = "uniqueIdsDataSource") public PoolingDataSource createUniqueIdsDataSource() { StorageProperties storageProperties = beanFactory.getBean("storageProperties", StorageProperties.class); GenericObjectPool.Config poolConfig = new GenericObjectPool.Config(); poolConfig.maxActive = 1; poolConfig.maxIdle = 1; ObjectPool connectionPool = new GenericObjectPool(null, poolConfig); ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( storageProperties.getConnectionUrl(), storageProperties.getUsername(), storageProperties.getPassword()); // default auto commit true! PoolableConnectionFactory pcf = new ArtifactoryPoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true); pcf.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); return new PoolingDataSource(connectionPool); }
From source file:org.artifactory.storage.db.spring.ArtifactoryDataSource.java
public ArtifactoryDataSource(StorageProperties storageProperties) { GenericObjectPool.Config poolConfig = new GenericObjectPool.Config(); poolConfig.maxActive = storageProperties.getMaxActiveConnections(); poolConfig.maxIdle = storageProperties.getMaxIdleConnections(); ObjectPool connectionPool = new GenericObjectPool(null, poolConfig); ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( connectionUrl = storageProperties.getConnectionUrl(), storageProperties.getUsername(), storageProperties.getPassword()); PoolableConnectionFactory pcf = new ArtifactoryPoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, false);/*from w w w . ja va 2 s .c om*/ pcf.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); setPool(connectionPool); genericPool = (GenericObjectPool) _pool; }
From source file:org.bremersee.objectlock.ObjectReadWriteLockImpl.java
/** * Construct a read write lock with the specified ordering policy. * //from ww w . j a va 2 s . com * @param fair * {@code true} if this lock should use a fair ordering policy * @param minIdle * the minimum number of objects allowed in the pool * @param maxIdle * the cap on the number of idle instances in the pool, use a * negative value to indicate an unlimited number of idle * instances */ public ObjectReadWriteLockImpl(boolean fair, int minIdle, int maxIdle) { GenericObjectPool.Config config = new GenericObjectPool.Config(); config.maxActive = -1; config.minIdle = minIdle >= 8 ? minIdle : 8; config.maxIdle = maxIdle < 0 ? maxIdle : (maxIdle >= 32 ? maxIdle : 32); this.pool = new GenericObjectPool<ReentrantReadWriteLock>(new ReentrantReadWriteLockFactory(fair), config); }
From source file:org.callimachusproject.sql.DriverConnectionPoolManager.java
public synchronized void registerDriver(String name, Driver driver, String url, Properties info, GenericObjectPool.Config config, String validationQuery) throws SQLException { ConnectionFactory factory;/*from ww w. j a va 2s .c om*/ PoolableDriverConnectionFactory poolable; ObjectPool<PoolableDriverConnection> pool; if (pools.containsKey(name)) { deregisterDriver(name); } factory = new DriverConnectionFactory(driver, url, info); poolable = new PoolableDriverConnectionFactory(factory, validationQuery); pool = new GenericObjectPool<PoolableDriverConnection>(poolable, config); poolable.setPool(pool); pools.put(name, pool); }
From source file:org.cipango.sipatra.DefaultContextLoader.java
public void contextInitialized(ServletContextEvent sce) { ServletContext servletContext = sce.getServletContext(); String appPath = servletContext.getRealPath("/WEB-INF/sipatra"); String scriptPath = PropertyUtils.getStringProperty(Properties.SIPATRA_PATH_PROPERTY, null, servletContext); if (scriptPath == null) { scriptPath = appPath + "/application.rb"; } else {/*ww w . j av a 2 s . c o m*/ File file = new File(scriptPath); if (!file.exists()) { _log.error(file.getAbsolutePath() + " does not exist!"); scriptPath = null; } if (file.isFile()) { if (!file.getName().endsWith(".rb")) _log.warn(file.getAbsolutePath() + " is not a ruby file!"); if (file.getParentFile() != null) appPath = file.getParentFile().getAbsolutePath(); else _log.error(file.getAbsolutePath() + " got no parent directory!"); } else if (file.isDirectory()) { appPath = new File(scriptPath).getAbsolutePath(); } } Config conf = new Config(); conf.maxActive = PropertyUtils.getIntegerProperty(Properties.SIPATRA_POOL_MAX_ACTIVE_PROPERTY, -1, servletContext); conf.maxIdle = PropertyUtils.getIntegerProperty(Properties.SIPATRA_POOL_MAX_IDLE_PROPERTY, -1, servletContext); conf.maxWait = PropertyUtils.getIntegerProperty(Properties.SIPATRA_POOL_MAX_WAIT_PROPERTY, -1, servletContext); conf.minIdle = PropertyUtils.getIntegerProperty(Properties.SIPATRA_POOL_MIN_IDLE_PROPERTY, -1, servletContext); conf.minEvictableIdleTimeMillis = PropertyUtils .getLongProperty(Properties.SIPATRA_POOL_MIN_EVICTABLE_PROPERTY, 1000L * 60L * 30L, servletContext); conf.lifo = PropertyUtils.getBooleanProperty(Properties.SIPATRA_POOL_LIFO, false, servletContext); conf.numTestsPerEvictionRun = PropertyUtils.getIntegerProperty(Properties.SIPATRA_POOL_TEST_EVICTION_RUN, 3, servletContext); conf.softMinEvictableIdleTimeMillis = PropertyUtils .getLongProperty(Properties.SIPATRA_POOL_SOFT_MIN_EVICTABLE, -1L, servletContext); 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); }
From source file:org.corfudb.client.PooledThriftClient.java
@SuppressWarnings("rawtypes") public PooledThriftClient(ClientFactory<T> factory, ProtocolFactory pfactory, Config config) { this.pool = new GenericObjectPool<T>(new ThriftClientFactory(factory, pfactory), config); }
From source file:org.corfudb.runtime.protocols.PooledThriftClient.java
@SuppressWarnings("rawtypes") @SneakyThrows//from w w w.j ava2s. c om public PooledThriftClient(ClientFactory<T> factory, AsyncClientFactory<U> asyncFactory, ProtocolFactory pfactory, Config config, String host, int port) { this.pool = new GenericObjectPool<>(new ThriftClientFactory(factory, pfactory), config); this.asyncPool = new GenericObjectPool<>(new AsyncThriftClientFactory(asyncFactory, new TCompactProtocol.Factory(), new TAsyncClientManager(), host, port), config); }
From source file:org.forumj.dbextreme.db.dao.FJDao.java
public static Connection getConnection() throws SQLException, ConfigurationException { if (dataSource == null) { synchronized (FJDao.class) { Configuration config = FJConfiguration.getConfig(); if (dataSource == null) { Integer maxActive = config.getInteger("dbcp.maxActive", 10); ObjectPool connectionPool = new GenericObjectPool(null, maxActive); String connectURI = config.getString("jdbc.url"); String userName = config.getString("jdbc.user.name"); String userPassword = config.getString("jdbc.user.password"); String driver = config.getString("jdbc.driver"); String validationQuery = config.getString("dbcp.validationQuery"); if (driver != null) { try { Class.forName(driver); } catch (ClassNotFoundException e) { e.printStackTrace(); }// www . j ava 2 s . co m } ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI, userName, userPassword); new PoolableConnectionFactory(connectionFactory, connectionPool, null, validationQuery, false, true); dataSource = new PoolingDataSource(connectionPool); } } } return dataSource.getConnection(); }
From source file:org.geosdi.geoplatform.connector.jaxb.pool.GeoPlatformJAXBContextPool.java
/** * <p>//from w w w . j a va2s . c om * Obtain a new instance of a <tt>GeoPlatformJAXBContextPool</tt> class. * * <p> * * @param contextPath list of java package names that contain schema derived classes * @param classLoader * This class loader will be used to locate the implementation classes. * @param properties * provider-specific properties. Can be null, which means the same thing as passing * in an empty map. * * @throws JAXBException if an error was encountered while creating the * <tt>JAXBContext</tt> such as * <ol> * <li>failure to locate either ObjectFactory.class or jaxb.index in the packages</li> * <li>an ambiguity among global elements contained in the contextPath</li> * <li>failure to locate a value for the context factory provider property</li> * <li>mixing schema derived packages from different providers on the same contextPath</li> * </ol> */ public GeoPlatformJAXBContextPool(String contextPath, ClassLoader classLoader, Map<String, ?> properties) throws JAXBException { super(contextPath, classLoader, properties); this.marshallerPool = new GenericObjectPool<Marshaller>(new GPMarshallerFactory(jaxbContext), new GeoPlatformJAXBConfig()); this.unmarshallerPool = new GenericObjectPool<Unmarshaller>(new GPUnmarshallerFactory(jaxbContext), new GeoPlatformJAXBConfig()); }