org.apache.camel.impl
Class ProducerCache

java.lang.Object
  extended by org.apache.camel.support.ServiceSupport
      extended by org.apache.camel.impl.ProducerCache
All Implemented Interfaces:
Service, ShutdownableService, StatefulService, SuspendableService

public class ProducerCache
extends ServiceSupport

Cache containing created Producer.

Version:

Field Summary
 
Fields inherited from class org.apache.camel.support.ServiceSupport
shutdown, shuttingdown, started, starting, stopped, stopping, suspended, suspending
 
Constructor Summary
ProducerCache(Object source, CamelContext camelContext)
           
ProducerCache(Object source, CamelContext camelContext, int cacheSize)
           
ProducerCache(Object source, CamelContext camelContext, Map<String,Producer> cache)
           
ProducerCache(Object source, CamelContext camelContext, ServicePool<Endpoint,Producer> producerServicePool, Map<String,Producer> cache)
           
 
Method Summary
 Producer acquireProducer(Endpoint endpoint)
          Acquires a pooled producer which you must release back again after usage using the releaseProducer(org.apache.camel.Endpoint, org.apache.camel.Producer) method.
protected static LRUCache<String,Producer> createLRUCache(int cacheSize)
          Creates the LRUCache to be used.
protected  Producer doGetProducer(Endpoint endpoint, boolean pooled)
           
 boolean doInAsyncProducer(Endpoint endpoint, Exchange exchange, ExchangePattern pattern, AsyncCallback callback, AsyncProducerCallback producerCallback)
          Sends an exchange to an endpoint using a supplied callback supporting the asynchronous routing engine.
<T> T
doInProducer(Endpoint endpoint, Exchange exchange, ExchangePattern pattern, ProducerCallback<T> callback)
          Sends an exchange to an endpoint using a supplied callback, using the synchronous processing.
protected  void doStart()
          Implementations override this method to support customized start/stop.
protected  void doStop()
          Implementations override this method to support customized start/stop.
 CamelContext getCamelContext()
           
 int getCapacity()
          Gets the maximum cache size (capacity).
 long getEvicted()
          Gets the cache evicted statistic

Will return -1 if it cannot determine this if a custom cache was used.

 long getHits()
          Gets the cache hits statistic

Will return -1 if it cannot determine this if a custom cache was used.

 long getMisses()
          Gets the cache misses statistic

Will return -1 if it cannot determine this if a custom cache was used.

 Object getSource()
          Gets the source which uses this cache
 void purge()
          Purges this cache
 void releaseProducer(Endpoint endpoint, Producer producer)
          Releases an acquired producer back after usage.
 void resetCacheStatistics()
          Resets the cache statistics
 void send(Endpoint endpoint, Exchange exchange)
          Sends the exchange to the given endpoint.
 Exchange send(Endpoint endpoint, ExchangePattern pattern, Processor processor)
          Sends an exchange to an endpoint using a supplied Processor to populate the exchange
 Exchange send(Endpoint endpoint, Processor processor)
          Sends an exchange to an endpoint using a supplied Processor to populate the exchange
protected  Exchange sendExchange(Endpoint endpoint, ExchangePattern pattern, Processor processor, Exchange exchange)
           
 int size()
          Returns the current size of the cache
 void startProducer(Endpoint endpoint)
          Starts the Producer to be used for sending to the given endpoint

This can be used to early start the Producer to ensure it can be created, such as when Camel is started.

 String toString()
           
 
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, wait, wait, wait
 

Constructor Detail

ProducerCache

public ProducerCache(Object source,
                     CamelContext camelContext)

ProducerCache

public ProducerCache(Object source,
                     CamelContext camelContext,
                     int cacheSize)

ProducerCache

public ProducerCache(Object source,
                     CamelContext camelContext,
                     Map<String,Producer> cache)

ProducerCache

public ProducerCache(Object source,
                     CamelContext camelContext,
                     ServicePool<Endpoint,Producer> producerServicePool,
                     Map<String,Producer> cache)
Method Detail

createLRUCache

protected static LRUCache<String,Producer> createLRUCache(int cacheSize)
Creates the LRUCache to be used.

This implementation returns a LRUCache instance.

Parameters:
cacheSize - the cache size
Returns:
the cache

getCamelContext

public CamelContext getCamelContext()

getSource

public Object getSource()
Gets the source which uses this cache

Returns:
the source

acquireProducer

public Producer acquireProducer(Endpoint endpoint)
Acquires a pooled producer which you must release back again after usage using the releaseProducer(org.apache.camel.Endpoint, org.apache.camel.Producer) method.

