diff --git a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/Cafe.java b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/Cafe.java index 8093d8aa43..f3e7a8f207 100644 --- a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/Cafe.java +++ b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/Cafe.java @@ -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. @@ -20,7 +20,7 @@ import org.springframework.integration.channel.MessageChannel; import org.springframework.integration.message.MessageBuilder; /** - * The entry point for {@link CafeDemo}. When the 'placeOrder' + * The entry point for Cafe Demo. When the 'placeOrder' * method is invoked, it passes the {@link Order} as the payload of a * {@link org.springframework.integration.message.Message} to the * 'orderChannel'. The channel reference is configured in the "cafe" bean diff --git a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/Delivery.java b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/Delivery.java index d32574bccc..d4e1815798 100644 --- a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/Delivery.java +++ b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/Delivery.java @@ -31,9 +31,8 @@ public class Delivery { private int orderNumber; - public Delivery(List deliveredDrinks) { - assert (deliveredDrinks.size() > 0); + assert(deliveredDrinks.size() > 0); this.deliveredDrinks = deliveredDrinks; this.orderNumber = deliveredDrinks.get(0).getOrderNumber(); } @@ -58,4 +57,5 @@ public class Delivery { buffer.append(SEPARATOR + "\n"); return buffer.toString(); } + } diff --git a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/DrinkType.java b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/DrinkType.java index b495eab0c4..6406722b29 100644 --- a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/DrinkType.java +++ b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/DrinkType.java @@ -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. diff --git a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/Order.java b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/Order.java index 2e308984db..fbde5db9ee 100644 --- a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/Order.java +++ b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/Order.java @@ -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. diff --git a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/OrderItem.java b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/OrderItem.java index 0a48f70a98..3193af490e 100644 --- a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/OrderItem.java +++ b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/OrderItem.java @@ -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. diff --git a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/annotation/Barista.java b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/annotation/Barista.java new file mode 100644 index 0000000000..118f5ebfcc --- /dev/null +++ b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/annotation/Barista.java @@ -0,0 +1,80 @@ +/* + * 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.cafe.annotation; + +import java.util.concurrent.atomic.AtomicInteger; + +import org.springframework.integration.annotation.ServiceActivator; +import org.springframework.integration.samples.cafe.Drink; +import org.springframework.integration.samples.cafe.OrderItem; +import org.springframework.stereotype.Component; + +/** + * @author Mark Fisher + * @author Marius Bogoevici + */ +@Component +public class Barista { + + private long hotDrinkDelay = 5000; + + private long coldDrinkDelay = 1000; + + private AtomicInteger hotDrinkCounter = new AtomicInteger(); + + private AtomicInteger coldDrinkCounter = new AtomicInteger(); + + + public void setHotDrinkDelay(long hotDrinkDelay) { + this.hotDrinkDelay = hotDrinkDelay; + } + + public void setColdDrinkDelay(long coldDrinkDelay) { + this.coldDrinkDelay = coldDrinkDelay; + } + + @ServiceActivator(inputChannel="hotDrinks", outputChannel="preparedDrinks") + public Drink prepareHotDrink(OrderItem orderItem) { + try { + Thread.sleep(this.hotDrinkDelay); + System.out.println(Thread.currentThread().getName() + + " prepared hot drink #" + hotDrinkCounter.incrementAndGet() + " for order #" + + orderItem.getOrder().getNumber() + ": " + orderItem); + return new Drink(orderItem.getOrder().getNumber(), orderItem.getDrinkType(), orderItem.isIced(), + orderItem.getShots()); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + return null; + } + + @ServiceActivator(inputChannel="coldDrinks", outputChannel="preparedDrinks") + public Drink prepareColdDrink(OrderItem orderItem) { + try { + Thread.sleep(this.coldDrinkDelay); + System.out.println(Thread.currentThread().getName() + + " prepared cold drink #" + coldDrinkCounter.incrementAndGet() + " for order #" + + orderItem.getOrder().getNumber() + ": " + orderItem); + return new Drink(orderItem.getOrder().getNumber(), orderItem.getDrinkType(), orderItem.isIced(), + orderItem.getShots()); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + return null; + } + +} diff --git a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/annotation/CafeDemo.java b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/annotation/CafeDemo.java new file mode 100644 index 0000000000..07bf600f5b --- /dev/null +++ b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/annotation/CafeDemo.java @@ -0,0 +1,55 @@ +/* + * 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.cafe.annotation; + +import org.springframework.context.support.AbstractApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.context.support.FileSystemXmlApplicationContext; +import org.springframework.integration.samples.cafe.Cafe; +import org.springframework.integration.samples.cafe.DrinkType; +import org.springframework.integration.samples.cafe.Order; + +/** + * Provides the 'main' method for running the Cafe Demo application. When an + * order is placed, the Cafe will send that order to the "orders" channel. + * The channels are defined within the configuration file ("cafeDemo.xml"), + * and the relevant components are configured with annotations (such as the + * OrderSplitter, DrinkRouter, and Barista classes). + * + * @author Mark Fisher + * @author Marius Bogoevici + */ +public class CafeDemo { + + public static void main(String[] args) { + AbstractApplicationContext context = null; + if(args.length > 0) { + context = new FileSystemXmlApplicationContext(args); + } + else { + context = new ClassPathXmlApplicationContext("cafeDemo.xml", CafeDemo.class); + } + Cafe cafe = (Cafe) context.getBean("cafe"); + for (int i = 1; i <= 100; i++) { + Order order = new Order(i); + order.addItem(DrinkType.LATTE, 2, false); + order.addItem(DrinkType.MOCHA, 3, true); + cafe.placeOrder(order); + } + } + +} diff --git a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/DeliveryAssembler.java b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/annotation/DeliveryAssembler.java similarity index 82% rename from org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/DeliveryAssembler.java rename to org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/annotation/DeliveryAssembler.java index 7c7fab9397..fd01c6c3f9 100644 --- a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/DeliveryAssembler.java +++ b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/annotation/DeliveryAssembler.java @@ -14,12 +14,14 @@ * limitations under the License. */ -package org.springframework.integration.samples.cafe; +package org.springframework.integration.samples.cafe.annotation; import java.util.List; import org.springframework.integration.annotation.Aggregator; import org.springframework.integration.annotation.MessageEndpoint; +import org.springframework.integration.samples.cafe.Delivery; +import org.springframework.integration.samples.cafe.Drink; /** * @author Marius Bogoevici @@ -27,7 +29,7 @@ import org.springframework.integration.annotation.MessageEndpoint; @MessageEndpoint public class DeliveryAssembler { - @Aggregator(inputChannel = "preparedDrinks", outputChannel = "deliveries") + @Aggregator(inputChannel = "preparedDrinks", outputChannel = "deliveries", timeout = 5 * 60 * 1000) public Delivery prepareDelivery(List drinks) { return new Delivery(drinks); } diff --git a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/DrinkRouter.java b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/annotation/DrinkRouter.java similarity index 83% rename from org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/DrinkRouter.java rename to org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/annotation/DrinkRouter.java index 2546a9d6cd..1f7cf0f2b1 100644 --- a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/DrinkRouter.java +++ b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/annotation/DrinkRouter.java @@ -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. @@ -14,10 +14,11 @@ * limitations under the License. */ -package org.springframework.integration.samples.cafe; +package org.springframework.integration.samples.cafe.annotation; import org.springframework.integration.annotation.MessageEndpoint; import org.springframework.integration.annotation.Router; +import org.springframework.integration.samples.cafe.OrderItem; /** * @author Mark Fisher diff --git a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/OrderSplitter.java b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/annotation/OrderSplitter.java similarity index 79% rename from org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/OrderSplitter.java rename to org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/annotation/OrderSplitter.java index 088da09461..156c50bb96 100644 --- a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/OrderSplitter.java +++ b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/annotation/OrderSplitter.java @@ -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. @@ -14,12 +14,14 @@ * limitations under the License. */ -package org.springframework.integration.samples.cafe; +package org.springframework.integration.samples.cafe.annotation; import java.util.List; import org.springframework.integration.annotation.MessageEndpoint; import org.springframework.integration.annotation.Splitter; +import org.springframework.integration.samples.cafe.Order; +import org.springframework.integration.samples.cafe.OrderItem; /** * @author Mark Fisher diff --git a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/cafeDemo.xml b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/annotation/cafeDemo.xml similarity index 67% rename from org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/cafeDemo.xml rename to org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/annotation/cafeDemo.xml index 1956eec556..a3f96a6fbe 100644 --- a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/cafeDemo.xml +++ b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/annotation/cafeDemo.xml @@ -13,34 +13,25 @@ - + - + - + - - - - - - - - - - + diff --git a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/Barista.java b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/xml/Barista.java similarity index 90% rename from org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/Barista.java rename to org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/xml/Barista.java index d542affd15..44668ac6c1 100644 --- a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/Barista.java +++ b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/xml/Barista.java @@ -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. @@ -14,17 +14,17 @@ * limitations under the License. */ -package org.springframework.integration.samples.cafe; +package org.springframework.integration.samples.cafe.xml; import java.util.concurrent.atomic.AtomicInteger; -import org.springframework.stereotype.Component; +import org.springframework.integration.samples.cafe.Drink; +import org.springframework.integration.samples.cafe.OrderItem; /** * @author Mark Fisher * @author Marius Bogoevici */ -@Component public class Barista { private long hotDrinkDelay = 5000; diff --git a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/CafeDemo.java b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemo.java similarity index 83% rename from org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/CafeDemo.java rename to org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemo.java index 52b31b0939..0a95d4c82d 100644 --- a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/CafeDemo.java +++ b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemo.java @@ -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. @@ -14,18 +14,20 @@ * limitations under the License. */ -package org.springframework.integration.samples.cafe; +package org.springframework.integration.samples.cafe.xml; import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.context.support.FileSystemXmlApplicationContext; +import org.springframework.integration.samples.cafe.Cafe; +import org.springframework.integration.samples.cafe.DrinkType; +import org.springframework.integration.samples.cafe.Order; /** * Provides the 'main' method for running the Cafe Demo application. When an * order is placed, the Cafe will send that order to the "orders" channel. * The relevant components are defined within the configuration file - * ("cafeDemo.xml") or configured with annotations (such as the - * OrderSplitter, DrinkRouter, and Barista classes). + * ("cafeDemo.xml"). * * @author Mark Fisher * @author Marius Bogoevici diff --git a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/xml/DeliveryAssembler.java b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/xml/DeliveryAssembler.java new file mode 100644 index 0000000000..aee8777ed4 --- /dev/null +++ b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/xml/DeliveryAssembler.java @@ -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.samples.cafe.xml; + +import java.util.List; + +import org.springframework.integration.samples.cafe.Delivery; +import org.springframework.integration.samples.cafe.Drink; + +/** + * @author Marius Bogoevici + */ +public class DeliveryAssembler { + + public Delivery prepareDelivery(List drinks) { + return new Delivery(drinks); + } + +} diff --git a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/Waiter.java b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/xml/DrinkRouter.java similarity index 68% rename from org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/Waiter.java rename to org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/xml/DrinkRouter.java index eec89af3c8..1d699b4bb5 100644 --- a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/Waiter.java +++ b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/xml/DrinkRouter.java @@ -14,18 +14,17 @@ * limitations under the License. */ -package org.springframework.integration.samples.cafe; +package org.springframework.integration.samples.cafe.xml; -import org.springframework.stereotype.Component; +import org.springframework.integration.samples.cafe.OrderItem; /** - * @author Marius Bogoevici + * @author Mark Fisher */ -@Component -public class Waiter { +public class DrinkRouter { - public void serve(Delivery delivery) { - System.out.println("\nDelivering: \n" + delivery); + public String resolveOrderItemChannel(OrderItem orderItem) { + return (orderItem.isIced()) ? "coldDrinks" : "hotDrinks"; } } diff --git a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/xml/OrderSplitter.java b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/xml/OrderSplitter.java new file mode 100644 index 0000000000..2a573054b0 --- /dev/null +++ b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/xml/OrderSplitter.java @@ -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.samples.cafe.xml; + +import java.util.List; + +import org.springframework.integration.samples.cafe.Order; +import org.springframework.integration.samples.cafe.OrderItem; + +/** + * @author Mark Fisher + */ +public class OrderSplitter { + + public List split(Order order) { + return order.getDrinks(); + } + +} diff --git a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/xml/cafeDemo.xml b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/xml/cafeDemo.xml new file mode 100644 index 0000000000..8b54b792e8 --- /dev/null +++ b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/cafe/xml/cafeDemo.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +