org.apache.camel.impl
Class ProducerCache

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

public class ProducerCache
extends ServiceSupport

Cache containing created Producer.

Version:
$Revision: 937935 $

Constructor Summary
ProducerCache(Object source, CamelContext camelContext)
           
ProducerCache(Object source, CamelContext camelContext, int cacheSize)
           
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  Producer doGetProducer(Endpoint endpoint, boolean pooled)
           
<T> T
doInProducer(Endpoint endpoint, Exchange exchange, ExchangePattern pattern, ProducerCallback<T> callback)
          Sends an exchange to an endpoint using a supplied callback
protected  void doStart()
           
protected  void doStop()
           
 CamelContext getCamelContext()
           
 int getCapacity()
          Gets the maximum cache size (capacity).
 Object getSource()
          Gets the source which uses this cache
 void releaseProducer(Endpoint endpoint, Producer producer)
          Releases an acquired producer back after usage.
 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
 String toString()
           
 
Methods inherited from class org.apache.camel.impl.ServiceSupport
addChildService, doShutdown, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, removeChildService, shutdown, start, stop
 
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,
                     ServicePool<Endpoint,Producer> producerServicePool,
                     Map<String,Producer> cache)
Method Detail

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.

send

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

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

Parameters:
endpoint - the endpoint to send the exchange to
processor - the transformer used to populate the new exchange
Returns:
the exchange

send

public Exchange send(Endpoint endpoint,
                     ExchangePattern pattern,
                     Processor processor)
Sends an exchange to an endpoint using a supplied Processor to populate the 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)
               throws Exception
Sends an exchange to an endpoint using a supplied callback

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
Throws:
Exception - if an internal processing error has occurred.

sendExchange

protected Exchange sendExchange(Endpoint endpoint,
                                ExchangePattern pattern,
                                Processor processor,
                                Exchange exchange)
                         throws Exception
Throws:
Exception

doGetProducer

protected Producer doGetProducer(Endpoint endpoint,
                                 boolean pooled)

doStop

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

doStart

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

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

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2007-2010 The Apache Software Foundation. All Rights Reserved.