From d5cb033c60c9c87bd9bfbb8671b2e304e4eae780 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Wed, 15 Sep 2010 21:38:00 -0400 Subject: [PATCH] INT-1456, removed spring-tx dependency from MessagingTemplate --- .../integration/core/MessagingTemplate.java | 90 +------------------ .../MessageSendingFileAdditionListener.java | 20 +---- 2 files changed, 5 insertions(+), 105 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/core/MessagingTemplate.java b/spring-integration-core/src/main/java/org/springframework/integration/core/MessagingTemplate.java index a3e6346881..d4cb92a818 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/core/MessagingTemplate.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/core/MessagingTemplate.java @@ -21,7 +21,6 @@ import java.util.concurrent.TimeUnit; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.InitializingBean; @@ -36,23 +35,15 @@ import org.springframework.integration.support.channel.ChannelResolutionExceptio import org.springframework.integration.support.channel.ChannelResolver; import org.springframework.integration.support.converter.MessageConverter; import org.springframework.integration.support.converter.SimpleMessageConverter; -import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.transaction.TransactionStatus; -import org.springframework.transaction.support.TransactionCallback; -import org.springframework.transaction.support.TransactionTemplate; import org.springframework.util.Assert; /** * This is the central class for invoking message exchange operations across * {@link MessageChannel}s. It supports one-way send and receive calls as well * as request/reply. - *

- * To enable transactions, configure the 'transactionManager' property with a - * reference to an instance of Spring's {@link PlatformTransactionManager} - * strategy and optionally provide the other transactional attributes - * (e.g. 'propagationBehaviorName'). * * @author Mark Fisher + * @author Oleg Zhurakousky */ public class MessagingTemplate implements MessagingOperations, BeanFactoryAware, InitializingBean { @@ -68,18 +59,6 @@ public class MessagingTemplate implements MessagingOperations, BeanFactoryAware, private volatile long receiveTimeout = -1; - private volatile PlatformTransactionManager transactionManager; - - private volatile TransactionTemplate transactionTemplate; - - private volatile String propagationBehaviorName = "PROPAGATION_REQUIRED"; - - private volatile String isolationLevelName = "ISOLATION_DEFAULT"; - - private volatile int transactionTimeout = -1; - - private volatile boolean readOnly = false; - private volatile boolean initialized; private final Object initializationMonitor = new Object(); @@ -147,38 +126,6 @@ public class MessagingTemplate implements MessagingOperations, BeanFactoryAware, this.receiveTimeout = receiveTimeout; } - /** - * Specify a transaction manager to use for all exchange operations. - * If none is provided, then the operations will occur without any - * transactional behavior (i.e. there is no default transaction manager). - */ - public void setTransactionManager(PlatformTransactionManager transactionManager) { - this.transactionManager = transactionManager; - } - - public void setPropagationBehaviorName(String propagationBehaviorName) { - this.propagationBehaviorName = propagationBehaviorName; - } - - public void setIsolationLevelName(String isolationLevelName) { - this.isolationLevelName = isolationLevelName; - } - - public void setTransactionTimeout(int transactionTimeout) { - this.transactionTimeout = transactionTimeout; - } - - public void setTransactionReadOnly(boolean readOnly) { - this.readOnly = readOnly; - } - - private TransactionTemplate getTransactionTemplate() { - if (!this.initialized) { - this.afterPropertiesSet(); - } - return this.transactionTemplate; - } - public void setBeanFactory(BeanFactory beanFactory) { if (this.channelResolver == null && beanFactory != null) { this.channelResolver = new BeanFactoryChannelResolver(beanFactory); @@ -190,14 +137,6 @@ public class MessagingTemplate implements MessagingOperations, BeanFactoryAware, if (this.initialized) { return; } - if (this.transactionManager != null) { - TransactionTemplate template = new TransactionTemplate(this.transactionManager); - template.setPropagationBehaviorName(this.propagationBehaviorName); - template.setIsolationLevelName(this.isolationLevelName); - template.setTimeout(this.transactionTimeout); - template.setReadOnly(this.readOnly); - this.transactionTemplate = template; - } this.initialized = true; } } @@ -207,15 +146,6 @@ public class MessagingTemplate implements MessagingOperations, BeanFactoryAware, } public

void send(final MessageChannel channel, final Message

message) { - TransactionTemplate txTemplate = this.getTransactionTemplate(); - if (txTemplate != null) { - txTemplate.execute(new TransactionCallback() { - public Object doInTransaction(TransactionStatus status) { - doSend(channel, message); - return null; - } - }); - } this.doSend(channel, message); } @@ -276,14 +206,6 @@ public class MessagingTemplate implements MessagingOperations, BeanFactoryAware, } public

Message

receive(final PollableChannel channel) { - TransactionTemplate txTemplate = this.getTransactionTemplate(); - if (txTemplate != null) { - return txTemplate.execute(new TransactionCallback>() { - public Message

doInTransaction(TransactionStatus status) { - return doReceive(channel); - } - }); - } return this.doReceive(channel); } @@ -314,14 +236,6 @@ public class MessagingTemplate implements MessagingOperations, BeanFactoryAware, } public Message sendAndReceive(final MessageChannel channel, final Message requestMessage) { - TransactionTemplate txTemplate = this.getTransactionTemplate(); - if (txTemplate != null) { - return txTemplate.execute(new TransactionCallback>() { - public Message doInTransaction(TransactionStatus status) { - return doSendAndReceive(channel, requestMessage); - } - }); - } return this.doSendAndReceive(channel, requestMessage); } @@ -482,7 +396,5 @@ public class MessagingTemplate implements MessagingOperations, BeanFactoryAware, this.latch.countDown(); return true; } - } - } diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/monitors/MessageSendingFileAdditionListener.java b/spring-integration-file/src/main/java/org/springframework/integration/file/monitors/MessageSendingFileAdditionListener.java index 8690ff5a9a..713766f4ce 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/monitors/MessageSendingFileAdditionListener.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/monitors/MessageSendingFileAdditionListener.java @@ -1,28 +1,25 @@ package org.springframework.integration.file.monitors; +import java.io.File; + import org.springframework.integration.Message; import org.springframework.integration.MessageChannel; import org.springframework.integration.context.IntegrationObjectSupport; import org.springframework.integration.core.MessagingTemplate; import org.springframework.integration.support.MessageBuilder; - -import org.springframework.transaction.PlatformTransactionManager; - import org.springframework.util.Assert; -import java.io.File; - /** * Supports propagating a {@link org.springframework.integration.Message} on the receipt of a new {@link java.io.File} * * @author Josh Long + * @author Oleg Zhurakousky */ public class MessageSendingFileAdditionListener extends IntegrationObjectSupport implements FileAdditionListener { private MessagingTemplate messagingTemplate = new MessagingTemplate(); private MessageChannel channel; - private PlatformTransactionManager platformTransactionManager; - + public void setChannel(MessageChannel channel) { this.channel = channel; } @@ -30,16 +27,7 @@ public class MessageSendingFileAdditionListener extends IntegrationObjectSupport @Override protected void onInit() throws Exception { Assert.notNull(this.channel, "'channel' can't be null!"); - - if (this.platformTransactionManager != null) { - this.messagingTemplate.setTransactionManager(platformTransactionManager); - } } - - public void setPlatformTransactionManager(PlatformTransactionManager platformTransactionManager) { - this.platformTransactionManager = platformTransactionManager; - } - public void fileAdded(File f) { Message fileMsg = MessageBuilder.withPayload(f).build(); this.messagingTemplate.send(fileMsg);