Implemented TriggerMessage with an EndpointPoller as its payload for convenience when triggering polling of an endpoint.

This commit is contained in:
Mark Fisher
2008-07-14 23:11:54 +00:00
parent 8f1cf63f5e
commit b45514003c
6 changed files with 57 additions and 23 deletions

View File

@@ -18,7 +18,6 @@ package org.springframework.integration.endpoint;
import org.springframework.integration.dispatcher.BroadcastingDispatcher;
import org.springframework.integration.dispatcher.PollingDispatcher;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.MessageSource;
import org.springframework.integration.scheduling.PollingSchedule;
@@ -36,7 +35,7 @@ public class EndpointTrigger extends PollingDispatcher {
* Create an endpoint trigger with the specified {@link Schedule}.
*/
public EndpointTrigger(Schedule schedule) {
super(new EndpointPollerMessageSource(), new BroadcastingDispatcher(), schedule);
super(new TriggerSource(), new BroadcastingDispatcher(), schedule);
}
/**
@@ -47,11 +46,19 @@ public class EndpointTrigger extends PollingDispatcher {
this(new PollingSchedule(interval));
}
/**
* Create an endpoint trigger that will run one time only when submitted to
* a {@link org.springframework.integration.scheduling.TaskScheduler}.
*/
public EndpointTrigger() {
this(null);
}
private static class EndpointPollerMessageSource implements MessageSource<EndpointPoller> {
private static class TriggerSource implements MessageSource<EndpointPoller> {
public Message<EndpointPoller> receive() {
return new GenericMessage<EndpointPoller>(new EndpointPoller());
return new TriggerMessage();
}
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.endpoint;
import org.springframework.integration.message.GenericMessage;
/**
* A convenience Message implementation for sending a polling trigger
* to an endpoint.
*
* @author Mark Fisher
*/
public class TriggerMessage extends GenericMessage<EndpointPoller> {
public TriggerMessage() {
super(new EndpointPoller());
}
}

View File

@@ -21,15 +21,13 @@ import static org.junit.Assert.assertEquals;
import java.util.List;
import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.endpoint.EndpointInterceptor;
import org.springframework.integration.endpoint.EndpointPoller;
import org.springframework.integration.endpoint.MessageEndpoint;
import org.springframework.integration.endpoint.SourceEndpoint;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.endpoint.TriggerMessage;
import org.springframework.integration.message.StringMessage;
/**
@@ -105,7 +103,7 @@ public class EndpointInterceptorTests {
if (endpoint instanceof SourceEndpoint) {
MessageChannel channel = (MessageChannel) context.getBean("testChannel");
channel.send(new StringMessage("foo"));
endpoint.send(new GenericMessage<EndpointPoller>(new EndpointPoller()));
endpoint.send(new TriggerMessage());
}
else {
endpoint.send(new StringMessage("test"));

View File

@@ -40,7 +40,7 @@ public class SourceEndpointTests {
SourceEndpoint endpoint = new SourceEndpoint(source);
endpoint.setTarget(channel);
endpoint.afterPropertiesSet();
endpoint.send(new GenericMessage<EndpointPoller>(new EndpointPoller()));
endpoint.send(new TriggerMessage());
Message<?> message = channel.receive(1000);
assertNotNull("message should not be null", message);
assertEquals("testing.1", message.getPayload());