Java Code Examples for org.apache.commons.pool.impl.GenericObjectPool#WHEN_EXHAUSTED_FAIL

The following examples show how to use org.apache.commons.pool.impl.GenericObjectPool#WHEN_EXHAUSTED_FAIL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceQueue.java    From datawave with Apache License 2.0 5 votes vote down vote up
public AccumuloResource getScannerResource() throws Exception {
    // let's grab an object from the pool,
    AccumuloResource resource = null;
    while (resource == null) {
        try {
            resource = scannerPool.borrowObject();
        } catch (NoSuchElementException nse) {
            if (type == GenericObjectPool.WHEN_EXHAUSTED_FAIL) {
                throw nse;
            }
        }
    }
    return resource;
}
 
Example 2
Source File: RDBMSTopicMapReference.java    From ontopia with Apache License 2.0 4 votes vote down vote up
protected void init() {
  // store factory
  TopicMapStoreFactoryIF sfactory = new TopicMapStoreFactoryIF() {
    @Override
    public TopicMapStoreIF createStore() {
     return _createStore(false);
    }
  };

  // initialize pool
  this.ofactory = new StorePoolableObjectFactory(sfactory);
  this.pool = new GenericObjectPool(ofactory);
  this.pool.setTestOnBorrow(true);

  Map<String, String> properties = storage.getProperties();
  if (properties != null) {
    // Set minimum pool size (default: 0)
    String _minsize = PropertyUtils.getProperty(properties,
        "net.ontopia.topicmaps.impl.rdbms.StorePool.MinimumSize", false);
    int minsize = (_minsize == null ? 0 : Integer.parseInt(_minsize));
    log.debug("Setting StorePool.MinimumSize '" + minsize + "'");
    pool.setMinIdle(minsize); // 0 = no limit

    // Set maximum pool size (default: Integer.MAX_VALUE)
    String _maxsize = PropertyUtils.getProperty(properties,
        "net.ontopia.topicmaps.impl.rdbms.StorePool.MaximumSize", false);
    int maxsize = (_maxsize == null ? 8 : Integer.parseInt(_maxsize));
    log.debug("Setting StorePool.MaximumSize '" + maxsize + "'");
    pool.setMaxActive(maxsize); // 0 = no limit

    // Set soft maximum - emergency objects (default: false)
    boolean softmax = MapUtils.getBoolean(properties, "net.ontopia.topicmaps.impl.rdbms.StorePool.SoftMaximum", false);
    log.debug("Setting StorePool.SoftMaximum '" + softmax + "'");
    if (softmax)
      pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_GROW);
    else
      pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK);
    
    // EXPERIMENTAL!
    String _etime = PropertyUtils.getProperty(properties, "net.ontopia.topicmaps.impl.rdbms.StorePool.IdleTimeout", false);
    int etime = (_etime == null ? -1 : Integer.parseInt(_etime));
    pool.setTimeBetweenEvictionRunsMillis(etime);
    pool.setSoftMinEvictableIdleTimeMillis(etime);
  }

  // allow the user to fully overwrite exhausted options
  String _whenExhaustedAction = PropertyUtils.getProperty(properties, "net.ontopia.topicmaps.impl.rdbms.StorePool.WhenExhaustedAction", false);
  if (EXHAUSED_BLOCK.equals(_whenExhaustedAction))
    pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK);
  if (EXHAUSED_GROW.equals(_whenExhaustedAction))
    pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_GROW);
  if (EXHAUSED_FAIL.equals(_whenExhaustedAction))
    pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_FAIL);

  if (pool.getWhenExhaustedAction() == GenericObjectPool.WHEN_EXHAUSTED_BLOCK)
    log.debug("Pool is set to block on exhaused");
  if (pool.getWhenExhaustedAction() == GenericObjectPool.WHEN_EXHAUSTED_GROW)
    log.debug("Pool is set to grow on exhaused");
  if (pool.getWhenExhaustedAction() == GenericObjectPool.WHEN_EXHAUSTED_FAIL)
    log.debug("Pool is set to fail on exhaused");

}