org.apache.camel.impl
Class DefaultConsumerTemplate

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

public class DefaultConsumerTemplate
extends ServiceSupport
implements ConsumerTemplate

Template (named like Spring's TransactionTemplate & JmsTemplate et al) for working with Camel and consuming Message instances in an Exchange from an Endpoint.

Version:

Field Summary
 
Fields inherited from class org.apache.camel.support.ServiceSupport
shutdown, shuttingdown, started, starting, stopped, stopping, suspended, suspending
 
Constructor Summary
DefaultConsumerTemplate(CamelContext camelContext)
           
 
Method Summary
 void doneUoW(Exchange exchange)
          If you have used any of the receive methods which returns a Exchange type then you need to invoke this method when you are done using the returned Exchange.
protected  void doStart()
          Implementations override this method to support customized start/stop.
protected  void doStop()
          Implementations override this method to support customized start/stop.
protected  Object extractResultBody(Exchange result)
          Extracts the body from the given result.
 CamelContext getCamelContext()
          Get the CamelContext
 CamelContext getContext()
          Deprecated. use getCamelContext()
 int getCurrentCacheSize()
          Gets an approximated size of the current cached resources in the backing cache pools.
 int getMaximumCacheSize()
          Gets the maximum cache size used.
 Exchange receive(Endpoint endpoint)
          Receives from the endpoint, waiting until there is a response.
 Exchange receive(Endpoint endpoint, long timeout)
          Receives from the endpoint, waiting until there is a response or the timeout occurs

Important: See ConsumerTemplate.doneUoW(Exchange)

 Exchange receive(String endpointUri)
          Receives from the endpoint, waiting until there is a response

Important: See ConsumerTemplate.doneUoW(Exchange)

 Exchange receive(String endpointUri, long timeout)
          Receives from the endpoint, waiting until there is a response or the timeout occurs

Important: See ConsumerTemplate.doneUoW(Exchange)

 Object receiveBody(Endpoint endpoint)
          Receives from the endpoint, waiting until there is a response
<T> T
receiveBody(Endpoint endpoint, Class<T> type)
          Receives from the endpoint, waiting until there is a response
 Object receiveBody(Endpoint endpoint, long timeout)
          Receives from the endpoint, waiting until there is a response or the timeout occurs
<T> T
receiveBody(Endpoint endpoint, long timeout, Class<T> type)
          Receives from the endpoint, waiting until there is a response or the timeout occurs
 Object receiveBody(String endpointUri)
          Receives from the endpoint, waiting until there is a response
<T> T
receiveBody(String endpointUri, Class<T> type)
          Receives from the endpoint, waiting until there is a response
 Object receiveBody(String endpointUri, long timeout)
          Receives from the endpoint, waiting until there is a response or the timeout occurs
<T> T
receiveBody(String endpointUri, long timeout, Class<T> type)
          Receives from the endpoint, waiting until there is a response or the timeout occurs
 Object receiveBodyNoWait(Endpoint endpoint)
          Receives from the endpoint, not waiting for a response if non exists.
<T> T
receiveBodyNoWait(Endpoint endpoint, Class<T> type)
          Receives from the endpoint, not waiting for a response if non exists.
 Object receiveBodyNoWait(String endpointUri)
          Receives from the endpoint, not waiting for a response if non exists.
<T> T
receiveBodyNoWait(String endpointUri, Class<T> type)
          Receives from the endpoint, not waiting for a response if non exists.
 Exchange receiveNoWait(Endpoint endpoint)
          Receives from the endpoint, not waiting for a response if non exists.
 Exchange receiveNoWait(String endpointUri)
          Receives from the endpoint, not waiting for a response if non exists.
protected  Endpoint resolveMandatoryEndpoint(String endpointUri)
           
 void setMaximumCacheSize(int maximumCacheSize)
          Sets a custom maximum cache size.
 
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
 
Methods inherited from interface org.apache.camel.Service
start, stop
 

Constructor Detail

DefaultConsumerTemplate

public DefaultConsumerTemplate(CamelContext camelContext)
Method Detail

getMaximumCacheSize

public int getMaximumCacheSize()
Description copied from interface: ConsumerTemplate
Gets the maximum cache size used.

Specified by:
getMaximumCacheSize in interface ConsumerTemplate
Returns:
the maximum cache size

setMaximumCacheSize

public void setMaximumCacheSize(int maximumCacheSize)
Description copied from interface: ConsumerTemplate
Sets a custom maximum cache size.

Specified by:
setMaximumCacheSize in interface ConsumerTemplate
Parameters:
maximumCacheSize - the custom maximum cache size

getCurrentCacheSize

public int getCurrentCacheSize()
Description copied from interface: ConsumerTemplate
Gets an approximated size of the current cached resources in the backing cache pools.

Specified by:
getCurrentCacheSize in interface ConsumerTemplate
Returns:
the size of current cached resources

getContext

@Deprecated
public CamelContext getContext()
Deprecated. use getCamelContext()


getCamelContext

public CamelContext getCamelContext()
Description copied from interface: ConsumerTemplate
Get the CamelContext

Specified by:
getCamelContext in interface ConsumerTemplate
Returns:
camelContext the Camel context

receive

public Exchange receive(String endpointUri)
Description copied from interface: ConsumerTemplate
Receives from the endpoint, waiting until there is a response

Important: See ConsumerTemplate.doneUoW(Exchange)

Specified by:
receive in interface ConsumerTemplate
Parameters:
endpointUri - the endpoint to receive from
Returns:
the returned exchange

receive

public Exchange receive(Endpoint endpoint)
Description copied from interface: ConsumerTemplate
Receives from the endpoint, waiting until there is a response.

Important: See ConsumerTemplate.doneUoW(Exchange)

Specified by:
receive in interface ConsumerTemplate
Parameters:
endpoint - the endpoint to receive from
Returns:
the returned exchange
See Also:
ConsumerTemplate.doneUoW(Exchange)

receive

public Exchange receive(String endpointUri,
                        long timeout)
Description copied from interface: ConsumerTemplate
Receives from the endpoint, waiting until there is a response or the timeout occurs

Important: See ConsumerTemplate.doneUoW(Exchange)

Specified by:
receive in interface ConsumerTemplate
Parameters:
endpointUri - the endpoint to receive from
timeout - timeout in millis to wait for a response
Returns:
the returned exchange, or null if no response
See Also:
ConsumerTemplate.doneUoW(Exchange)

receive

public Exchange receive(Endpoint endpoint,
                        long timeout)
Description copied from interface: ConsumerTemplate
Receives from the endpoint, waiting until there is a response or the timeout occurs

Important: See ConsumerTemplate.doneUoW(Exchange)

Specified by:
receive in interface ConsumerTemplate
Parameters:
endpoint - the endpoint to receive from
timeout - timeout in millis to wait for a response
Returns:
the returned exchange, or null if no response
See Also:
ConsumerTemplate.doneUoW(Exchange)

receiveNoWait

public Exchange receiveNoWait(String endpointUri)
Description copied from interface: ConsumerTemplate
Receives from the endpoint, not waiting for a response if non exists.

Important: See ConsumerTemplate.doneUoW(Exchange)

Specified by:
receiveNoWait in interface ConsumerTemplate
Parameters:
endpointUri - the endpoint to receive from
Returns:
the returned exchange, or null if no response

receiveNoWait

public Exchange receiveNoWait(Endpoint endpoint)
Description copied from interface: ConsumerTemplate
Receives from the endpoint, not waiting for a response if non exists.

Important: See ConsumerTemplate.doneUoW(Exchange)

Specified by:
receiveNoWait in interface ConsumerTemplate
Parameters:
endpoint - the endpoint to receive from
Returns:
the returned exchange, or null if no response

receiveBody

public Object receiveBody(String endpointUri)
Description copied from interface: ConsumerTemplate
Receives from the endpoint, waiting until there is a response

Specified by:
receiveBody in interface ConsumerTemplate
Parameters:
endpointUri - the endpoint to receive from
Returns:
the returned response body

receiveBody

public Object receiveBody(Endpoint endpoint)
Description copied from interface: ConsumerTemplate
Receives from the endpoint, waiting until there is a response

Specified by:
receiveBody in interface ConsumerTemplate
Parameters:
endpoint - the endpoint to receive from
Returns:
the returned response body

receiveBody

public Object receiveBody(String endpointUri,
                          long timeout)
Description copied from interface: ConsumerTemplate
Receives from the endpoint, waiting until there is a response or the timeout occurs

Specified by:
receiveBody in interface ConsumerTemplate
Parameters:
endpointUri - the endpoint to receive from
timeout - timeout in millis to wait for a response
Returns:
the returned response body, or null if no response

receiveBody

public Object receiveBody(Endpoint endpoint,
                          long timeout)
Description copied from interface: ConsumerTemplate
Receives from the endpoint, waiting until there is a response or the timeout occurs

Specified by:
receiveBody in interface ConsumerTemplate
Parameters:
endpoint - the endpoint to receive from
timeout - timeout in millis to wait for a response
Returns:
the returned response body, or null if no response

receiveBodyNoWait

public Object receiveBodyNoWait(String endpointUri)
Description copied from interface: ConsumerTemplate
Receives from the endpoint, not waiting for a response if non exists.

Specified by:
receiveBodyNoWait in interface ConsumerTemplate
Parameters:
endpointUri - the endpoint to receive from
Returns:
the returned response body, or null if no response

receiveBodyNoWait

public Object receiveBodyNoWait(Endpoint endpoint)
Description copied from interface: ConsumerTemplate
Receives from the endpoint, not waiting for a response if non exists.

Specified by:
receiveBodyNoWait in interface ConsumerTemplate
Parameters:
endpoint - the endpoint to receive from
Returns:
the returned response body, or null if no response

receiveBody

public <T> T receiveBody(String endpointUri,
                         Class<T> type)
Description copied from interface: ConsumerTemplate
Receives from the endpoint, waiting until there is a response

Specified by:
receiveBody in interface ConsumerTemplate
Parameters:
endpointUri - the endpoint to receive from
type - the expected response type
Returns:
the returned response body

receiveBody

public <T> T receiveBody(Endpoint endpoint,
                         Class<T> type)
Description copied from interface: ConsumerTemplate
Receives from the endpoint, waiting until there is a response

Specified by:
receiveBody in interface ConsumerTemplate
Parameters:
endpoint - the endpoint to receive from
type - the expected response type
Returns:
the returned response body

receiveBody

public <T> T receiveBody(String endpointUri,
                         long timeout,
                         Class<T> type)
Description copied from interface: ConsumerTemplate
Receives from the endpoint, waiting until there is a response or the timeout occurs

Specified by:
receiveBody in interface ConsumerTemplate
Parameters:
endpointUri - the endpoint to receive from
timeout - timeout in millis to wait for a response
type - the expected response type
Returns:
the returned response body, or null if no response

receiveBody

public <T> T receiveBody(Endpoint endpoint,
                         long timeout,
                         Class<T> type)
Description copied from interface: ConsumerTemplate
Receives from the endpoint, waiting until there is a response or the timeout occurs

Specified by:
receiveBody in interface ConsumerTemplate
Parameters:
endpoint - the endpoint to receive from
timeout - timeout in millis to wait for a response
type - the expected response type
Returns:
the returned response body, or null if no response

receiveBodyNoWait

public <T> T receiveBodyNoWait(String endpointUri,
                               Class<T> type)
Description copied from interface: ConsumerTemplate
Receives from the endpoint, not waiting for a response if non exists.

Specified by:
receiveBodyNoWait in interface ConsumerTemplate
Parameters:
endpointUri - the endpoint to receive from
type - the expected response type
Returns:
the returned response body, or null if no response

receiveBodyNoWait

public <T> T receiveBodyNoWait(Endpoint endpoint,
                               Class<T> type)
Description copied from interface: ConsumerTemplate
Receives from the endpoint, not waiting for a response if non exists.

Specified by:
receiveBodyNoWait in interface ConsumerTemplate
Parameters:
endpoint - the endpoint to receive from
type - the expected response type
Returns:
the returned response body, or null if no response

doneUoW

public void doneUoW(Exchange exchange)
Description copied from interface: ConsumerTemplate
If you have used any of the receive methods which returns a Exchange type then you need to invoke this method when you are done using the returned Exchange.

This is needed to ensure any Synchronization works is being executed. For example if you consumed from a file endpoint, then the consumed file is only moved/delete when you done the Exchange.

Note for all the other receive methods which does not return a Exchange type, the done has been executed automatic by Camel itself.

Specified by:
doneUoW in interface ConsumerTemplate
Parameters:
exchange - the exchange

resolveMandatoryEndpoint

protected Endpoint resolveMandatoryEndpoint(String endpointUri)

extractResultBody

protected Object extractResultBody(Exchange result)
Extracts the body from the given result.

If the exchange pattern is provided it will try to honor it and retrieve the body from either IN or OUT according to the pattern.

Parameters:
result - the result
Returns:
the result, can be null.

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