From b9d1779bf1344000e4c1d69fc287076db630861b Mon Sep 17 00:00:00 2001 From: Marius Bogoevici Date: Wed, 20 Aug 2008 00:57:19 +0000 Subject: [PATCH] Quartz-based variant of the odd/even application. Demonstrates configuring a poller using cron expressions. --- .../samples/quartzoddeven/Counter.java | 32 ++++++++++++ .../samples/quartzoddeven/EvenLogger.java | 35 +++++++++++++ .../samples/quartzoddeven/OddEvenDemo.java | 30 ++++++++++++ .../samples/quartzoddeven/OddLogger.java | 35 +++++++++++++ .../samples/quartzoddeven/ParityResolver.java | 31 ++++++++++++ .../samples/quartzoddeven/oddEvenDemo.xml | 49 +++++++++++++++++++ 6 files changed, 212 insertions(+) create mode 100644 org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/quartzoddeven/Counter.java create mode 100644 org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/quartzoddeven/EvenLogger.java create mode 100644 org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/quartzoddeven/OddEvenDemo.java create mode 100644 org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/quartzoddeven/OddLogger.java create mode 100644 org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/quartzoddeven/ParityResolver.java create mode 100644 org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/quartzoddeven/oddEvenDemo.xml diff --git a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/quartzoddeven/Counter.java b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/quartzoddeven/Counter.java new file mode 100644 index 0000000000..28afc81d5c --- /dev/null +++ b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/quartzoddeven/Counter.java @@ -0,0 +1,32 @@ +/* + * 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.quartzoddeven; + +import java.util.concurrent.atomic.AtomicInteger; + +/** + * @author Mark Fisher + */ +public class Counter { + + private final AtomicInteger count = new AtomicInteger(); + + public int next() { + return count.incrementAndGet(); + } + +} diff --git a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/quartzoddeven/EvenLogger.java b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/quartzoddeven/EvenLogger.java new file mode 100644 index 0000000000..f7971c448d --- /dev/null +++ b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/quartzoddeven/EvenLogger.java @@ -0,0 +1,35 @@ +/* + * 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.quartzoddeven; + +import java.text.SimpleDateFormat; +import java.util.Date; + +import org.springframework.integration.annotation.Handler; + +/** + * @author Mark Fisher + * @author Marius Bogoevici + */ +public class EvenLogger { + + @Handler + public void log(int i) { + System.out.println("even: " + i + " at " + new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date())); + } + +} diff --git a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/quartzoddeven/OddEvenDemo.java b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/quartzoddeven/OddEvenDemo.java new file mode 100644 index 0000000000..9afa9c662a --- /dev/null +++ b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/quartzoddeven/OddEvenDemo.java @@ -0,0 +1,30 @@ +/* + * 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.quartzoddeven; + +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @author Mark Fisher + */ +public class OddEvenDemo { + + public static void main(String[] args) { + new ClassPathXmlApplicationContext("oddEvenDemo.xml", OddEvenDemo.class); + } + +} diff --git a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/quartzoddeven/OddLogger.java b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/quartzoddeven/OddLogger.java new file mode 100644 index 0000000000..7bf4916bf3 --- /dev/null +++ b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/quartzoddeven/OddLogger.java @@ -0,0 +1,35 @@ +/* + * 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.quartzoddeven; + +import java.text.SimpleDateFormat; +import java.util.Date; + +import org.springframework.integration.annotation.Handler; + +/** + * @author Mark Fisher + * @author Marius Bogoevici + */ +public class OddLogger { + + @Handler + public void log(int i) { + System.out.println("odd: " + i + " at " + new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date())); + } + +} diff --git a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/quartzoddeven/ParityResolver.java b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/quartzoddeven/ParityResolver.java new file mode 100644 index 0000000000..3bb46e6892 --- /dev/null +++ b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/quartzoddeven/ParityResolver.java @@ -0,0 +1,31 @@ +/* + * 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.quartzoddeven; + +/** + * @author Mark Fisher + */ +public class ParityResolver { + + public String getParity(int i) { + if (i % 2 == 0) { + return "even"; + } + return "odd"; + } + +} diff --git a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/quartzoddeven/oddEvenDemo.xml b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/quartzoddeven/oddEvenDemo.xml new file mode 100644 index 0000000000..f05318223e --- /dev/null +++ b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/quartzoddeven/oddEvenDemo.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +