domain updates + new runnable class

This commit is contained in:
Tom McCuch
2011-10-31 13:04:28 -04:00
parent a32ed6647b
commit 15dc7cd059
10 changed files with 172 additions and 30 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 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,16 +20,18 @@ import java.util.List;
/**
* @author Marius Bogoevici
* @author Tom McCuch
*/
public class Delivery {
private static final String SEPARATOR = "-----------------------";
private List<Drink> deliveredDrinks;
private int orderNumber;
// Default constructor required by Jackson Java JSON-processor
public Delivery() {}
public Delivery(List<Drink> deliveredDrinks) {
assert(deliveredDrinks.size() > 0);
@@ -42,10 +44,18 @@ public class Delivery {
return orderNumber;
}
public void setOrderNumber(int orderNumber) {
this.orderNumber = orderNumber;
}
public List<Drink> getDeliveredDrinks() {
return deliveredDrinks;
}
public void setDeliveredDrinks(List<Drink> deliveredDrinks) {
this.deliveredDrinks = deliveredDrinks;
}
@Override
public String toString() {
StringBuffer buffer = new StringBuffer(SEPARATOR + "\n");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 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.
@@ -18,6 +18,7 @@ package org.springframework.integration.samples.cafe;
/**
* @author Marius Bogoevici
* @author Tom McCuch
*/
public class Drink {
@@ -30,10 +31,13 @@ public class Drink {
private int orderNumber;
public Drink(int orderNumber, DrinkType drinkType, boolean hot, int shots) {
// Default constructor required by Jackson Java JSON-processor
public Drink() {}
public Drink(int orderNumber, DrinkType drinkType, boolean iced, int shots) {
this.orderNumber = orderNumber;
this.drinkType = drinkType;
this.iced = hot;
this.iced = iced;
this.shots = shots;
}
@@ -42,6 +46,34 @@ public class Drink {
return orderNumber;
}
public void setOrderNumber(int orderNumber) {
this.orderNumber = orderNumber;
}
public boolean isIced() {
return this.iced;
}
public void setIced(boolean iced) {
this.iced = iced;
}
public DrinkType getDrinkType() {
return this.drinkType;
}
public void setDrinkType(DrinkType drinkType) {
this.drinkType = drinkType;
}
public int getShots() {
return this.shots;
}
public void setShots(int shots) {
this.shots = shots;
}
@Override
public String toString() {
return (iced?"Iced":"Hot") + " " + drinkType.toString() + ", " + shots + " shots.";

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 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.

View File

@@ -22,6 +22,7 @@ import java.util.List;
/**
* @author Mark Fisher
* @author Marius Bogoevici
* @author Tom McCuch
*/
public class Order {
@@ -29,20 +30,30 @@ public class Order {
private int number;
// Default constructor required by Jackson Java JSON-processor
public Order() {}
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));
this.orderItems.add(new OrderItem(this.number, drinkType, shots, iced));
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public List<OrderItem> getItems() {
return this.orderItems;
}
public void setItems(List<OrderItem> orderItems) {
this.orderItems = orderItems;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 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,6 +19,7 @@ package org.springframework.integration.samples.cafe;
/**
* @author Mark Fisher
* @author Marius Bogoevici
* @author Tom McCuch
*/
public class OrderItem {
@@ -28,34 +29,51 @@ public class OrderItem {
private boolean iced = false;
private final Order order;
private int orderNumber;
// Default constructor required by Jackson Java JSON-processor
public OrderItem() {}
public OrderItem(Order order, DrinkType type, int shots, boolean iced) {
this.order = order;
public OrderItem(int orderNumber, DrinkType type, int shots, boolean iced) {
this.orderNumber = orderNumber;
this.type = type;
this.shots = shots;
this.iced = iced;
}
public Order getOrder() {
return this.order;
public int getOrderNumber() {
return this.orderNumber;
}
public void setOrderNumber(int orderNumber) {
this.orderNumber = orderNumber;
}
public boolean isIced() {
return this.iced;
}
public int getShots() {
public void setIced(boolean iced) {
this.iced = iced;
}
public int getShots() {
return shots;
}
public DrinkType getDrinkType() {
public void setShots(int shots) {
this.shots = shots;
}
public DrinkType getDrinkType() {
return this.type;
}
public String toString() {
public void setDrinkType(DrinkType type) {
this.type = type;
}
public String toString() {
return ((this.iced) ? "iced " : "hot ") + this.shots + " shot " + this.type;
}

View File

@@ -27,7 +27,9 @@ import org.springframework.stereotype.Component;
/**
* @author Mark Fisher
* @author Marius Bogoevici
* @author Tom McCuch
*/
@Component
public class Barista {
private static Logger logger = Logger.getLogger(Barista.class);
@@ -54,8 +56,8 @@ public class Barista {
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.getOrderNumber() + ": " + orderItem);
return new Drink(orderItem.getOrderNumber(), orderItem.getDrinkType(), orderItem.isIced(),
orderItem.getShots());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
@@ -69,8 +71,8 @@ public class Barista {
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.getOrderNumber() + ": " + orderItem);
return new Drink(orderItem.getOrderNumber(), orderItem.getDrinkType(), orderItem.isIced(),
orderItem.getShots());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 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.
@@ -25,7 +25,9 @@ import org.springframework.integration.samples.cafe.OrderItem;
/**
* @author Mark Fisher
* @author Marius Bogoevici
* @author Tom McCuch
*/
public class Barista {
private static Logger logger = Logger.getLogger(Barista.class);
private long hotDrinkDelay = 5000;
@@ -50,8 +52,8 @@ public class Barista {
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.getOrderNumber() + ": " + orderItem);
return new Drink(orderItem.getOrderNumber(), orderItem.getDrinkType(), orderItem.isIced(),
orderItem.getShots());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
@@ -64,8 +66,8 @@ public class Barista {
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.getOrderNumber() + ": " + orderItem);
return new Drink(orderItem.getOrderNumber(), orderItem.getDrinkType(), orderItem.isIced(),
orderItem.getShots());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();

View File

@@ -0,0 +1,60 @@
/*
* Copyright 2002-2011 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.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
* using AMQP. Before running, be sure to have a RabbitMQ broker
* started on localhost:5672 configured with the default
* guest | guest client credentials on the / vHost. When an order is
* placed, the Cafe will send that order to the "orders" channel.
* <p/>
* The relevant components are defined within the configuration files:
* ("cafeDemo-amqp-xml.xml", "cafeDemo-amqp-baristaCold-xml.xml, and
* "cafeDemo-amqp-baristaHot-xml.xml).
* <p/>
* If deploying in SpringSource dmServer, the relevant ApplicationContext
* configuration is in the META-INF/spring directory instead.
*
* @author Tom McCuch
*/
public class CafeDemoAppAmqp {
public static void main(String[] args) {
AbstractApplicationContext context =
new ClassPathXmlApplicationContext(
new String[] {"/META-INF/spring/integration/amqp/cafeDemo-amqp-xml.xml",
"/META-INF/spring/integration/amqp/cafeDemo-amqp-baristaCold-xml.xml",
"/META-INF/spring/integration/amqp/cafeDemo-amqp-baristaHot-xml.xml"},
CafeDemoAppAmqp.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

@@ -22,9 +22,8 @@
<int:wire-tap channel="logger" pattern="orders,coldDrinks,hotDrinks,preparedDrinks,deliveries"/>
<int:logging-channel-adapter id="logger" log-full-message="true" level="INFO"/>
<int-amqp:inbound-channel-adapter queue-names="new-orders" channel="jsonOrders" connection-factory="rabbitConnectionFactory" acknowledge-mode="AUTO" />
<int:json-to-object-transformer id="json-to-order" input-channel="jsonOrders" output-channel="orders" type="org.springframework.integration.samples.cafe.Order" />
<int:gateway id="cafe" service-interface="org.springframework.integration.samples.cafe.Cafe"
default-request-channel="orders"/>
<int:splitter input-channel="orders" expression="payload.items" output-channel="preDrinks" apply-sequence="true"/>

View File

@@ -6,7 +6,7 @@
<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" />
<param name="ConversionPattern" value="%t %-5p: %c - %m%n" />
</layout>
</appender>
@@ -15,6 +15,14 @@
<level value="warn" />
</logger>
<logger name="org.springframework.amqp">
<level value="info" />
</logger>
<logger name="org.springframework.integration">
<level value="info" />
</logger>
<logger name="org.springframework.integration.samples">
<level value="debug" />
</logger>