Refactored MessageEndpointAnnotationPostProcessor to MessagingAnnotationPostProcessor which delegates to HandlerAnnotationPostProcessor, SourceAnnotationPostProcessor, and TargetAnnotationPostProcessor (work related to INT-194 and INT-195).

This commit is contained in:
Mark Fisher
2008-05-30 22:18:07 +00:00
parent bd80868ca5
commit 05524a330a
47 changed files with 1002 additions and 585 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* 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.
@@ -19,28 +19,21 @@ package org.springframework.integration.samples.oddeven;
import java.util.concurrent.atomic.AtomicInteger;
import org.springframework.integration.annotation.MessageEndpoint;
import org.springframework.integration.annotation.MessageSource;
import org.springframework.integration.annotation.Polled;
import org.springframework.integration.annotation.Router;
/**
* @author Mark Fisher
*/
@MessageEndpoint
@MessageEndpoint(output="numbers")
@Polled(initialDelay=1000, period=3000)
public class Counter {
private AtomicInteger count = new AtomicInteger();
private final AtomicInteger count = new AtomicInteger();
@Polled(initialDelay=1000, period=3000)
public int getNumber() {
@MessageSource
public int next() {
return count.incrementAndGet();
}
@Router
public String resolveChannel(int i) {
if (i % 2 == 0) {
return "even";
}
return "odd";
}
}

View File

@@ -0,0 +1,36 @@
/*
* 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.samples.oddeven;
import org.springframework.integration.annotation.MessageEndpoint;
import org.springframework.integration.annotation.Router;
/**
* @author Mark Fisher
*/
@MessageEndpoint(input="numbers")
public class NumberRouter {
@Router
public String resolveChannel(int i) {
if (i % 2 == 0) {
return "even";
}
return "odd";
}
}

View File

@@ -11,8 +11,12 @@
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
<context:component-scan base-package="org.springframework.integration.samples.oddeven"/>
<message-bus auto-create-channels="true" auto-startup="false"/>
<message-bus auto-startup="false"/>
<channel id="numbers"/>
<channel id="even"/>
<channel id="odd"/>
<annotation-driven/>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* 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.
@@ -16,14 +16,16 @@
package org.springframework.integration.samples.quote;
import org.springframework.integration.annotation.Subscriber;
import org.springframework.integration.annotation.MessageEndpoint;
import org.springframework.integration.annotation.MessageTarget;
/**
* @author Mark Fisher
*/
public class QuoteSubscriber {
@MessageEndpoint(input="quotes")
public class Logger {
@Subscriber(channel="quotes")
@MessageTarget
public void log(Object o) {
System.out.println(o);
}

View File

@@ -22,25 +22,15 @@ import java.util.Random;
import org.springframework.integration.annotation.Handler;
import org.springframework.integration.annotation.MessageEndpoint;
import org.springframework.integration.annotation.Polled;
/**
* @author Mark Fisher
*/
@MessageEndpoint(output="quotes")
public class QuotePublisher {
@Polled(period=300)
public String generateTicker() {
char[] chars = new char[3];
for (int i = 0; i < 3; i++) {
chars[i] = (char) (new Random().nextInt(25) + 65);
}
return new String(chars);
}
@MessageEndpoint(input="tickers", output="quotes")
public class QuoteService {
@Handler
public Quote getQuote(String ticker) {
public Quote lookupQuote(String ticker) {
BigDecimal price = new BigDecimal(new Random().nextDouble() * 100);
return new Quote(ticker, price.setScale(2, RoundingMode.HALF_EVEN));
}

View File

@@ -0,0 +1,41 @@
/*
* 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.samples.quote;
import java.util.Random;
import org.springframework.integration.annotation.MessageEndpoint;
import org.springframework.integration.annotation.MessageSource;
import org.springframework.integration.annotation.Polled;
/**
* @author Mark Fisher
*/
@MessageEndpoint(output="tickers")
@Polled(period=300)
public class TickerStream {
@MessageSource
public String nextTicker() {
char[] chars = new char[3];
for (int i = 0; i < 3; i++) {
chars[i] = (char) (new Random().nextInt(25) + 65);
}
return new String(chars);
}
}

View File

@@ -11,10 +11,13 @@
<annotation-driven/>
<channel id="tickers"/>
<channel id="quotes"/>
<beans:bean id="publisher" class="org.springframework.integration.samples.quote.QuotePublisher"/>
<beans:bean class="org.springframework.integration.samples.quote.TickerStream"/>
<beans:bean id="subscriber" class="org.springframework.integration.samples.quote.QuoteSubscriber"/>
<beans:bean class="org.springframework.integration.samples.quote.QuoteService"/>
<beans:bean class="org.springframework.integration.samples.quote.Logger"/>
</beans:beans>