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

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

Introduction

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

Prototype

public void setTestOnBorrow(boolean testOnBorrow) 

Source Link

Document

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

Usage

From source file:com.gxl.test.shark.resource.redisSetData.java

public @BeforeClass static void init() {
    GenericObjectPoolConfig cfg = new GenericObjectPoolConfig();
    cfg.setMaxIdle(10);//from  w w w  .j av a 2  s . c  om
    cfg.setMinIdle(1);
    cfg.setMaxIdle(5);
    cfg.setMaxWaitMillis(5000);
    cfg.setTestOnBorrow(true);
    cfg.setTestOnReturn(true);
    Set<HostAndPort> hostAndPorts = new HashSet<HostAndPort>();
    HostAndPort hostAndPort = new HostAndPort("120.24.75.22", 7000);
    hostAndPorts.add(hostAndPort);
    jedis = new JedisCluster(hostAndPorts, cfg);
}

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 ava  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;/* w  w w  .ja  v a2  s  .c o  m*/
    genericObjectPoolConfig.setMaxTotal(START_POOL_SIZE);
    genericObjectPoolConfig.setMaxIdle(START_POOL_SIZE);
    return genericObjectPoolConfig;
}

From source file:com.kurento.kmf.thrift.pool.AbstractPool.java

protected void init(BasePooledObjectFactory<T> factory) {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMinIdle(apiConfig.getClientPoolSize());
    config.setTestOnBorrow(true);
    config.setTestOnReturn(true);/*from w ww .j a v a  2 s.  c o  m*/
    this.pool = PoolUtils.erodingPool(new GenericObjectPool<>(factory, 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
 *//* w  ww. j  a v  a2s.co  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: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  . j  av a 2 s  .  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:com.lambdaworks.redis.RedisConnectionPool.java

/**
 * Create a new connection pool/*from w ww . j a  v  a  2s  . com*/
 * 
 * @param redisConnectionProvider the connection provider
 * @param maxActive max active connections
 * @param maxIdle max idle connections
 * @param maxWait max wait time (ms) for a connection
 */
public RedisConnectionPool(RedisConnectionProvider<T> redisConnectionProvider, int maxActive, int maxIdle,
        long maxWait) {
    this.redisConnectionProvider = redisConnectionProvider;

    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxIdle(maxIdle);
    config.setMaxTotal(maxActive);
    config.setMaxWaitMillis(maxWait);
    config.setTestOnBorrow(true);

    objectPool = new GenericObjectPool<>(createFactory(redisConnectionProvider), config);
}

From source file:com.mirth.connect.connectors.file.FileConnector.java

/**
 * Gets the pool of connections to the "server" for the specified endpoint, creating the pool if
 * necessary.//ww w  .  j ava2  s.c  om
 * 
 * @param uri
 *            The URI of the endpoint the created pool should be associated with.
 * @param message
 *            ???
 * @return The pool of connections for this endpoint.
 */
private synchronized ObjectPool<FileSystemConnection> getConnectionPool(
        FileSystemConnectionOptions fileSystemOptions) throws Exception {
    FileSystemConnectionFactory fileSystemConnectionFactory = getFileSystemConnectionFactory(fileSystemOptions);
    String key = fileSystemConnectionFactory.getPoolKey();
    ObjectPool<FileSystemConnection> pool = pools.get(key);

    if (pool == null) {
        GenericObjectPoolConfig config = new GenericObjectPoolConfig();
        if (isValidateConnection()) {
            config.setTestOnBorrow(true);
            config.setTestOnReturn(true);
        }
        pool = new GenericObjectPool<FileSystemConnection>(fileSystemConnectionFactory, config);

        pools.put(key, pool);
    }
    return pool;
}

From source file:com.zxy.commons.redis.RedisPoolFactory.java

private RedisPoolFactory() {
    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMaxIdle(RedisPropUtils.getMaxIdle());
    poolConfig.setMinIdle(RedisPropUtils.getMinIdle());
    poolConfig.setMaxTotal(RedisPropUtils.getMaxTotal());
    poolConfig.setMaxWaitMillis(RedisPropUtils.getMaxWaitMillis());
    poolConfig.setTimeBetweenEvictionRunsMillis(RedisPropUtils.getTimeBetweenEvictionRunsMillis());
    poolConfig.setMinEvictableIdleTimeMillis(RedisPropUtils.getMinEvictableIdleTimeMillis());
    poolConfig.setTestWhileIdle(RedisPropUtils.getTestWhileIdle());
    poolConfig.setTestOnBorrow(RedisPropUtils.getTestOnBorrow());

    Set<String> hosts = RedisPropUtils.getServers();
    if (hosts.size() > 1) {
        throw new IllegalArgumentException("ip port??!");
    }//w  w w .  j  av  a 2  s .  c om
    HostAndPort hostAndPort = RedisPropUtils.getServer();
    int timeout = RedisPropUtils.getTimeout();
    this.jedisPool = new JedisPool(poolConfig, hostAndPort.getHost(), hostAndPort.getPort(), timeout);
}

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 w  w.jav  a 2 s.  co  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());
    }
}