org.apache.camel.component.jpa
Class JpaConsumer

java.lang.Object
  extended by org.apache.camel.impl.ServiceSupport
      extended by org.apache.camel.impl.DefaultConsumer
          extended by org.apache.camel.impl.ScheduledPollConsumer
              extended by org.apache.camel.component.jpa.JpaConsumer
All Implemented Interfaces:
Runnable, BatchConsumer, Consumer, Service, ShutdownableService, ShutdownAware, SuspendableService

public class JpaConsumer
extends ScheduledPollConsumer
implements BatchConsumer, ShutdownAware

Version:
$Revision: 22087 $

Field Summary
 
Fields inherited from class org.apache.camel.impl.DefaultConsumer
log
 
Constructor Summary
JpaConsumer(JpaEndpoint endpoint, Processor processor)
           
 
Method Summary
protected  void configureParameters(Query query)
           
protected  DeleteHandler<Object> createDeleteHandler()
           
protected  Exchange createExchange(Object result)
           
protected  QueryFactory createQueryFactory()
           
 boolean deferShutdown(ShutdownRunningTask shutdownRunningTask)
          To defer shutdown during first phase of shutdown.
 DeleteHandler<Object> getDeleteHandler()
           
 JpaEndpoint getEndpoint()
          Gets the endpoint this Consumer consumes from.
protected  String getEntityName(Class<?> clazz)
           
 String getNamedQuery()
           
 String getNativeQuery()
           
 int getPendingExchangesSize()
          Gets the number of pending exchanges.
 String getQuery()
           
 QueryFactory getQueryFactory()
           
 boolean isBatchAllowed()
          Whether processing the batch is still allowed.
protected  boolean lockEntity(Object entity, EntityManager entityManager)
          A strategy method to lock an object with an exclusive lock so that it can be processed
protected  void poll()
          The polling method which is invoked periodically to poll this consumer
 void processBatch(Queue<Object> exchanges)
          Processes the list of Exchange in a batch.
 void setDeleteHandler(DeleteHandler<Object> deleteHandler)
           
 void setMaxMessagesPerPoll(int maxMessagesPerPoll)
          Sets a maximum number of messages as a limit to poll at each polling.
 void setNamedQuery(String namedQuery)
           
 void setNativeQuery(String nativeQuery)
           
 void setQuery(String query)
           
 void setQueryFactory(QueryFactory queryFactory)
           
 
Methods inherited from class org.apache.camel.impl.ScheduledPollConsumer
doStart, doStop, doSuspend, getDelay, getInitialDelay, getPollStrategy, getTimeUnit, isPollAllowed, isUseFixedDelay, run, setDelay, setInitialDelay, setPollStrategy, setTimeUnit, setUseFixedDelay
 
Methods inherited from class org.apache.camel.impl.DefaultConsumer
getAsyncProcessor, getExceptionHandler, getProcessor, handleException, setExceptionHandler, toString
 
Methods inherited from class org.apache.camel.impl.ServiceSupport
addChildService, doResume, doShutdown, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspended, isSuspending, removeChildService, resume, shutdown, start, start, stop, suspend
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.camel.Service
start, stop
 
Methods inherited from interface org.apache.camel.SuspendableService
isSuspended, resume, suspend
 

Constructor Detail

JpaConsumer

public JpaConsumer(JpaEndpoint endpoint,
                   Processor processor)
Method Detail

poll

protected void poll()
             throws Exception
Description copied from class: ScheduledPollConsumer
The polling method which is invoked periodically to poll this consumer

Specified by:
poll in class ScheduledPollConsumer
Throws:
Exception - can be thrown if an exception occurred during polling

setMaxMessagesPerPoll

public void setMaxMessagesPerPoll(int maxMessagesPerPoll)
Description copied from interface: BatchConsumer
Sets a maximum number of messages as a limit to poll at each polling.

Can be used to limit eg to 100 to avoid when starting and there are millions of messages for you in the first poll.

Is default unlimited, but use 0 or negative number to disable it as unlimited.

Specified by:
setMaxMessagesPerPoll in interface BatchConsumer
Parameters:
maxMessagesPerPoll - maximum messages to poll.

processBatch

public void processBatch(Queue<Object> exchanges)
                  throws Exception
Description copied from interface: BatchConsumer
Processes the list of Exchange in a batch.

Each message exchange will be processed individually but the batch consumer will add properties with the current index and total in the batch. The items in the Queue may actually be Holder objects that store other data alongside the Exchange.

Specified by:
processBatch in interface BatchConsumer
Parameters:
exchanges - list of items in this batch
Throws:
Exception - if an internal processing error has occurred.

deferShutdown

public boolean deferShutdown(ShutdownRunningTask shutdownRunningTask)
Description copied from interface: ShutdownAware
To defer shutdown during first phase of shutdown. This allows any pending exchanges to be completed and therefore ensure a graceful shutdown without loosing messages. At the very end when there are no more inflight and pending messages the consumer could then safely be shutdown.

This is needed by SedaConsumer.

Specified by:
deferShutdown in interface ShutdownAware
Parameters:
shutdownRunningTask - the configured option for how to act when shutting down running tasks.
Returns:
true to defer shutdown to very last.

getPendingExchangesSize

public int getPendingExchangesSize()
Description copied from interface: ShutdownAware
Gets the number of pending exchanges.

Some consumers has internal queues with Exchange which are pending. For example the SedaConsumer.

Return zero to indicate no pending exchanges and therefore ready to shutdown.

Specified by:
getPendingExchangesSize in interface ShutdownAware
Returns:
number of pending exchanges

isBatchAllowed

public boolean isBatchAllowed()
Description copied from interface: BatchConsumer
Whether processing the batch is still allowed.

This is used during shutdown to help indicate whether to complete the pending exchanges or stop after current exchange has been processed.

Specified by:
isBatchAllowed in interface BatchConsumer
Returns:
true to continue processing from the batch, or false to stop.
See Also:
ShutdownRunningTask

getEndpoint

public JpaEndpoint getEndpoint()
Description copied from interface: Consumer
Gets the endpoint this Consumer consumes from.

Specified by:
getEndpoint in interface Consumer
Overrides:
getEndpoint in class DefaultConsumer
Returns:
the endpoint

getQueryFactory

public QueryFactory getQueryFactory()

setQueryFactory

public void setQueryFactory(QueryFactory queryFactory)

getDeleteHandler

public DeleteHandler<Object> getDeleteHandler()

setDeleteHandler

public void setDeleteHandler(DeleteHandler<Object> deleteHandler)

getNamedQuery

public String getNamedQuery()

setNamedQuery

public void setNamedQuery(String namedQuery)

getNativeQuery

public String getNativeQuery()

setNativeQuery

public void setNativeQuery(String nativeQuery)

getQuery

public String getQuery()

setQuery

public void setQuery(String query)

lockEntity

protected boolean lockEntity(Object entity,
                             EntityManager entityManager)
A strategy method to lock an object with an exclusive lock so that it can be processed

Parameters:
entity - the entity to be locked
entityManager - entity manager
Returns:
true if the entity was locked

createQueryFactory

protected QueryFactory createQueryFactory()

getEntityName

protected String getEntityName(Class<?> clazz)

createDeleteHandler

protected DeleteHandler<Object> createDeleteHandler()

configureParameters

protected void configureParameters(Query query)

createExchange

protected Exchange createExchange(Object result)


Apache CAMEL