From b45d80a32e05d2a30f12224222ac2ca2f5f55500 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Sun, 16 Dec 2007 18:35:02 +0000 Subject: [PATCH] Added quote demo in new sub-package location --- .../integration/samples/quote/Quote.java | 39 +++++++++++++++++++ .../integration/samples/quote/QuoteDemo.java | 32 +++++++++++++++ .../samples/quote/QuotePublisher.java | 38 ++++++++++++++++++ .../samples/quote/QuoteSubscriber.java | 31 +++++++++++++++ .../integration/samples/quote/quoteDemo.xml | 20 ++++++++++ 5 files changed, 160 insertions(+) create mode 100644 spring-integration-core/src/main/java/org/springframework/integration/samples/quote/Quote.java create mode 100644 spring-integration-core/src/main/java/org/springframework/integration/samples/quote/QuoteDemo.java create mode 100644 spring-integration-core/src/main/java/org/springframework/integration/samples/quote/QuotePublisher.java create mode 100644 spring-integration-core/src/main/java/org/springframework/integration/samples/quote/QuoteSubscriber.java create mode 100644 spring-integration-core/src/main/java/org/springframework/integration/samples/quote/quoteDemo.xml diff --git a/spring-integration-core/src/main/java/org/springframework/integration/samples/quote/Quote.java b/spring-integration-core/src/main/java/org/springframework/integration/samples/quote/Quote.java new file mode 100644 index 0000000000..f655f02cf6 --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/integration/samples/quote/Quote.java @@ -0,0 +1,39 @@ +/* + * Copyright 2002-2007 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.math.BigDecimal; + +/** + * @author Mark Fisher + */ +public class Quote { + + private String ticker; + + private BigDecimal price; + + public Quote(String ticker, BigDecimal price) { + this.ticker = ticker; + this.price = price; + } + + public String toString() { + return ticker + ": " + price; + } + +} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/samples/quote/QuoteDemo.java b/spring-integration-core/src/main/java/org/springframework/integration/samples/quote/QuoteDemo.java new file mode 100644 index 0000000000..e48bd03bd5 --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/integration/samples/quote/QuoteDemo.java @@ -0,0 +1,32 @@ +/* + * Copyright 2002-2007 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 org.springframework.context.support.AbstractApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @author Mark Fisher + */ +public class QuoteDemo { + + public static void main(String[] args) throws Exception { + AbstractApplicationContext context = new ClassPathXmlApplicationContext("quoteDemo.xml", QuoteDemo.class); + context.start(); + System.in.read(); + } +} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/samples/quote/QuotePublisher.java b/spring-integration-core/src/main/java/org/springframework/integration/samples/quote/QuotePublisher.java new file mode 100644 index 0000000000..ded1769972 --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/integration/samples/quote/QuotePublisher.java @@ -0,0 +1,38 @@ +/* + * Copyright 2002-2007 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.math.BigDecimal; +import java.math.RoundingMode; +import java.util.Random; + +import org.springframework.integration.endpoint.annotation.MessageEndpoint; +import org.springframework.integration.endpoint.annotation.Polled; + +/** + * @author Mark Fisher + */ +@MessageEndpoint(defaultOutput="quotes") +public class QuotePublisher { + + @Polled(period=300) + public Quote getQuote() { + BigDecimal price = new BigDecimal(new Random().nextDouble() * 100); + return new Quote("SOA", price.setScale(2, RoundingMode.HALF_EVEN)); + } + +} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/samples/quote/QuoteSubscriber.java b/spring-integration-core/src/main/java/org/springframework/integration/samples/quote/QuoteSubscriber.java new file mode 100644 index 0000000000..cf7456b4bd --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/integration/samples/quote/QuoteSubscriber.java @@ -0,0 +1,31 @@ +/* + * Copyright 2002-2007 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 org.springframework.integration.endpoint.annotation.Subscriber; + +/** + * @author Mark Fisher + */ +public class QuoteSubscriber { + + @Subscriber(channel="quotes") + public void log(Object o) { + System.out.println(o); + } + +} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/samples/quote/quoteDemo.xml b/spring-integration-core/src/main/java/org/springframework/integration/samples/quote/quoteDemo.xml new file mode 100644 index 0000000000..cf66173db8 --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/integration/samples/quote/quoteDemo.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + +