use of org.springframework.context.support.AbstractApplicationContext in project camel by apache.
the class CamelClientRemoting method main.
// START SNIPPET: e1
public static void main(final String[] args) {
System.out.println("Notice this client requires that the CamelServer is already running!");
AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-client-remoting.xml");
// just get the proxy to the service and we as the client can use the "proxy" as it was
// a local object we are invoking. Camel will under the covers do the remote communication
// to the remote ActiveMQ server and fetch the response.
Multiplier multiplier = context.getBean("multiplierProxy", Multiplier.class);
System.out.println("Invoking the multiply with 33");
int response = multiplier.multiply(33);
System.out.println("... the result is: " + response);
// we're done so let's properly close the application context
IOHelper.close(context);
}
use of org.springframework.context.support.AbstractApplicationContext in project camel by apache.
the class CamelFileClient method main.
public static void main(final String[] args) throws Exception {
AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-file-client.xml");
// get the camel template for Spring template style sending of messages (= producer)
final ProducerTemplate producer = context.getBean("camelTemplate", ProducerTemplate.class);
// now send a lot of messages
System.out.println("Writing files ...");
for (int i = 0; i < SIZE; i++) {
producer.sendBodyAndHeader("file:target//inbox", "File " + i, Exchange.FILE_NAME, i + ".txt");
}
System.out.println("... Wrote " + SIZE + " files");
// we're done so let's properly close the application context
IOHelper.close(context);
}
use of org.springframework.context.support.AbstractApplicationContext in project java-chassis by ServiceComb.
the class CseApplicationListener method onApplicationEvent.
@Override
public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof ContextRefreshedEvent) {
ApplicationContext applicationContext = ((ContextRefreshedEvent) event).getApplicationContext();
//TODO to load when webapplication context is used for discovery client, need to check if can use the order and undo this change with proper fix.
if (!isInit) {
try {
BeanUtils.setContext(applicationContext);
bootListenerList = applicationContext.getBeansOfType(BootListener.class).values();
triggerEvent(EventType.BEFORE_HANDLER);
HandlerConfigUtils.init();
triggerEvent(EventType.AFTER_HANDLER);
triggerEvent(EventType.BEFORE_PRODUCER_PROVIDER);
producerProviderManager.init();
triggerEvent(EventType.AFTER_PRODUCER_PROVIDER);
triggerEvent(EventType.BEFORE_CONSUMER_PROVIDER);
consumerProviderManager.init();
triggerEvent(EventType.AFTER_CONSUMER_PROVIDER);
triggerEvent(EventType.BEFORE_TRANSPORT);
transportManager.init();
triggerEvent(EventType.AFTER_TRANSPORT);
schemaListenerManager.notifySchemaListener();
triggerEvent(EventType.BEFORE_REGISTRY);
RegistryUtils.init();
triggerEvent(EventType.AFTER_REGISTRY);
// TODO 服务优雅退出
if (applicationContext instanceof AbstractApplicationContext) {
((AbstractApplicationContext) applicationContext).registerShutdownHook();
}
isInit = true;
} catch (Exception e) {
LOGGER.error("cse init failed, {}", FortifyUtils.getErrorInfo(e));
}
}
} else if (event instanceof ContextClosedEvent) {
LOGGER.warn("cse is closing now...");
RegistryUtils.destory();
isInit = false;
}
}
use of org.springframework.context.support.AbstractApplicationContext in project cloudstack by apache.
the class NetworkProviderTest method globalTearDown.
@AfterClass
public static void globalTearDown() throws Exception {
s_lockMaster.cleanupForServer(s_msId);
JmxUtil.unregisterMBean("Locks", "Locks");
s_lockMaster = null;
AbstractApplicationContext ctx = (AbstractApplicationContext) ComponentContext.getApplicationContext();
Map<String, ComponentLifecycle> lifecycleComponents = ctx.getBeansOfType(ComponentLifecycle.class);
for (ComponentLifecycle bean : lifecycleComponents.values()) {
bean.stop();
}
ctx.close();
s_logger.info("destroying mysql server instance running at port <" + s_mysqlSrverPort + ">");
TestDbSetup.destroy(s_mysqlSrverPort, null);
}
use of org.springframework.context.support.AbstractApplicationContext in project camel by apache.
the class CamelProxyUsingRefTest method testCamelProxyUsingRef.
public void testCamelProxyUsingRef() throws Exception {
AbstractApplicationContext ac = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/CamelProxyUsingRefTest.xml");
MyProxySender sender = ac.getBean("myProxySender", MyProxySender.class);
String reply = sender.hello("World");
assertEquals("Hello World", reply);
// we're done so let's properly close the application context
IOHelper.close(ac);
}
Aggregations