This commit is contained in:
Mark Fisher
2008-12-11 23:38:48 +00:00
parent c67c48c85e
commit 69fc0a0cb3
3 changed files with 51 additions and 19 deletions

View File

@@ -62,14 +62,21 @@ public class HttpInvokerInboundGateway extends RemotingInboundGatewaySupport imp
private volatile HttpInvokerServiceExporter exporter;
private final Object initializationMonitor = new Object();
@Override
protected void onInit() {
HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter();
exporter.setService(this);
exporter.setServiceInterface(RemoteMessageHandler.class);
exporter.afterPropertiesSet();
this.exporter = exporter;
protected void onInit() throws Exception {
synchronized (this.initializationMonitor) {
if (this.exporter == null) {
HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter();
exporter.setService(this);
exporter.setServiceInterface(RemoteMessageHandler.class);
exporter.afterPropertiesSet();
this.exporter = exporter;
}
}
super.onInit();
}
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

View File

@@ -16,7 +16,6 @@
package org.springframework.integration.rmi;
import java.rmi.RemoteException;
import java.rmi.registry.Registry;
import org.springframework.beans.factory.InitializingBean;
@@ -46,6 +45,10 @@ public class RmiInboundGateway extends RemotingInboundGatewaySupport implements
private volatile RemoteInvocationExecutor remoteInvocationExecutor;
private volatile RmiServiceExporter exporter;
private final Object initializationMonitor = new Object();
/**
* Specify the request channel where messages will be sent.
@@ -73,19 +76,25 @@ public class RmiInboundGateway extends RemotingInboundGatewaySupport implements
}
@Override
protected void onInit() throws RemoteException {
RmiServiceExporter exporter = new RmiServiceExporter();
if (this.registryHost != null) {
exporter.setRegistryHost(this.registryHost);
protected void onInit() throws Exception {
synchronized (this.initializationMonitor) {
if (this.exporter == null) {
RmiServiceExporter exporter = new RmiServiceExporter();
if (this.registryHost != null) {
exporter.setRegistryHost(this.registryHost);
}
exporter.setRegistryPort(this.registryPort);
if (this.remoteInvocationExecutor != null) {
exporter.setRemoteInvocationExecutor(this.remoteInvocationExecutor);
}
exporter.setService(this);
exporter.setServiceInterface(RemoteMessageHandler.class);
exporter.setServiceName(SERVICE_NAME_PREFIX + this.requestChannelName);
exporter.afterPropertiesSet();
this.exporter = exporter;
}
}
exporter.setRegistryPort(this.registryPort);
if (this.remoteInvocationExecutor != null) {
exporter.setRemoteInvocationExecutor(this.remoteInvocationExecutor);
}
exporter.setService(this);
exporter.setServiceInterface(RemoteMessageHandler.class);
exporter.setServiceName(SERVICE_NAME_PREFIX + this.requestChannelName);
exporter.afterPropertiesSet();
super.onInit();
}
}

View File

@@ -52,6 +52,8 @@ public abstract class AbstractMessagingGateway extends AbstractEndpoint implemen
private volatile boolean shouldThrowErrors = true;
private volatile boolean initialized;
private volatile AbstractEndpoint replyMessageCorrelator;
private final Object replyMessageCorrelatorMonitor = new Object();
@@ -106,7 +108,19 @@ public abstract class AbstractMessagingGateway extends AbstractEndpoint implemen
this.shouldThrowErrors = shouldThrowErrors;
}
@Override
protected void onInit() throws Exception {
this.initialized = true;
}
private void initializeIfNecessary() {
if (!this.initialized) {
this.afterPropertiesSet();
}
}
public void send(Object object) {
this.initializeIfNecessary();
Assert.state(this.requestChannel != null,
"send is not supported, because no request channel has been configured");
Message<?> message = this.toMessage(object);
@@ -117,6 +131,7 @@ public abstract class AbstractMessagingGateway extends AbstractEndpoint implemen
}
public Object receive() {
this.initializeIfNecessary();
Assert.state(this.replyChannel != null && (this.replyChannel instanceof PollableChannel),
"receive is not supported, because no pollable reply channel has been configured");
Message<?> message = this.channelTemplate.receive((PollableChannel) this.replyChannel);
@@ -141,6 +156,7 @@ public abstract class AbstractMessagingGateway extends AbstractEndpoint implemen
}
private Message<?> sendAndReceiveMessage(Message<?> message) {
this.initializeIfNecessary();
Assert.notNull(message, "request message must not be null");
if (this.requestChannel == null) {
throw new MessageDeliveryException(message,