Parameters:
endpoint - the endpoint
Returns:
the producer

releaseProducer

public void releaseProducer(Endpoint endpoint,
                            Producer producer)
                     throws Exception
Releases an acquired producer back after usage.

Parameters:
endpoint - the endpoint
producer - the producer to release
Throws:
Exception - can be thrown if error stopping producer if that was needed.

startProducer

public void startProducer(Endpoint endpoint)
                   throws Exception
Starts the Producer to be used for sending to the given endpoint

This can be used to early start the Producer to ensure it can be created, such as when Camel is started. This allows to fail fast in case the Producer could not be started.

Parameters:
endpoint - the endpoint to send the exchange to
Throws:
Exception - is thrown if failed to create or start the Producer

send

public void send(Endpoint endpoint,
                 Exchange exchange)
Sends the exchange to the given endpoint.

This method will not throw an exception. If processing of the given Exchange failed then the exception is stored on the provided Exchange

Parameters:
endpoint - the endpoint to send the exchange to
exchange - the exchange to send

send

public Exchange send(Endpoint endpoint,
                     Processor processor)
Sends an exchange to an endpoint using a supplied Processor to populate the exchange

This method will not throw an exception. If processing of the given Exchange failed then the exception is stored on the return Exchange

Parameters:
endpoint - the endpoint to send the exchange to
processor - the transformer used to populate the new exchange
Returns:
the exchange
Throws:
CamelExecutionException - is thrown if sending failed

send

public Exchange send(Endpoint endpoint,
                     ExchangePattern pattern,
                     Processor processor)
Sends an exchange to an endpoint using a supplied Processor to populate the exchange

This method will not throw an exception. If processing of the given Exchange failed then the exception is stored on the return Exchange

Parameters:
endpoint - the endpoint to send the exchange to
pattern - the message ExchangePattern such as ExchangePattern.InOnly or ExchangePattern.InOut
processor - the transformer used to populate the new exchange
Returns:
the exchange

doInProducer

public <T> T doInProducer(Endpoint endpoint,
                          Exchange exchange,
                          ExchangePattern pattern,
                          ProducerCallback<T> callback)
Sends an exchange to an endpoint using a supplied callback, using the synchronous processing.

If an exception was thrown during processing, it would be set on the given Exchange

Parameters:
endpoint - the endpoint to send the exchange to
exchange - the exchange, can be null if so then create a new exchange from the producer
pattern - the exchange pattern, can be null
callback - the callback
Returns:
the response from the callback
See Also:
doInAsyncProducer(org.apache.camel.Endpoint, org.apache.camel.Exchange, org.apache.camel.ExchangePattern, org.apache.camel.AsyncCallback, org.apache.camel.AsyncProducerCallback)

doInAsyncProducer

public boolean doInAsyncProducer(Endpoint endpoint,
                                 Exchange exchange,
                                 ExchangePattern pattern,
                                 AsyncCallback callback,
                                 AsyncProducerCallback producerCallback)
Sends an exchange to an endpoint using a supplied callback supporting the asynchronous routing engine.

If an exception was thrown during processing, it would be set on the given Exchange

Parameters:
endpoint - the endpoint to send the exchange to
exchange - the exchange, can be null if so then create a new exchange from the producer
pattern - the exchange pattern, can be null
callback - the asynchronous callback
producerCallback - the producer template callback to be executed
Returns:
(doneSync) true to continue execute synchronously, false to continue being executed asynchronously

sendExchange

protected Exchange sendExchange(Endpoint endpoint,
                                ExchangePattern pattern,
                                Processor processor,
                                Exchange exchange)

doGetProducer

protected Producer doGetProducer(Endpoint endpoint,
                                 boolean pooled)

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()

size

public int size()
Returns the current size of the cache

Returns:
the current size

getCapacity

public int getCapacity()
Gets the maximum cache size (capacity).

Will return -1 if it cannot determine this if a custom cache was used.

Returns:
the capacity

getHits

public long getHits()
Gets the cache hits statistic

Will return -1 if it cannot determine this if a custom cache was used.

Returns:
the hits

getMisses

public long getMisses()
Gets the cache misses statistic

Will return -1 if it cannot determine this if a custom cache was used.

Returns:
the misses

getEvicted

public long getEvicted()
Gets the cache evicted statistic

Will return -1 if it cannot determine this if a custom cache was used.

Returns:
the evicted

resetCacheStatistics

public void resetCacheStatistics()
Resets the cache statistics


purge

public void purge()
Purges this cache


toString

public String toString()
Overrides:
toString in class Object


Apache CAMEL