INT-718, OSGi-enabled Cafe sample. README provided
This commit is contained in:
35
spring-integration-samples/cafe/README.txt
Normal file
35
spring-integration-samples/cafe/README.txt
Normal file
@@ -0,0 +1,35 @@
|
||||
Instructions for running CafeDemo sample
|
||||
-------------------------------------------------------------------------------
|
||||
1. See README.txt of the parent directory
|
||||
|
||||
2. To run this sample as stand alone application simply execute HelloWorldDemo class
|
||||
located in org.springframework.integration.samples.cafe package
|
||||
|
||||
3. This sample is also configured to be a valid OSGi bundle. This means you can deploy generated JAR
|
||||
into OSGi environment providing that Spring Integration bundles as well as other prerequisites
|
||||
(e.g., Spring Framework were installed).
|
||||
For example: To deploy it on SpringSource dmServer simply drop cafe-1.0.3.jar file, located
|
||||
in the 'target' directory, to the 'pickup' directory of the dmServer.
|
||||
You should see the following output in the trace file:
|
||||
|
||||
. . . . . . . . . . . . .
|
||||
System.out I -----------------------
|
||||
[2009-07-11 01:43:04.614] task-scheduler-3 System.out I Order #1
|
||||
[2009-07-11 01:43:04.614] task-scheduler-3 System.out I Iced MOCHA, 3 shots.
|
||||
[2009-07-11 01:43:04.614] task-scheduler-3 System.out I Hot LATTE, 2 shots.
|
||||
[2009-07-11 01:43:04.614] task-scheduler-3 System.out I -----------------------
|
||||
[2009-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
|
||||
[2009-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
|
||||
[2009-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
|
||||
[2009-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
|
||||
[2009-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
|
||||
[2009-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
|
||||
[2009-07-11 01:43:09.615] task-scheduler-3 System.out I -----------------------
|
||||
[2009-07-11 01:43:09.615] task-scheduler-3 System.out I Order #2
|
||||
[2009-07-11 01:43:09.615] task-scheduler-3 System.out I Iced MOCHA, 3 shots.
|
||||
[2009-07-11 01:43:09.615] task-scheduler-3 System.out I Hot LATTE, 2 shots.
|
||||
[2009-07-11 01:43:09.615] task-scheduler-3 System.out I -----------------------
|
||||
[2009-07-11 01:43:09.620] task-scheduler-2 System.out I task-scheduler-2 prepared cold
|
||||
. . . . . . . . . . . . .
|
||||
|
||||
Happy integration :-)
|
||||
@@ -8,4 +8,34 @@
|
||||
<groupId>cafe</groupId>
|
||||
<artifactId>cafe</artifactId>
|
||||
<version>1.0.3</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi</artifactId>
|
||||
<version>3.4.2.R34x_v20080826-1230</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<filtering>false</filtering>
|
||||
<directory>${basedir}/src/main/resources</directory>
|
||||
<includes>
|
||||
<include>META-INF/spring/*.xml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
</project>
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.integration.samples.cafe.xml;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.context.support.FileSystemXmlApplicationContext;
|
||||
@@ -28,27 +29,34 @@ import org.springframework.integration.samples.cafe.Order;
|
||||
* order is placed, the Cafe will send that order to the "orders" channel.
|
||||
* The relevant components are defined within the configuration file
|
||||
* ("cafeDemo.xml").
|
||||
* If deployed in SpringSource dmServer the ApplicationContext configuration is in
|
||||
* META-INF/spring directory
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Marius Bogoevici
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public class CafeDemo {
|
||||
|
||||
public static void main(String[] args) {
|
||||
AbstractApplicationContext context = null;
|
||||
CafeDemo demo = new CafeDemo();
|
||||
AbstractApplicationContext applicationContext = null;
|
||||
if(args.length > 0) {
|
||||
context = new FileSystemXmlApplicationContext(args);
|
||||
applicationContext = new FileSystemXmlApplicationContext(args);
|
||||
}
|
||||
else {
|
||||
context = new ClassPathXmlApplicationContext("cafeDemo.xml", CafeDemo.class);
|
||||
applicationContext = new ClassPathXmlApplicationContext("cafeDemo.xml", CafeDemo.class);
|
||||
}
|
||||
Cafe cafe = (Cafe) context.getBean("cafe");
|
||||
for (int i = 1; i <= 100; i++) {
|
||||
demo.performDemo(applicationContext, 100);
|
||||
}
|
||||
|
||||
public void performDemo(ApplicationContext applicationContext, int iterations){
|
||||
Cafe cafe = (Cafe) applicationContext.getBean("cafe");
|
||||
for (int i = 1; i <= iterations; i++) {
|
||||
Order order = new Order(i);
|
||||
order.addItem(DrinkType.LATTE, 2, false);
|
||||
order.addItem(DrinkType.MOCHA, 3, true);
|
||||
cafe.placeOrder(order);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2002-2009 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.osgi.cafe;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.osgi.framework.BundleActivator;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.Constants;
|
||||
import org.osgi.framework.ServiceEvent;
|
||||
import org.osgi.framework.ServiceListener;
|
||||
import org.osgi.framework.ServiceReference;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.integration.samples.cafe.xml.CafeDemo;
|
||||
|
||||
/**
|
||||
* Simple BundleActivator which will register ServiceListener which will listen for
|
||||
* ApplicationContext published event. Once event is received, CafeDemo will be executed.
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public class CafeBundleActivator implements BundleActivator, ServiceListener{
|
||||
private BundleContext context;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void start(BundleContext context) throws Exception {
|
||||
this.context = context;
|
||||
context.addServiceListener(this);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void stop(BundleContext context) throws Exception {}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void serviceChanged(ServiceEvent serviceEvent) {
|
||||
ServiceReference sr = serviceEvent.getServiceReference();
|
||||
if (context.getBundle().getSymbolicName().equals(sr.getProperty(Constants.BUNDLE_SYMBOLICNAME))){
|
||||
final ApplicationContext applicationContext = (ApplicationContext) context.getService(sr);
|
||||
ExecutorService executor = Executors.newCachedThreadPool();
|
||||
executor.execute(new Runnable() {
|
||||
public void run() {
|
||||
new CafeDemo().performDemo(applicationContext, 20);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-Version: 1.0.3
|
||||
Bundle-Name: org.springframework.integration.samples.cafe
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-SymbolicName: org.springframework.integration.samples.cafe
|
||||
Bundle-Activator: org.springframework.integration.samples.osgi.cafe.CafeBundleActivator
|
||||
Import-Package: org.osgi.framework;version="[1.4.0,1.4.0]"
|
||||
Import-Library: org.aspectj;version="[1.6.2.RELEASE,1.6.2.RELEASE]",
|
||||
org.springframework.spring;version="[2.5.6.A,2.5.6.A]"
|
||||
Import-Bundle: org.springframework.integration;version="(1.0.2,1.0.4)",
|
||||
org.springframework.integration.stream;version="(1.0.2,1.0.4)"
|
||||
@@ -0,0 +1,48 @@
|
||||
<?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-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
|
||||
http://www.springframework.org/schema/integration/stream
|
||||
http://www.springframework.org/schema/integration/stream/spring-integration-stream-1.0.xsd">
|
||||
|
||||
<gateway id="cafe" service-interface="org.springframework.integration.samples.cafe.Cafe"/>
|
||||
|
||||
<channel id="orders"/>
|
||||
<splitter input-channel="orders" method="split" output-channel="drinks">
|
||||
<beans:bean class="org.springframework.integration.samples.cafe.xml.OrderSplitter"/>
|
||||
</splitter>
|
||||
|
||||
<channel id="drinks"/>
|
||||
<router input-channel="drinks" method="resolveOrderItemChannel">
|
||||
<beans:bean class="org.springframework.integration.samples.cafe.xml.DrinkRouter"/>
|
||||
</router>
|
||||
|
||||
<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">
|
||||
<interval-trigger interval="1000"/>
|
||||
</poller>
|
||||
|
||||
</beans:beans>
|
||||
Reference in New Issue
Block a user