org.vibur.objectpool.util.ConcurrentCollection Java Examples

The following examples show how to use org.vibur.objectpool.util.ConcurrentCollection. 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: ConcurrentPool.java    From vibur-object-pool with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new {@code ConcurrentPool} with the given {@link PoolObjectFactory}, initial and max sizes,
 * and fairness setting.
 *
 * @param available         the concurrent collection that will store the pooled objects;
 *                          it must be an empty collection or a collection pre-initialized with
 *                          {@code initialSize} objects
 * @param poolObjectFactory the factory which will be used to create new objects
 *                          in this object pool as well as to control their lifecycle
 * @param initialSize       the object pool initial size, i.e. the initial number of
 *                          allocated in the object pool objects; this parameter never changes
 * @param maxSize           the object pool max size, i.e. the max number of allocated
 *                          in the object pool objects; this parameter never changes
 * @param fair              the object pool fairness setting with regards to waiting threads
 * @param listener          if not {@code null}, this listener instance methods will be called
 *                          when the pool executes {@code take} or {@code restore} operations
 * @throws IllegalArgumentException if one of the following holds:<br>
 *         {@code initialSize < 0 || maxSize < 1 || maxSize < initialSize}
 * @throws NullPointerException if {@code available} or {@code poolObjectFactory} are null
 */
public ConcurrentPool(ConcurrentCollection<T> available, PoolObjectFactory<T> poolObjectFactory,
                      int initialSize, int maxSize, boolean fair, Listener<T> listener) {
    forbidIllegalArgument(initialSize < 0, "initialSize");
    forbidIllegalArgument(maxSize < 1 || maxSize < initialSize || maxSize > MAX_ALLOWED_SIZE, "maxSize");
    int availableSize = available.size();
    forbidIllegalArgument(availableSize != 0 && availableSize != initialSize, "available");

    this.available = requireNonNull(available);
    this.poolObjectFactory = requireNonNull(poolObjectFactory);
    this.listener = listener;

    this.initialSize = initialSize;
    this.maxSize = maxSize;
    this.takeSemaphore = new Semaphore(maxSize, fair);

    this.createdTotal = new AtomicInteger(availableSize);
    if (availableSize == 0) {
        addInitialObjects();
    }
}
 
Example #2
Source File: ViburConfig.java    From vibur-dbcp with Apache License 2.0 4 votes vote down vote up
protected ConcurrentCollection<ConnHolder> getConcurrentCollection() {
    return concurrentCollection;
}
 
Example #3
Source File: ViburConfig.java    From vibur-dbcp with Apache License 2.0 4 votes vote down vote up
protected void setConcurrentCollection(ConcurrentCollection<ConnHolder> concurrentCollection) {
    this.concurrentCollection = concurrentCollection;
}
 
Example #4
Source File: ConcurrentPool.java    From vibur-object-pool with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new {@code ConcurrentPool} with the given {@link PoolObjectFactory}, initial and max sizes,
 * and fairness setting.
 *
 * @param available         the concurrent collection that will store the pooled objects;
 *                          it must be an empty collection or a collection pre-initialized with
 *                          {@code initialSize} objects
 * @param poolObjectFactory the factory which will be used to create new objects
 *                          in this object pool as well as to control their lifecycle
 * @param initialSize       the object pool initial size, i.e. the initial number of
 *                          allocated in the object pool objects; this parameter never changes
 * @param maxSize           the object pool max size, i.e. the max number of allocated
 *                          in the object pool objects; this parameter never changes
 * @param fair              the object pool fairness setting with regards to waiting threads
 * @throws IllegalArgumentException if one of the following holds:<br>
 *         {@code initialSize < 0 || maxSize < 1 || maxSize < initialSize}
 * @throws NullPointerException if {@code available} or {@code poolObjectFactory} are null
 */
public ConcurrentPool(ConcurrentCollection<T> available, PoolObjectFactory<T> poolObjectFactory,
                      int initialSize, int maxSize, boolean fair) {
    this(available, poolObjectFactory, initialSize, maxSize, fair, null);
}