Example usage for org.apache.commons.pool2.impl GenericObjectPoolConfig setBlockWhenExhausted

List of usage examples for org.apache.commons.pool2.impl GenericObjectPoolConfig setBlockWhenExhausted

Introduction

In this page you can find the example usage for org.apache.commons.pool2.impl GenericObjectPoolConfig setBlockWhenExhausted.

Prototype

public void setBlockWhenExhausted(boolean blockWhenExhausted) 

Source Link

Document

Set the value for the blockWhenExhausted configuration attribute for pools created with this configuration instance.

Usage

From source file:net.greghaines.jesque.utils.PoolUtils.java

/**
 * @return a GenericObjectPoolConfig configured with: maxActive=-1,
 * maxIdle=10, minIdle=1, testOnBorrow=true,
 * blockWhenExhausted=false//  w  w w  . j  a  v  a 2 s  .c o m
 */
public static GenericObjectPoolConfig getDefaultPoolConfig() {
    final GenericObjectPoolConfig cfg = new GenericObjectPoolConfig();
    cfg.setMaxTotal(-1); // Infinite
    cfg.setMaxIdle(10);
    cfg.setMinIdle(1);
    cfg.setTestOnBorrow(true);
    cfg.setBlockWhenExhausted(false);
    return cfg;
}

From source file:com.reversemind.hypergate.client.ClientPool.java

private static GenericObjectPoolConfig createConfig(int poolSize) {
    GenericObjectPoolConfig genericObjectPoolConfig = new GenericObjectPoolConfig();
    genericObjectPoolConfig.setJmxEnabled(true);
    genericObjectPoolConfig.setJmxNameBase("HyperGatePool");
    genericObjectPoolConfig.setJmxNamePrefix("HyperGatePoolPrefix");
    genericObjectPoolConfig.setBlockWhenExhausted(false);
    genericObjectPoolConfig.setMinIdle(0);
    genericObjectPoolConfig.setTestOnBorrow(true);
    genericObjectPoolConfig.setMaxWaitMillis(500);
    START_POOL_SIZE = poolSize;//from  ww  w  .ja  v  a2 s  . c  o m
    genericObjectPoolConfig.setMaxTotal(START_POOL_SIZE);
    genericObjectPoolConfig.setMaxIdle(START_POOL_SIZE);
    return genericObjectPoolConfig;
}

From source file:com.pytsoft.cachelock.LockSmithTest_RedisCluster_Jedis.java

@Before
public void init() {
    Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
    HostAndPort hostAndPort = new HostAndPort(this.cacheServerHost, this.redisServerPort);
    jedisClusterNodes.add(hostAndPort);//from  w  ww.  j  ava2s.c o  m

    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setBlockWhenExhausted(true);
    config.setMaxTotal(20);
    config.setMaxIdle(10);
    config.setMinIdle(5);
    config.setMaxWaitMillis(5000);

    this.cluster = new JedisCluster(jedisClusterNodes, config);
}

From source file:com.thinkbiganalytics.nifi.provenance.config.NifiProvenanceConfig.java

/**
 * The KyloProvenanceEventReportingTask will override these defaults based upon its batch property ("Processing batch size")
 *
 * @return an object pool for processing ProvenanceEventRecordDTO objects
 *//*from w ww.  j  ava  2  s.c  o  m*/
@Bean
public ProvenanceEventObjectPool provenanceEventObjectPool() {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxIdle(1000);
    config.setMaxTotal(1000);
    config.setMinIdle(1);
    config.setBlockWhenExhausted(false);
    config.setTestOnBorrow(false);
    config.setTestOnReturn(false);
    return new ProvenanceEventObjectPool(new ProvenanceEventObjectFactory(), config);
}

From source file:com.streamsets.pipeline.lib.parser.log.TestCEFParser.java

private GenericObjectPool<StringBuilder> getStringBuilderPool() {
    GenericObjectPoolConfig stringBuilderPoolConfig = new GenericObjectPoolConfig();
    stringBuilderPoolConfig.setMaxTotal(1);
    stringBuilderPoolConfig.setMinIdle(1);
    stringBuilderPoolConfig.setMaxIdle(1);
    stringBuilderPoolConfig.setBlockWhenExhausted(false);
    return new GenericObjectPool<>(new StringBuilderPoolFactory(1024), stringBuilderPoolConfig);
}

From source file:com.streamsets.pipeline.lib.parser.DataParserFactory.java

