Search in sources :

Example 1 with SessionBatchTransactionSynchronization

use of org.apache.camel.component.sjms.tx.SessionBatchTransactionSynchronization in project camel by apache.

the class SjmsConsumer method createMessageHandler.

/**
     * Helper factory method used to create a MessageListener based on the MEP
     *
     * @param session a session is only required if we are a transacted consumer
     * @return the listener
     */
protected MessageListener createMessageHandler(Session session) {
    TransactionCommitStrategy commitStrategy;
    if (getTransactionCommitStrategy() != null) {
        commitStrategy = getTransactionCommitStrategy();
    } else if (getTransactionBatchCount() > 0) {
        commitStrategy = new BatchTransactionCommitStrategy(getTransactionBatchCount());
    } else {
        commitStrategy = new DefaultTransactionCommitStrategy();
    }
    Synchronization synchronization;
    if (commitStrategy instanceof BatchTransactionCommitStrategy) {
        TimedTaskManager timedTaskManager = getEndpoint().getComponent().getTimedTaskManager();
        synchronization = new SessionBatchTransactionSynchronization(timedTaskManager, session, commitStrategy, getTransactionBatchTimeout());
    } else {
        synchronization = new SessionTransactionSynchronization(session, commitStrategy);
    }
    AbstractMessageHandler messageHandler;
    if (getEndpoint().getExchangePattern().equals(ExchangePattern.InOnly)) {
        if (isTransacted()) {
            messageHandler = new InOnlyMessageHandler(getEndpoint(), executor, synchronization);
        } else {
            messageHandler = new InOnlyMessageHandler(getEndpoint(), executor);
        }
    } else {
        if (isTransacted()) {
            messageHandler = new InOutMessageHandler(getEndpoint(), executor, synchronization);
        } else {
            messageHandler = new InOutMessageHandler(getEndpoint(), executor);
        }
    }
    messageHandler.setSession(session);
    messageHandler.setProcessor(getAsyncProcessor());
    messageHandler.setSynchronous(isSynchronous());
    messageHandler.setTransacted(isTransacted());
    messageHandler.setSharedJMSSession(isSharedJMSSession());
    messageHandler.setTopic(isTopic());
    return messageHandler;
}
Also used : InOnlyMessageHandler(org.apache.camel.component.sjms.consumer.InOnlyMessageHandler) SessionTransactionSynchronization(org.apache.camel.component.sjms.tx.SessionTransactionSynchronization) InOutMessageHandler(org.apache.camel.component.sjms.consumer.InOutMessageHandler) BatchTransactionCommitStrategy(org.apache.camel.component.sjms.tx.BatchTransactionCommitStrategy) DefaultTransactionCommitStrategy(org.apache.camel.component.sjms.tx.DefaultTransactionCommitStrategy) DefaultTransactionCommitStrategy(org.apache.camel.component.sjms.tx.DefaultTransactionCommitStrategy) BatchTransactionCommitStrategy(org.apache.camel.component.sjms.tx.BatchTransactionCommitStrategy) SessionBatchTransactionSynchronization(org.apache.camel.component.sjms.tx.SessionBatchTransactionSynchronization) SessionTransactionSynchronization(org.apache.camel.component.sjms.tx.SessionTransactionSynchronization) Synchronization(org.apache.camel.spi.Synchronization) TimedTaskManager(org.apache.camel.component.sjms.taskmanager.TimedTaskManager) SessionBatchTransactionSynchronization(org.apache.camel.component.sjms.tx.SessionBatchTransactionSynchronization) AbstractMessageHandler(org.apache.camel.component.sjms.consumer.AbstractMessageHandler)

Aggregations

AbstractMessageHandler (org.apache.camel.component.sjms.consumer.AbstractMessageHandler)1 InOnlyMessageHandler (org.apache.camel.component.sjms.consumer.InOnlyMessageHandler)1 InOutMessageHandler (org.apache.camel.component.sjms.consumer.InOutMessageHandler)1 TimedTaskManager (org.apache.camel.component.sjms.taskmanager.TimedTaskManager)1 BatchTransactionCommitStrategy (org.apache.camel.component.sjms.tx.BatchTransactionCommitStrategy)1 DefaultTransactionCommitStrategy (org.apache.camel.component.sjms.tx.DefaultTransactionCommitStrategy)1 SessionBatchTransactionSynchronization (org.apache.camel.component.sjms.tx.SessionBatchTransactionSynchronization)1 SessionTransactionSynchronization (org.apache.camel.component.sjms.tx.SessionTransactionSynchronization)1 Synchronization (org.apache.camel.spi.Synchronization)1