org.apache.camel.impl
Class DefaultServicePool<Key,Service>

java.lang.Object
  extended by org.apache.camel.impl.ServiceSupport
      extended by org.apache.camel.impl.DefaultServicePool<Key,Service>
All Implemented Interfaces:
Service, ShutdownableService, ServicePool<Key,Service>
Direct Known Subclasses:
DefaultProducerServicePool

public abstract class DefaultServicePool<Key,Service>
extends ServiceSupport
implements ServicePool<Key,Service>

Default implementation to inherit for a basic service pool.

Version:
$Revision: 931456 $

Field Summary
protected  int capacity
           
protected  org.apache.commons.logging.Log log
           
protected  ConcurrentHashMap<Key,BlockingQueue<Service>> pool
           
 
Constructor Summary
protected DefaultServicePool()
           
  DefaultServicePool(int capacity)
           
 
Method Summary
 Service acquire(Key key)
          Tries to acquire the service with the given key
 Service addAndAcquire(Key key, Service service)
          Adds the given service to the pool and acquires it.
protected  void doStart()
           
protected  void doStop()
           
 int getCapacity()
          Gets the capacity per key.
 void release(Key key, Service service)
          Releases the service back to the pool
 void setCapacity(int capacity)
          Sets the capacity, which is capacity per key.
 int size()
          Returns the current size of the pool
 
Methods inherited from class org.apache.camel.impl.ServiceSupport
addChildService, doResume, doShutdown, doSuspend, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspended, isSuspending, removeChildService, resume, shutdown, start, start, stop, suspend
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected final org.apache.commons.logging.Log log

pool

protected final ConcurrentHashMap<Key,BlockingQueue<Service>> pool

capacity

protected int capacity
Constructor Detail

DefaultServicePool

protected DefaultServicePool()

DefaultServicePool

public DefaultServicePool(int capacity)
Method Detail

getCapacity

public int getCapacity()
Description copied from interface: ServicePool
Gets the capacity per key.

Specified by:
getCapacity in interface ServicePool<Key,Service>
Returns:
the capacity per key

setCapacity

public void setCapacity(int capacity)
Description copied from interface: ServicePool
Sets the capacity, which is capacity per key.

Specified by:
setCapacity in interface ServicePool<Key,Service>
Parameters:
capacity - the capacity per key

size

public int size()
Description copied from interface: ServicePool
Returns the current size of the pool

Specified by:
size in interface ServicePool<Key,Service>
Returns:
the current size of the pool

addAndAcquire

public Service addAndAcquire(Key key,
                             Service service)
Description copied from interface: ServicePool
Adds the given service to the pool and acquires it.

Specified by:
addAndAcquire in interface ServicePool<Key,Service>
Parameters:
key - the key
service - the service
Returns:
the acquired service, is newer null

acquire

public Service acquire(Key key)
Description copied from interface: ServicePool
Tries to acquire the service with the given key

Specified by:
acquire in interface ServicePool<Key,Service>
Parameters:
key - the key
Returns:
the acquired service, or null if no free in pool

release

public void release(Key key,
                    Service service)
Description copied from interface: ServicePool
Releases the service back to the pool

Specified by:
release in interface ServicePool<Key,Service>
Parameters:
key - the key
service - the service

doStart

protected void doStart()
                throws Exception
Specified by:
doStart in class ServiceSupport
Throws:
Exception

doStop

protected void doStop()
               throws Exception
Specified by:
doStop in class ServiceSupport
Throws:
Exception


Apache CAMEL