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, 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: 779038 $

Field Summary
protected  int capacity
           
protected  org.apache.commons.logging.Log log
           
protected  ConcurrentHashMap<Key,BlockingQueue<Service>> pool
           
 
Constructor Summary
DefaultServicePool(int capacity)
          The capacity, note this is per key.
 
Method Summary
 Service acquire(Key key)
          Tries to acquire the servie 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()
           
 void release(Key key, Service service)
          Releases the service back to the pool
 
Methods inherited from class org.apache.camel.impl.ServiceSupport
addChildService, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, removeChildService, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.camel.Service
start, stop
 

Field Detail

log

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

pool

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

capacity

protected final int capacity
Constructor Detail

DefaultServicePool

public DefaultServicePool(int capacity)
The capacity, note this is per key.

Parameters:
capacity - the capacity per key.
Method Detail

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 servie 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