Search in sources :

Example 11 with AbstractApplicationContext

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);
}
Also used : AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Multiplier(org.apache.camel.example.server.Multiplier)

Example 12 with AbstractApplicationContext

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);
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext)

Example 13 with AbstractApplicationContext

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;
    }
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) ContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent) ContextClosedEvent(org.springframework.context.event.ContextClosedEvent)

Example 14 with AbstractApplicationContext

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);
}
Also used : AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) ComponentLifecycle(com.cloud.utils.component.ComponentLifecycle) AfterClass(org.junit.AfterClass)

Example 15 with AbstractApplicationContext

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);
}
Also used : AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext)

Aggregations

AbstractApplicationContext (org.springframework.context.support.AbstractApplicationContext)27 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)13 Test (org.junit.Test)6 ApplicationContext (org.springframework.context.ApplicationContext)6 CamelContext (org.apache.camel.CamelContext)4 ProducerTemplate (org.apache.camel.ProducerTemplate)3 ComponentLifecycle (com.cloud.utils.component.ComponentLifecycle)2 GlobalSettings (com.openmeap.model.dto.GlobalSettings)2 Method (java.lang.reflect.Method)2 AfterClass (org.junit.AfterClass)2 FileSystemXmlApplicationContext (org.springframework.context.support.FileSystemXmlApplicationContext)2 StopWatch (org.springframework.util.StopWatch)2 AuthorizerImpl (com.openmeap.AuthorizerImpl)1 InvalidPropertiesException (com.openmeap.model.InvalidPropertiesException)1 ModelManager (com.openmeap.model.ModelManager)1 ModelServiceImpl (com.openmeap.model.ModelServiceImpl)1 ClusterNode (com.openmeap.model.dto.ClusterNode)1 MapPayloadEvent (com.openmeap.model.event.MapPayloadEvent)1 Result (com.openmeap.services.dto.Result)1 JSONObject (com.openmeap.thirdparty.org.json.me.JSONObject)1