org.apache.openejb.util
Class Pool<T>

java.lang.Object
  extended by org.apache.openejb.util.Pool<T>

public class Pool<T>
extends java.lang.Object

Any successful pop() call requires a corresponding push() or discard() call.

A pop() call that returns null is considered successful. A null indicates that the calling code has a permit to create a poolable object and call push(Object). This is the only situation in which that method may be called.

To simply fill the pool without a corresponding pop(), the add() method must be used. This method will attempt to aquire a permit to add to the pool.

Version:
$Rev$ $Date$

Nested Class Summary
static class Pool.Builder<T>
           
 class Pool.Entry
           
static class Pool.Event
           
static class Pool.HardReference<T>
           
static interface Pool.Supplier<T>
           
 
Constructor Summary
Pool(int max, int min, boolean strict)
           
Pool(int max, int min, boolean strict, long maxAge, long idleTimeout, long sweepInterval, java.util.concurrent.Executor executor, Pool.Supplier<T> supplier, boolean replaceAged, double maxAgeOffset, boolean garbageCollection, boolean replaceFlushed)
           
 
Method Summary
 boolean add(T obj)
          Attempt to aquire a permit to add the object to the pool.
 boolean add(T obj, long offset)
          Attempt to aquire a permit to add the object to the pool.
 boolean close(long timeout, java.util.concurrent.TimeUnit unit)
           
 void discard()
          Used when a call to pop() was made that returned null indicating that the caller has a permit to create an object for this pool, but the caller will not be exercising that permit and wishes intstead to return "null" to the pool.
 void discard(Pool.Entry entry)
           
 void flush()
           
 Pool.Entry pop(long timeout, java.util.concurrent.TimeUnit unit)
          Any successful pop() call requires a corresponding push() or discard() call

A pop() call that returns null is considered successful.

 boolean push(Pool.Entry entry)
           
 boolean push(T obj)
          Never call this method without having successfully called pop(long, java.util.concurrent.TimeUnit) beforehand.
 boolean running()
           
 Pool start()
           
 void stop()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Pool

public Pool(int max,
            int min,
            boolean strict)

Pool

public Pool(int max,
            int min,
            boolean strict,
            long maxAge,
            long idleTimeout,
            long sweepInterval,
            java.util.concurrent.Executor executor,
            Pool.Supplier<T> supplier,
            boolean replaceAged,
            double maxAgeOffset,
            boolean garbageCollection,
            boolean replaceFlushed)
Method Detail

start

public Pool start()

stop

public void stop()

running

public boolean running()

flush

public void flush()

pop

public Pool.Entry pop(long timeout,
                      java.util.concurrent.TimeUnit unit)
               throws java.lang.InterruptedException,
                      java.util.concurrent.TimeoutException
Any successful pop() call requires a corresponding push() or discard() call

A pop() call that returns null is considered successful.

Parameters:
timeout - time to block while waiting for an instance
unit - unit of time dicated by the timeout
Returns:
an entry from the pool or null indicating permission to create and push() an instance into the pool
Throws:
java.lang.InterruptedException - vm level thread interruption
java.lang.IllegalStateException - if a permit could not be acquired
java.util.concurrent.TimeoutException - if no instance could be obtained within the timeout

add

public boolean add(T obj)
Attempt to aquire a permit to add the object to the pool.

Parameters:
obj - object to add to the pool
Returns:
true of the item as added

add

public boolean add(T obj,
                   long offset)
Attempt to aquire a permit to add the object to the pool.

Parameters:
obj - object to add to the pool
offset - creation time offset, used for maxAge
Returns:
true of the item as added

push

public boolean push(T obj)
Never call this method without having successfully called pop(long, java.util.concurrent.TimeUnit) beforehand.

Failure to do so will increase the max pool size by one.

Parameters:
obj - object to push onto the pool
Returns:
false if the pool max size was exceeded

push

public boolean push(Pool.Entry entry)

discard

public void discard()
Used when a call to pop() was made that returned null indicating that the caller has a permit to create an object for this pool, but the caller will not be exercising that permit and wishes intstead to return "null" to the pool.


discard

public void discard(Pool.Entry entry)

close

public boolean close(long timeout,
                     java.util.concurrent.TimeUnit unit)
              throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException


Copyright © 1999-2011 The Apache OpenEJB development community. All Rights Reserved.