Example usage for org.apache.commons.pool.impl GenericObjectPool GenericObjectPool

List of usage examples for org.apache.commons.pool.impl GenericObjectPool GenericObjectPool

Introduction

In this page you can find the example usage for org.apache.commons.pool.impl GenericObjectPool GenericObjectPool.

Prototype

public GenericObjectPool(PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait,
        int maxIdle, int minIdle, boolean testOnBorrow, boolean testOnReturn,
        long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis,
        boolean testWhileIdle, long softMinEvictableIdleTimeMillis, boolean lifo) 

Source Link

Document

Create a new GenericObjectPool using the specified values.

Usage

From source file:org.ow2.petals.binding.soap.SoapComponentContext.java

/**
 * <p>/* www.  j ava2s . c  o m*/
 * Get a service client associated to an axis service set with the good
 * operation. It is taken from a pool object.
 * </p>
 * <p>
 * <b>This service client must be returned to the pool after usage using
 * API:
 * <code>{@link #returnServiceClient(String, QName, URI, ServiceClient)}</code>
 * .</b>
 * </p>
 * 
 * @param address
 *            the address of the service, mainly used as key to retrieve the
 *            associated SU.
 * @param operation
 *            the target operation QName. Non null
 * @param mep
 *            the message exchange pattern used. Non null
 * @param cdkExtensions
 *            SU extensions used by the service client pool when the
 *            creation of a service client is needed
 * @param provides
 *            the provides block of the endpoint which is creating the
 *            external WS call
 * @param ramprtUserName 
 * @return a ServiceClient. Not null. Must be returned to the pool after
 *         usage using API:
 *         <code>{@link #returnServiceClient(String, QName, URI, ServiceClient)}</code>
 * @throws HandlingException
 */
public ServiceClient borrowServiceClient(final String address, final QName operation, final String soapAction,
        final URI mep, final ConfigurationExtensions cdkExtensions, final Provides provides,
        String rampartUserName) throws MessagingException {

    try {

        String resolvedOp;
        if (operation != null) {
            resolvedOp = operation.toString();
        } else if (soapAction != null) {
            resolvedOp = soapAction;
        } else {
            throw new MessagingException(
                    "Unable to resolve the operation. Set it in the Jbi exchange or SoapAction.");
        }

        final ServiceClientKey key = new ServiceClientKey(address, resolvedOp, mep);
        ObjectPool pool = this.serviceClientPools.get(key);
        if (pool == null) {
            // TODO: The pool max size should be limited by the JBI worker
            // number
            pool = new GenericObjectPool(
                    // object factory
                    new ServiceClientPoolObjectFactory(address, operation, mep, cdkExtensions, this, provides,
                            this.logger, soapAction, rampartUserName),

                    // max number of borrowed object sized to the number of
                    // JBI message processors
                    this.componentConfiguration.getProcessorPoolSize().getValue(),

                    // getting an object blocks until a new or idle object
                    // is available
                    GenericObjectPool.WHEN_EXHAUSTED_BLOCK,

                    // if getting an object is blocked for at most this
                    // delay, a NoSuchElementException will be thrown. In
                    // case of a synchronous call the delay is sized to the
                    // value of the SU's parameter "synchronous-timeout",
                    // otherwise it sized to 5 minutes.
                    MEPConstants.IN_OUT_PATTERN.equals(mep) || MEPConstants.IN_OPTIONAL_OUT_PATTERN.equals(mep)
                            ? SUPropertiesHelper.retrieveTimeout(cdkExtensions)
                            : 300000l,

                    // max number of idle object in the pool. Sized to the
                    // number of JBI acceptors.
                    this.componentConfiguration.getAcceptorPoolSize().getValue(),

                    // min number of idle object in the pool. Sized to 0
                    // (ie when no activity no object in pool)
                    GenericObjectPool.DEFAULT_MIN_IDLE,

                    // no validation test of the borrowed object
                    false,

                    // no validation test of the returned object
                    false,

                    // how long the eviction thread should sleep before
                    // "runs" of examining idle objects. Sized to 5min.
                    300000l,

                    // the number of objects examined in each run of the
                    // idle object evictor. Size to the default value (ie.
                    // 3)
                    GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,

                    // the minimum amount of time that an object may sit
                    // idle in the pool before it is eligible for eviction
                    // due to idle time. Sized to 30min
                    GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,

                    // no validation test of the idle object
                    false,

                    // the minimum amount of time an object may sit idle in
                    // the pool before it is eligible for eviction by the
                    // idle object evictor (if any), with the extra
                    // condition that at least "minIdle" amount of object
                    // remain in the pool.
                    GenericObjectPool.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS,

                    // the pool returns idle objects in last-in-first-out
                    // order
                    true);

            this.serviceClientPools.put(key, pool);
        }

        return (ServiceClient) pool.borrowObject();

    } catch (final Exception e) {
        throw new MessagingException("Can't create get an Axis service client from the pool", e);
    }
}

From source file:org.ow2.petals.binding.soapproxy.SoapComponentContext.java

/**
 * <p>//from  w  w  w . j av  a 2  s. c  o m
 * Get a service client associated to an axis service set with the good
 * operation. It is taken from a pool object.
 * </p>
 * <p>
 * <b>This service client must be returned to the pool after usage using
 * API:
 * <code>{@link #returnServiceClient(String, QName, URI, ServiceClient)}</code>
 * .</b>
 * </p>
 * 
 * @param address
 *            the address of the service, mainly used as key to retrieve the
 *            associated SU.
 * @param operation
 *            the target operation QName. Non null
 * @param mep
 *            the message exchange pattern used. Non null
 * @param cdkExtensions
 *            SU extensions used by the service client pool when the
 *            creation of a service client is needed
 * @param provides
 *            the provides block of the endpoint which is creating the
 *            external WS call
 * @param ramprtUserName
 * @return a ServiceClient. Not null. Must be returned to the pool after
 *         usage using API:
 *         <code>{@link #returnServiceClient(String, QName, URI, ServiceClient)}</code>
 * @throws HandlingException
 */
public ServiceClient borrowServiceClient(final String address, final QName operation, final String soapAction,
        final URI mep) throws MessagingException {

    try {

        String resolvedOp;
        if (operation != null) {
            resolvedOp = operation.toString();
        } else if (soapAction != null) {
            resolvedOp = soapAction;
        } else {
            throw new MessagingException(
                    "Unable to resolve the operation. Set it in the Jbi exchange or SoapAction.");
        }

        final ServiceClientKey key = new ServiceClientKey(address, resolvedOp, mep);
        ObjectPool pool = this.serviceClientPools.get(key);
        if (pool == null) {
            // TODO: The pool max size should be limited by the JBI worker
            // number
            pool = new GenericObjectPool(
                    // object factory
                    new ServiceClientPoolObjectFactory(address, operation, mep, this, this.logger, soapAction),

                    // max number of borrowed object sized to the number of
                    // JBI message processors
                    this.componentConfiguration.getProcessorPoolSize().getValue(),

                    // getting an object blocks until a new or idle object
                    // is available
                    GenericObjectPool.WHEN_EXHAUSTED_BLOCK,

                    // if getting an object is blocked for at most this
                    // delay, a NoSuchElementException will be thrown. In
                    // case of a synchronous call the delay is sized to the
                    // value of the SU's parameter "synchronous-timeout",
                    // otherwise it sized to 5 minutes.
                    MEPConstants.IN_OUT_PATTERN.equals(mep) || MEPConstants.IN_OPTIONAL_OUT_PATTERN.equals(mep)
                            ? 300000l
                            : 300000l,

                    // max number of idle object in the pool. Sized to the
                    // number of JBI acceptors.
                    this.componentConfiguration.getAcceptorPoolSize().getValue(),

                    // min number of idle object in the pool. Sized to 0
                    // (ie when no activity no object in pool)
                    GenericObjectPool.DEFAULT_MIN_IDLE,

                    // no validation test of the borrowed object
                    false,

                    // no validation test of the returned object
                    false,

                    // how long the eviction thread should sleep before
                    // "runs" of examining idle objects. Sized to 5min.
                    300000l,

                    // the number of objects examined in each run of the
                    // idle object evictor. Size to the default value (ie.
                    // 3)
                    GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,

                    // the minimum amount of time that an object may sit
                    // idle in the pool before it is eligible for eviction
                    // due to idle time. Sized to 30min
                    GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,

                    // no validation test of the idle object
                    false,

                    // the minimum amount of time an object may sit idle in
                    // the pool before it is eligible for eviction by the
                    // idle object evictor (if any), with the extra
                    // condition that at least "minIdle" amount of object
                    // remain in the pool.
                    GenericObjectPool.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS,

                    // the pool returns idle objects in last-in-first-out
                    // order
                    true);

            this.serviceClientPools.put(key, pool);
        }

        return (ServiceClient) pool.borrowObject();

    } catch (final Exception e) {
        throw new MessagingException("Can't create get an Axis service client from the pool", e);
    }
}