INT-729 Added log4j configuration to the Cafe sample.
This commit is contained in:
28
spring-integration-samples/cafe/src/main/java/log4j.xml
Normal file
28
spring-integration-samples/cafe/src/main/java/log4j.xml
Normal 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">
|
||||
<level value="warn" />
|
||||
</logger>
|
||||
|
||||
<!-- Root Logger -->
|
||||
<root>
|
||||
<priority value="warn" />
|
||||
<appender-ref ref="console" />
|
||||
</root>
|
||||
|
||||
</log4j:configuration>
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* 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.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* 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.
|
||||
@@ -19,7 +19,6 @@ 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;
|
||||
import org.springframework.integration.samples.cafe.Cafe;
|
||||
import org.springframework.integration.samples.cafe.DrinkType;
|
||||
import org.springframework.integration.samples.cafe.Order;
|
||||
@@ -29,8 +28,9 @@ 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
|
||||
* <p/>
|
||||
* If deploying in SpringSource dmServer, the relevant ApplicationContext
|
||||
* configuration is in the META-INF/spring directory instead.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Marius Bogoevici
|
||||
@@ -40,17 +40,12 @@ public class CafeDemo {
|
||||
|
||||
public static void main(String[] args) {
|
||||
CafeDemo demo = new CafeDemo();
|
||||
AbstractApplicationContext applicationContext = null;
|
||||
if(args.length > 0) {
|
||||
applicationContext = new FileSystemXmlApplicationContext(args);
|
||||
}
|
||||
else {
|
||||
applicationContext = new ClassPathXmlApplicationContext("cafeDemo.xml", CafeDemo.class);
|
||||
}
|
||||
demo.performDemo(applicationContext, 100);
|
||||
AbstractApplicationContext context = new ClassPathXmlApplicationContext("cafeDemo.xml", CafeDemo.class);
|
||||
demo.performDemo(context, 100);
|
||||
}
|
||||
|
||||
public void performDemo(ApplicationContext applicationContext, int iterations){
|
||||
|
||||
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);
|
||||
@@ -59,4 +54,5 @@ public class CafeDemo {
|
||||
cafe.placeOrder(order);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* 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;
|
||||
@@ -28,30 +29,27 @@ 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.
|
||||
* An OSGi BundleActivator which will register a ServiceListener to listen for
|
||||
* an ApplicationContext published event. Once the event is received, the
|
||||
* CafeDemo will be executed.
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
* @since 1.0.3
|
||||
*/
|
||||
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))){
|
||||
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() {
|
||||
@@ -61,4 +59,5 @@ public class CafeBundleActivator implements BundleActivator, ServiceListener{
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user