INT-1380 added cafe sample

This commit is contained in:
Oleg Zhurakousky
2010-09-16 14:48:11 -04:00
parent bfd8637e25
commit 8ec1d3557b
22 changed files with 959 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" path="src/test/resources"/>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>cafe</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.maven.ide.eclipse.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -0,0 +1,6 @@
#Wed Feb 24 19:23:36 PST 2010
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.5

52
case-studies/cafe/pom.xml Normal file
View File

@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.integration.samples</groupId>
<artifactId>cafe</artifactId>
<version>2.0.0</version>
<name>Spring Integration Cafe Sample</name>
<properties>
<spring.integration.version>2.0.0.M7</spring.integration.version>
<log4j.version>1.2.15</log4j.version>
<junit.version>4.7</junit.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-core</artifactId>
<version>${spring.integration.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-stream</artifactId>
<version>${spring.integration.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<!-- test-scoped dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>false</showDeprecation>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,60 @@
The Cafe sample emulates a simple operation of the Coffee shop shop when modeled using EIP
It is inspired by one of the samples featured in Gregor Hohpe's Ramblings.
The domain is that of a Cafe, and the basic flow is depicted in the following diagram:
Barista
hotDrinks ____________________
|==========| -->| |
orders drinks / | prepareHotDrink() |
Place Order ->Cafe->|======|->OrderSplitter->|======|->DrinkRouter | |
\ coldDeinks | prepareColdDrink() |
|==========| -->| |
|____________________|
Legend: |====| - channels
The Order object may contain multiple OrderItems. Once the order is placed, a Splitter will break the
composite order message into a single message per drink. Each of these is then processed by a Router that
determines whether the drink is hot or cold (checking the OrderItem object's 'isIced' property). The Barista
prepares each drink, but hot and cold drink preparation are handled by two distinct methods: 'prepareHotDrink'
and 'prepareColdDrink'. The prepared drinks are then sent to the Waiter where they are aggregated into a
Delivery object.
Instructions for running the CafeDemo sample
-------------------------------------------------------------------------------
1. See README.txt in the parent directory.
2. To run this sample as a standalone application simply execute the CafeDemo
class in the org.springframework.integration.samples.cafe.xml package.
3. This sample is also configured to be a valid OSGi bundle. This means you can
deploy the generated JAR into an OSGi environment providing that the Spring
Integration bundles as well as other prerequisites (e.g., Spring Framework)
were installed. For example: To deploy it on SpringSource dm Server simply
drop the cafe-[version].jar file, located in the 'target' directory, to the
'pickup' directory of the dm Server instance. You should see output similar
to the following in the trace file:
. . . . . . . . . . . . .
System.out I -----------------------
[2010-07-11 01:43:04.614] task-scheduler-3 System.out I Order #1
[2010-07-11 01:43:04.614] task-scheduler-3 System.out I Iced MOCHA, 3 shots.
[2010-07-11 01:43:04.614] task-scheduler-3 System.out I Hot LATTE, 2 shots.
[2010-07-11 01:43:04.614] task-scheduler-3 System.out I -----------------------
[2010-07-11 01:43:04.618] task-scheduler-2 System.out I task-scheduler-2 prepared cold drink #5 for order #5: iced 3 shot MOCHA
[2010-07-11 01:43:05.618] task-scheduler-2 System.out I task-scheduler-2 prepared cold drink #6 for order #6: iced 3 shot MOCHA
[2010-07-11 01:43:06.618] task-scheduler-2 System.out I task-scheduler-2 prepared cold drink #7 for order #7: iced 3 shot MOCHA
[2010-07-11 01:43:07.619] task-scheduler-2 System.out I task-scheduler-2 prepared cold drink #8 for order #8: iced 3 shot MOCHA
[2010-07-11 01:43:08.619] task-scheduler-2 System.out I task-scheduler-2 prepared cold drink #9 for order #9: iced 3 shot MOCHA
[2010-07-11 01:43:09.614] task-scheduler-3 System.out I task-scheduler-3 prepared hot drink #2 for order #2: hot 2 shot LATTE
[2010-07-11 01:43:09.615] task-scheduler-3 System.out I -----------------------
[2010-07-11 01:43:09.615] task-scheduler-3 System.out I Order #2
[2010-07-11 01:43:09.615] task-scheduler-3 System.out I Iced MOCHA, 3 shots.
[2010-07-11 01:43:09.615] task-scheduler-3 System.out I Hot LATTE, 2 shots.
[2010-07-11 01:43:09.615] task-scheduler-3 System.out I -----------------------
[2010-07-11 01:43:09.620] task-scheduler-2 System.out I task-scheduler-2 prepared cold
. . . . . . . . . . . . .
Happy integration :-)

View File

@@ -0,0 +1,36 @@
/*
* Copyright 2002-2010 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;
import org.springframework.integration.annotation.Gateway;
/**
* The entry point for Cafe Demo. The demo's main() method invokes the
* '<code>placeOrder</code>' method on a generated MessagingGateway proxy.
* The gateway then passes the {@link Order} as the payload of a
* {@link org.springframework.integration.Message} to the
* configured <em>requestChannel</em>. The channel ('orders') is
* defined in the 'cafeDemo.xml' file.
*
* @author Mark Fisher
*/
public interface Cafe {
@Gateway(requestChannel="orders")
void placeOrder(Order order);
}

View File

@@ -0,0 +1,61 @@
/*
* Copyright 2002-2010 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;
import java.util.List;
/**
* @author Marius Bogoevici
*/
public class Delivery {
private static final String SEPARATOR = "-----------------------";
private List<Drink> deliveredDrinks;
private int orderNumber;
public Delivery(List<Drink> deliveredDrinks) {
assert(deliveredDrinks.size() > 0);
this.deliveredDrinks = deliveredDrinks;
this.orderNumber = deliveredDrinks.get(0).getOrderNumber();
}
public int getOrderNumber() {
return orderNumber;
}
public List<Drink> getDeliveredDrinks() {
return deliveredDrinks;
}
@Override
public String toString() {
StringBuffer buffer = new StringBuffer(SEPARATOR + "\n");
buffer.append("Order #" + getOrderNumber() + "\n");
for (Drink drink : getDeliveredDrinks()) {
buffer.append(drink);
buffer.append("\n");
}
buffer.append(SEPARATOR + "\n");
return buffer.toString();
}
}

View File

@@ -0,0 +1,50 @@
/*
* Copyright 2002-2010 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;
/**
* @author Marius Bogoevici
*/
public class Drink {
private boolean iced;
private int shots;
private DrinkType drinkType;
private int orderNumber;
public Drink(int orderNumber, DrinkType drinkType, boolean hot, int shots) {
this.orderNumber = orderNumber;
this.drinkType = drinkType;
this.iced = hot;
this.shots = shots;
}
public int getOrderNumber() {
return orderNumber;
}
@Override
public String toString() {
return (iced?"Iced":"Hot") + " " + drinkType.toString() + ", " + shots + " shots.";
}
}

View File

@@ -0,0 +1,29 @@
/*
* Copyright 2002-2010 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;
/**
* @author Mark Fisher
*/
public enum DrinkType {
ESPRESSO,
LATTE,
CAPPUCCINO,
MOCHA
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright 2002-2010 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;
import java.util.ArrayList;
import java.util.List;
/**
* @author Mark Fisher
* @author Marius Bogoevici
*/
public class Order {
private List<OrderItem> orderItems = new ArrayList<OrderItem>();
private int number;
public Order(int number) {
this.number = number;
}
public void addItem(DrinkType drinkType, int shots, boolean iced) {
this.orderItems.add(new OrderItem(this, drinkType, shots, iced));
}
public int getNumber() {
return number;
}
public List<OrderItem> getItems() {
return this.orderItems;
}
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright 2002-2010 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;
/**
* @author Mark Fisher
* @author Marius Bogoevici
*/
public class OrderItem {
private DrinkType type;
private int shots = 1;
private boolean iced = false;
private final Order order;
public OrderItem(Order order, DrinkType type, int shots, boolean iced) {
this.order = order;
this.type = type;
this.shots = shots;
this.iced = iced;
}
public Order getOrder() {
return this.order;
}
public boolean isIced() {
return this.iced;
}
public int getShots() {
return shots;
}
public DrinkType getDrinkType() {
return this.type;
}
public String toString() {
return ((this.iced) ? "iced " : "hot ") + this.shots + " shot " + this.type;
}
}

View File

@@ -0,0 +1,81 @@
/*
* Copyright 2002-2010 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.apache.log4j.Logger;
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 static Logger logger = Logger.getLogger(Barista.class);
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="hotDrinkBarista", outputChannel="preparedDrinks")
public Drink prepareHotDrink(OrderItem orderItem) {
try {
Thread.sleep(this.hotDrinkDelay);
logger.info(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="coldDrinkBarista", outputChannel="preparedDrinks")
public Drink prepareColdDrink(OrderItem orderItem) {
try {
Thread.sleep(this.coldDrinkDelay);
logger.info(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;
}
}
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright 2002-2010 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.integration.annotation.MessageEndpoint;
import org.springframework.integration.annotation.Router;
import org.springframework.integration.samples.cafe.OrderItem;
/**
* @author Mark Fisher
*/
@MessageEndpoint
public class DrinkRouter {
@Router(inputChannel="drinks")
public String resolveOrderItemChannel(OrderItem orderItem) {
return (orderItem.isIced()) ? "coldDrinks" : "hotDrinks";
}
}

View File

@@ -0,0 +1,37 @@
/*
* Copyright 2002-2010 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.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
*/
@MessageEndpoint
public class OrderSplitter {
@Splitter(inputChannel="orders", outputChannel="drinks")
public List<OrderItem> split(Order order) {
return order.getItems();
}
}

View File

@@ -0,0 +1,43 @@
/*
* Copyright 2002-2010 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.List;
import org.springframework.integration.annotation.Aggregator;
import org.springframework.integration.annotation.CorrelationStrategy;
import org.springframework.integration.annotation.MessageEndpoint;
import org.springframework.integration.samples.cafe.Delivery;
import org.springframework.integration.samples.cafe.Drink;
/**
* @author Marius Bogoevici
*/
@MessageEndpoint
public class Waiter {
@Aggregator(inputChannel = "preparedDrinks", outputChannel = "deliveries")
public Delivery prepareDelivery(List<Drink> drinks) {
return new Delivery(drinks);
}
@CorrelationStrategy
public int correlateByOrderNumber(Drink drink) {
return drink.getOrderNumber();
}
}

View File

@@ -0,0 +1,76 @@
/*
* Copyright 2002-2010 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.concurrent.atomic.AtomicInteger;
import org.apache.log4j.Logger;
import org.springframework.integration.samples.cafe.Drink;
import org.springframework.integration.samples.cafe.OrderItem;
/**
* @author Mark Fisher
* @author Marius Bogoevici
*/
public class Barista {
private static Logger logger = Logger.getLogger(Barista.class);
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;
}
public Drink prepareHotDrink(OrderItem orderItem) {
try {
Thread.sleep(this.hotDrinkDelay);
logger.info(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;
}
}
public Drink prepareColdDrink(OrderItem orderItem) {
try {
Thread.sleep(this.coldDrinkDelay);
logger.info(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;
}
}
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright 2002-2010 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 Waiter {
public Delivery prepareDelivery(List<Drink> drinks) {
return new Delivery(drinks);
}
}

View File

@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:stream="http://www.springframework.org/schema/integration/stream"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/stream
http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd">
<annotation-config/>
<context:component-scan base-package="org.springframework.integration.samples.cafe.annotation"/>
<gateway id="cafe" service-interface="org.springframework.integration.samples.cafe.Cafe"/>
<channel id="orders"/>
<channel id="drinks"/>
<channel id="coldDrinks"><queue capacity="10"/></channel>
<channel id="hotDrinks"><queue capacity="10"/></channel>
<channel id="coldDrinkBarista"/>
<channel id="hotDrinkBarista"/>
<channel id="preparedDrinks"/>
<bridge input-channel="coldDrinks" output-channel="coldDrinkBarista">
<poller fixed-delay="1000"/>
</bridge>
<bridge input-channel="hotDrinks" output-channel="hotDrinkBarista">
<poller fixed-delay="1000"/>
</bridge>
<stream:stdout-channel-adapter id="deliveries"/>
</beans:beans>

View File

@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:stream="http://www.springframework.org/schema/integration/stream"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/stream
http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd">
<gateway id="cafe" service-interface="org.springframework.integration.samples.cafe.Cafe"/>
<channel id="orders"/>
<splitter input-channel="orders" expression="payload.items" output-channel="drinks"/>
<channel id="drinks"/>
<router input-channel="drinks" expression="payload.iced ? 'coldDrinks' : 'hotDrinks'"/>
<channel id="coldDrinks">
<queue capacity="10"/>
</channel>
<service-activator input-channel="coldDrinks" ref="barista" method="prepareColdDrink" output-channel="preparedDrinks"/>
<channel id="hotDrinks">
<queue capacity="10"/>
</channel>
<service-activator input-channel="hotDrinks" ref="barista" method="prepareHotDrink" output-channel="preparedDrinks"/>
<channel id="preparedDrinks"/>
<aggregator input-channel="preparedDrinks" method="prepareDelivery" output-channel="deliveries">
<beans:bean class="org.springframework.integration.samples.cafe.xml.Waiter"/>
</aggregator>
<stream:stdout-channel-adapter id="deliveries"/>
<beans:bean id="barista" class="org.springframework.integration.samples.cafe.xml.Barista"/>
<poller id="poller" default="true" fixed-delay="1000"/>
</beans:beans>

View File

@@ -0,0 +1,53 @@
/*
* Copyright 2002-2010 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.junit.Test;
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 CafeDemoTestAnnotation {
@Test
public void testCafeDemoWithAnnotationSupport() {
AbstractApplicationContext context =
new ClassPathXmlApplicationContext("/META-INF/spring/integration/cafeDemo-annotation.xml", CafeDemoTestAnnotation.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);
}
context.close();
}
}

View File

@@ -0,0 +1,55 @@
/*
* Copyright 2002-2010 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 org.junit.Test;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
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").
* <p/>
* If deploying in SpringSource dmServer, the relevant ApplicationContext
* configuration is in the META-INF/spring directory instead.
*
* @author Mark Fisher
* @author Marius Bogoevici
* @author Oleg Zhurakousky
*/
public class CafeDemoTestXml {
@Test
public void testCafeDemoWithXmlSupport() {
AbstractApplicationContext context =
new ClassPathXmlApplicationContext("/META-INF/spring/integration/cafeDemo-xml.xml", CafeDemoTestXml.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);
}
context.close();
}
}

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- Appenders -->
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p: %c - %m%n" />
</layout>
</appender>
<!-- Loggers -->
<logger name="org.springframework">
<level value="warn" />
</logger>
<logger name="org.springframework.integration.samples">
<level value="debug" />
</logger>
<!-- Root Logger -->
<root>
<priority value="warn" />
<appender-ref ref="console" />
</root>
</log4j:configuration>