protected GenericObjectPool<StringBuilder> getStringBuilderPool(Settings settings) {
    int maxRecordLen = getSettings().getMaxRecordLen();
    int poolSize = getSettings().getStringBuilderPoolSize();
    GenericObjectPoolConfig stringBuilderPoolConfig = new GenericObjectPoolConfig();
    stringBuilderPoolConfig.setMaxTotal(poolSize);
    stringBuilderPoolConfig.setMinIdle(poolSize);
    stringBuilderPoolConfig.setMaxIdle(poolSize);
    stringBuilderPoolConfig.setBlockWhenExhausted(false);
    return new GenericObjectPool<>(
            new StringBuilderPoolFactory(maxRecordLen > 0 ? maxRecordLen : DEFAULT_MAX_RECORD_LENGTH),
            stringBuilderPoolConfig);// w  w  w. j av  a  2 s.c om
}

From source file:herddb.jdbc.BasicHerdDBDataSource.java

protected synchronized void ensureClient() throws SQLException {
    if (client == null) {
        ClientConfiguration clientConfiguration = new ClientConfiguration(properties);
        Properties propsNoPassword = new Properties(properties);
        if (propsNoPassword.contains("password")) {
            propsNoPassword.setProperty("password", "-------");
        }//from  w  w w .  j  a va2 s.c o  m
        LOGGER.log(Level.INFO, "Booting HerdDB Client, url:" + url + ", properties:" + propsNoPassword
                + " clientConfig " + clientConfiguration);
        clientConfiguration.readJdbcUrl(url);
        if (properties.containsKey("discoverTableSpaceFromQuery")) {
            this.discoverTableSpaceFromQuery = clientConfiguration.getBoolean("discoverTableSpaceFromQuery",
                    true);
        }
        client = new HDBClient(clientConfiguration);
    }
    if (pool == null) {
        if (properties.containsKey("maxActive")) {
            this.maxActive = Integer.parseInt(properties.get("maxActive").toString());
        }
        GenericObjectPoolConfig config = new GenericObjectPoolConfig();
        config.setBlockWhenExhausted(true);
        config.setMaxTotal(maxActive);
        config.setMaxIdle(maxActive);
        config.setMinIdle(maxActive / 2);
        config.setJmxNamePrefix("HerdDBClient");
        pool = new GenericObjectPool<>(new ConnectionsFactory(), config);
    }
}

From source file:net.sheehantech.cherry.pool.PooledPushClient.java

@Override
public void init() throws ConnectionFailedException {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    if (maxTotal != null)
        config.setMaxTotal(maxTotal);/*from w  w  w  .jav a  2s . c om*/
    if (maxIdle != null)
        config.setMaxIdle(maxIdle);
    if (minIdle != null)
        config.setMinIdle(minIdle);
    config.setTestOnBorrow(true);
    config.setTestWhileIdle(true);
    config.setBlockWhenExhausted(true);
    pool = new GenericObjectPool<PooledPushSocket>(new PooledPushSocketFactory(socketFactory, gateway, port),
            config);
    try {
        pool.preparePool();
    } catch (Exception e) {
        throw (new ConnectionFailedException(e));
    }
    logger.debug("Started new push socket pool with {} sockets", pool.getNumIdle());
}

From source file:ch.cyberduck.core.pool.DefaultSessionPool.java

public DefaultSessionPool(final ConnectionService connect, final X509TrustManager trust,
        final X509KeyManager key, final VaultRegistry registry, final PathCache cache,
        final TranscriptListener transcript, final Host bookmark) {
    this.connect = connect;
    this.registry = registry;
    this.cache = cache;
    this.bookmark = bookmark;
    this.transcript = transcript;
    final GenericObjectPoolConfig configuration = new GenericObjectPoolConfig();
    configuration.setJmxEnabled(false);/*from www  .  j a  v a2s .  c  o m*/
    configuration.setEvictionPolicyClassName(CustomPoolEvictionPolicy.class.getName());
    configuration.setBlockWhenExhausted(true);
    configuration.setMaxWaitMillis(BORROW_MAX_WAIT_INTERVAL);
    this.pool = new GenericObjectPool<Session>(
            new PooledSessionFactory(connect, trust, key, cache, bookmark, registry), configuration);
    final AbandonedConfig abandon = new AbandonedConfig();
    abandon.setUseUsageTracking(true);
    this.pool.setAbandonedConfig(abandon);
}

From source file:edu.harvard.hul.ois.fits.service.servlets.FitsServlet.java

public void init() throws ServletException {

    // "fits.home" property set differently in Tomcat 7 and JBoss 7.
    // Tomcat: set in catalina.properties
    // JBoss: set as a command line value "-Dfits.home=<path/to/fits/home>
    fitsHome = System.getProperty(FITS_HOME_SYSTEM_PROP_NAME);
    logger.info(FITS_HOME_SYSTEM_PROP_NAME + ": " + fitsHome);

    if (StringUtils.isEmpty(fitsHome)) {
        logger.fatal(FITS_HOME_SYSTEM_PROP_NAME
                + " system property HAS NOT BEEN SET!!! This web application will not properly run.");
        throw new ServletException(FITS_HOME_SYSTEM_PROP_NAME
                + " system property HAS NOT BEEN SET!!! This web application will not properly run.");
    }//  w ww  .ja  va2  s . c  o  m

    // Set the projects properties.
    // First look for a system property pointing to a project properties file. (e.g. - file:/path/to/file)
    // If this value either does not exist or is not valid, the default
    // file that comes with this application will be used for initialization.
    String environmentProjectPropsFile = System.getProperty(ENV_PROJECT_PROPS);
    logger.info(
            "Value of environment property: [ + ENV_PROJECT_PROPS + ] for finding external properties file in location: ["
                    + environmentProjectPropsFile + "]");
    if (environmentProjectPropsFile != null) {
        logger.info("Will look for properties file from environment in location: ["
                + environmentProjectPropsFile + "]");
        try {
            File projectProperties = new File(environmentProjectPropsFile);
            if (projectProperties.exists() && projectProperties.isFile() && projectProperties.canRead()) {
                InputStream is = new FileInputStream(projectProperties);
                applicationProps = new Properties();
                applicationProps.load(is);
            }
        } catch (IOException e) {
            // fall back to default file
            logger.error("Unable to load properties file: [" + environmentProjectPropsFile + "] -- reason: "
                    + e.getMessage(), e);
            logger.error("Falling back to default project.properties file: [" + PROPERTIES_FILE_NAME + "]");
            applicationProps = null;
        }
    }

    if (applicationProps == null) { // did not load from environment variable location
        try {
            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
            InputStream resourceStream = classLoader.getResourceAsStream(PROPERTIES_FILE_NAME);
            if (resourceStream != null) {
                applicationProps = new Properties();
                applicationProps.load(resourceStream);
                logger.info("loaded default applicationProps");
            } else {
                logger.warn("project.properties not found!!!");
            }
        } catch (IOException e) {
            logger.error("Could not load properties file: [" + PROPERTIES_FILE_NAME + "]", e);
            // couldn't load default properties so bail...
            throw new ServletException("Couldn't load an applications properties file.", e);
        }
    }
    int maxPoolSize = Integer
            .valueOf(applicationProps.getProperty("max.objects.in.pool", DEFAULT_MAX_OBJECTS_IN_POOL));
    maxFileUploadSizeMb = Long
            .valueOf(applicationProps.getProperty("max.upload.file.size.MB", DEFAULT_MAX_UPLOAD_SIZE));
    maxRequestSizeMb = Long
            .valueOf(applicationProps.getProperty("max.request.size.MB", DEFAULT_MAX_REQUEST_SIZE));
    maxInMemoryFileSizeMb = Integer
            .valueOf(applicationProps.getProperty("max.in.memory.file.size.MB", DEFAULT_IN_MEMORY_FILE_SIZE));
    logger.info("Max objects in object pool: " + maxPoolSize + " -- Max file upload size: "
            + maxFileUploadSizeMb + "MB -- Max request object size: " + maxRequestSizeMb
            + "MB -- Max in-memory file size: " + maxInMemoryFileSizeMb + "MB");

    logger.debug("Initializing FITS pool");
    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMinIdle(MIN_IDLE_OBJECTS_IN_POOL);
    poolConfig.setMaxTotal(maxPoolSize);
    poolConfig.setTestOnBorrow(true);
    poolConfig.setBlockWhenExhausted(true);
    fitsWrapperPool = new FitsWrapperPool(new FitsWrapperFactory(), poolConfig);
    logger.debug("FITS pool finished Initializing");

    String uploadBaseDirName = getServletContext().getRealPath("") + File.separator + UPLOAD_DIRECTORY;
    uploadBaseDir = new File(uploadBaseDirName);
    if (!uploadBaseDir.exists()) {
        uploadBaseDir.mkdir();
        logger.info("Created upload base directory: " + uploadBaseDir.getAbsolutePath());
    }
}