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

java.lang.Object
  extended by org.apache.camel.support.ServiceSupport
      extended by org.apache.camel.impl.DefaultServicePool<Key,Service>
All Implemented Interfaces:
Service, ShutdownableService, ServicePool<Key,Service>, StatefulService, SuspendableService
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:

Field Summary
protected  int capacity
           
protected  org.slf4j.Logger log
           
protected  ConcurrentMap<Key,BlockingQueue<Service>> pool
           
 
Fields inherited from class org.apache.camel.support.ServiceSupport
shutdown, shuttingdown, started, starting, stopped, stopping, suspended, suspending
 
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()
          Implementations override this method to support customized start/stop.
protected  void doStop()
          Implementations override this method to support customized start/stop.
 int getCapacity()
          Gets the capacity per key.
 void purge()
          Purges the pool.
 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.support.ServiceSupport
doResume, doShutdown, doSuspend, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspended, isSuspending, resume, shutdown, 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.slf4j.Logger log

pool

protected final ConcurrentMap<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

purge

public void purge()
Description copied from interface: ServicePool
Purges the pool.

Specified by:
purge in interface ServicePool<Key,Service>

doStart

protected void doStart()
                throws Exception
Description copied from class: ServiceSupport
Implementations override this method to support customized start/stop.

Important: See ServiceSupport.doStop() for more details.

Specified by:
doStart in class ServiceSupport
Throws:
Exception
See Also:
ServiceSupport.doStop()

doStop

protected void doStop()
               throws Exception
Description copied from class: ServiceSupport
Implementations override this method to support customized start/stop.

Important: Camel will invoke this ServiceSupport.doStop() method when the service is being stopped. This method will also be invoked if the service is still in uninitialized state (eg has not been started). The method is always called to allow the service to do custom logic when the service is being stopped, such as when CamelContext is shutting down.

Specified by:
doStop in class ServiceSupport
Throws:
Exception
See Also:
ServiceSupport.doStart()


Apache CAMEL