当前位置: 首页>>代码示例>>Java>>正文


Java DefaultCamelContext.stop方法代码示例

本文整理汇总了Java中org.apache.camel.impl.DefaultCamelContext.stop方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultCamelContext.stop方法的具体用法?Java DefaultCamelContext.stop怎么用?Java DefaultCamelContext.stop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.camel.impl.DefaultCamelContext的用法示例。


在下文中一共展示了DefaultCamelContext.stop方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: runCafeRouteDemo

import org.apache.camel.impl.DefaultCamelContext; //导入方法依赖的package包/类
public void runCafeRouteDemo() throws Exception {
    // create CamelContext
    DefaultCamelContext camelContext = new DefaultCamelContext();
    camelContext.setRegistry(createRegistry());
    camelContext.addRoutes(this);
    camelContext.start();
    
    ProducerTemplate template = camelContext.createProducerTemplate();
    
    Order order = new Order(2);
    order.addItem(DrinkType.ESPRESSO, 2, true);
    order.addItem(DrinkType.CAPPUCCINO, 4, false);
    order.addItem(DrinkType.LATTE, 4, false);
    order.addItem(DrinkType.MOCHA, 2, false);
    
    template.sendBody("direct:cafe", order);
    
    Thread.sleep(6000);
    camelContext.stop();
    
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:CafeRouteBuilder.java

示例2: testThirdCamelContext

import org.apache.camel.impl.DefaultCamelContext; //导入方法依赖的package包/类
@Test
public void testThirdCamelContext() throws Exception {
    camel1.stop();
    
    camel2.stop();
            
    DefaultCamelContext camel3 = new DefaultCamelContext();
    camel3.setName("camel-3");
    camel3.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("quartz2://myThirdGroup/myThirdTimerName?cron=0/1+*+*+*+*+?").to("mock:three");
        }
    });
    camel3.start();
    
    MockEndpoint mock3 = camel3.getEndpoint("mock:three", MockEndpoint.class);
    mock3.expectedMinimumMessageCount(2);
    
    mock3.assertIsSatisfied();
    camel3.stop();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:QuartzTwoCamelContextTest.java

示例3: testRestart

import org.apache.camel.impl.DefaultCamelContext; //导入方法依赖的package包/类
/**
 * Make sure a resume doesn't trigger a dupe name error.
 */
@Test
public void testRestart() throws Exception {
    DefaultCamelContext camel = new DefaultCamelContext();

    camel.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("quartz2://myGroup/myTimerName?cron=0/1+*+*+*+*+?").to("log:one", "mock:one");
        }
    });

    // traverse a litany of states
    camel.start();
    Thread.sleep(100);
    camel.suspend();
    Thread.sleep(100);
    camel.resume();
    Thread.sleep(100);
    camel.stop();
    Thread.sleep(100);
    camel.start();
    Thread.sleep(100);
    camel.stop();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:28,代码来源:QuartzNameCollisionTest.java

示例4: camelContextFactoryServiceRegistryTest

import org.apache.camel.impl.DefaultCamelContext; //导入方法依赖的package包/类
@Test
public void camelContextFactoryServiceRegistryTest() throws Exception {
    DefaultCamelContext context = new OsgiDefaultCamelContext(getBundleContext());
    context.start();

    MyService myService = context.getRegistry().lookupByNameAndType(MyService.class.getName(), MyService.class);
    assertNotNull("MyService should not be null", myService);
    
    myService = context.getRegistry().lookupByNameAndType("test", MyService.class);
    assertNull("We should not get the MyService Object here", myService);

    Object service = context.getRegistry().lookupByName(MyService.class.getName());
    assertNotNull("MyService should not be null", service);
    assertTrue("It should be the instance of MyService ", service instanceof MyService);

    Map<String, MyService> collection = context.getRegistry().findByTypeWithName(MyService.class);
    assertNotNull("MyService should not be null", collection);
    assertNotNull("There should have one MyService.", collection.get(MyService.class.getName()));

    Set<MyService> collection2 = context.getRegistry().findByType(MyService.class);
    assertNotNull("MyService should not be null", collection2);
    assertEquals(1, collection2.size());

    context.stop();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:26,代码来源:ServiceRegistryTest.java

示例5: testThirdCamelContext

import org.apache.camel.impl.DefaultCamelContext; //导入方法依赖的package包/类
@Test
public void testThirdCamelContext() throws Exception {
    camel1.stop();
    
    camel2.stop();
            
    DefaultCamelContext camel3 = new DefaultCamelContext();
    camel3.setName("camel-3");
    camel3.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("quartz://myThirdGroup/myThirdTimerName?cron=0/1+*+*+*+*+?").to("mock:three");
        }
    });
    camel3.start();
    
    MockEndpoint mock3 = camel3.getEndpoint("mock:three", MockEndpoint.class);
    mock3.expectedMinimumMessageCount(2);
    
    mock3.assertIsSatisfied();
    camel3.stop();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:QuartzTwoCamelContextTest.java

示例6: testRestart

import org.apache.camel.impl.DefaultCamelContext; //导入方法依赖的package包/类
/**
 * Make sure a resume doesn't trigger a dupe name error.
 */
@Test
public void testRestart() throws Exception {
    DefaultCamelContext camel = new DefaultCamelContext();

    camel.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("quartz://myGroup/myTimerName?cron=0/1+*+*+*+*+?").to("log:one", "mock:one");
        }
    });

    // traverse a litany of states
    camel.start();
    Thread.sleep(100);
    camel.suspend();
    Thread.sleep(100);
    camel.resume();
    Thread.sleep(100);
    camel.stop();
    Thread.sleep(100);
    camel.start();
    Thread.sleep(100);
    camel.stop();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:28,代码来源:QuartzNameCollisionTest.java

示例7: shouldNotBreakRedeliveriesOfSecondContextAfterFirstBeingStopped

import org.apache.camel.impl.DefaultCamelContext; //导入方法依赖的package包/类
@Test
public void shouldNotBreakRedeliveriesOfSecondContextAfterFirstBeingStopped() throws Exception {
    DefaultCamelContext context1 = createContext();
    ProducerTemplate producer1 = context1.createProducerTemplate();
    ConsumerTemplate consumer1 = context1.createConsumerTemplate();
    context1.start();
    producer1.sendBody("seda://input", "Hey1");
    Exchange ex1 = consumer1.receive("seda://output", 5000);

    DefaultCamelContext context2 = createContext();
    ProducerTemplate producer2 = context2.createProducerTemplate();
    ConsumerTemplate consumer2 = context2.createConsumerTemplate();
    context2.start();

    // now stop 1, and see that 2 is still working
    consumer1.stop();
    producer1.stop();
    context1.stop();

    producer2.sendBody("seda://input", "Hey2");
    Exchange ex2 = consumer2.receive("seda://output", 5000);

    Assert.assertNotNull(ex1);
    Assert.assertEquals("Hey1", ex1.getIn().getBody());
    Assert.assertNotNull(ex2);
    Assert.assertEquals("Hey2", ex2.getIn().getBody());

    consumer2.stop();
    producer2.stop();
    context2.stop();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:32,代码来源:RedeliveryErrorHandlerAsyncDelayedTwoCamelContextIssueTest.java

示例8: testProducer

import org.apache.camel.impl.DefaultCamelContext; //导入方法依赖的package包/类
public void testProducer() throws Exception {
    // use shutdown hook to verify that we have stopped within 5 seconds
    Thread hook = new AssertShutdownHook();
    Runtime.getRuntime().addShutdownHook(hook);

    start = System.currentTimeMillis();

    context = new DefaultCamelContext();
    context.addRoutes(createRouteBuilder());
    context.start();

    sendMessage();

    context.stop();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:16,代码来源:MinaProducerShutdownTest.java

示例9: sendMessage

import org.apache.camel.impl.DefaultCamelContext; //导入方法依赖的package包/类
public void sendMessage() throws Exception {        
    DefaultCamelContext context = new DefaultCamelContext();
    
    final CountDownLatch logonLatch = new CountDownLatch(4);
    final CountDownLatch receivedMessageLatch = new CountDownLatch(1);
    
    RouteBuilder routes = new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            // Release latch when session logon events are received
            // We expect four logon events (four sessions)
            from("quickfix:examples/gateway.cfg").
                filter(header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.SessionLogon)).
                bean(new CountDownLatchDecrementer("logon", logonLatch));

            // Dynamic router -- Uses FIX DeliverTo tags
            from("quickfix:examples/gateway.cfg").
                filter(header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageReceived)).
                recipientList(method(new FixMessageRouter("quickfix:examples/gateway.cfg")));

            // Logger app messages as JSON
            from("quickfix:examples/gateway.cfg").
                filter(PredicateBuilder.or(
                        header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageReceived),
                        header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageSent))).
                bean(new QuickfixjMessageJsonPrinter());
            
            // If the [email protected] session receives an email then release the latch
            from("quickfix:examples/gateway.cfg?sessionID=FIX.4.2:[email protected]>GATEWAY").
                filter(PredicateBuilder.and(
                        header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageReceived),
                        header(QuickfixjEndpoint.MESSAGE_TYPE_KEY).isEqualTo(MsgType.EMAIL))).
                bean(new CountDownLatchDecrementer("message", receivedMessageLatch));
        }
    };
    
    context.addRoutes(routes);
    
    LOG.info("Starting Camel context");
    context.start();
    
    // This is not strictly necessary, but it prevents the need for session
    // synchronization due to app messages being sent before being logged on
    if (!logonLatch.await(5, TimeUnit.SECONDS)) {
        throw new IllegalStateException("Logon did not complete");
    }
    
    String gatewayUri = "quickfix:examples/gateway.cfg?sessionID=FIX.4.2:[email protected]>GATEWAY";
    Endpoint gatewayEndpoint = context.getEndpoint(gatewayUri);
    Producer producer = gatewayEndpoint.createProducer();
    
    Email email = TestSupport.createEmailMessage("Dynamic Routing Example");
    email.getHeader().setString(DeliverToCompID.FIELD, "[email protected]");
    
    LOG.info("Sending routed message");
    
    Exchange exchange = producer.createExchange(ExchangePattern.InOnly);
    exchange.getIn().setBody(email);
    producer.process(exchange);            

    if (!receivedMessageLatch.await(5, TimeUnit.SECONDS)) {
        throw new IllegalStateException("Message did not reach target");
    }
    
    LOG.info("Message received, shutting down Camel context");
    
    context.stop();
    
    LOG.info("Dynamic routing example complete");
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:71,代码来源:DynamicRoutingExample.java

示例10: sendMessage

import org.apache.camel.impl.DefaultCamelContext; //导入方法依赖的package包/类
public void sendMessage() throws Exception {        
    DefaultCamelContext context = new DefaultCamelContext();
    context.addComponent("trade-executor", new TradeExecutorComponent());
    
    final CountDownLatch logonLatch = new CountDownLatch(2);
    final CountDownLatch executionReportLatch = new CountDownLatch(2);
    
    RouteBuilder routes = new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            // Release latch when session logon events are received
            from("quickfix:examples/inprocess.cfg").
                filter(header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.SessionLogon)).
                bean(new CountDownLatchDecrementer("logon", logonLatch));

            from("quickfix:examples/inprocess.cfg?sessionID=FIX.4.2:MARKET->TRADER").
                filter(header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageReceived)).
                to("trade-executor:market");

            from("trade-executor:market").to("quickfix:examples/inprocess.cfg");
            
            // Logger app messages as JSON
            from("quickfix:examples/inprocess.cfg").
                filter(PredicateBuilder.or(
                    header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageReceived),
                    header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageSent))).
                bean(new QuickfixjMessageJsonPrinter());
            
            // Release latch when trader receives execution report
            from("quickfix:examples/inprocess.cfg?sessionID=FIX.4.2:TRADER->MARKET").
                filter(PredicateBuilder.and(
                    header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageReceived),
                    header(QuickfixjEndpoint.MESSAGE_TYPE_KEY).isEqualTo(MsgType.EXECUTION_REPORT))).
                bean(new CountDownLatchDecrementer("execution report", executionReportLatch));
        }
    };
    
    context.addRoutes(routes);
    
    LOG.info("Starting Camel context");
    context.start();
    
    // This is not strictly necessary, but it prevents the need for session
    // synchronization due to app messages being sent before being logged on
    if (!logonLatch.await(5, TimeUnit.SECONDS)) {
        throw new IllegalStateException("Logon did not complete");
    }
    
    String gatewayUri = "quickfix:examples/inprocess.cfg?sessionID=FIX.4.2:TRADER->MARKET";
    Endpoint gatewayEndpoint = context.getEndpoint(gatewayUri);
    Producer producer = gatewayEndpoint.createProducer();
    
    LOG.info("Sending order");
    
    NewOrderSingle order = createNewOrderMessage();
    Exchange exchange = producer.createExchange(ExchangePattern.InOnly);
    exchange.getIn().setBody(order);
    producer.process(exchange);            

    if (!executionReportLatch.await(5, TimeUnit.SECONDS)) {
        throw new IllegalStateException("Did not receive execution reports");
    }
    
    LOG.info("Message received, shutting down Camel context");
    
    context.stop();
    
    LOG.info("Order execution example complete");
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:70,代码来源:TradeExecutorExample.java

示例11: sendMessage

import org.apache.camel.impl.DefaultCamelContext; //导入方法依赖的package包/类
public void sendMessage() throws Exception {        
    DefaultCamelContext context = new DefaultCamelContext();
    
    final CountDownLatch logonLatch = new CountDownLatch(2);
    final CountDownLatch receivedMessageLatch = new CountDownLatch(1);
    
    RouteBuilder routes = new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            // Release latch when session logon events are received
            // We expect two events, one for the trader session and one for the market session
            from("quickfix:examples/inprocess.cfg").
                filter(header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.SessionLogon)).
                bean(new CountDownLatchDecrementer("logon", logonLatch));

            // For all received messages, print the JSON-formatted message to stdout
            from("quickfix:examples/inprocess.cfg").
                filter(PredicateBuilder.or(
                        header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AdminMessageReceived),
                        header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageReceived))).
                bean(new QuickfixjMessageJsonPrinter());

            // If the market session receives an email then release the latch
            from("quickfix:examples/inprocess.cfg?sessionID=FIX.4.2:MARKET->TRADER").
                filter(header(QuickfixjEndpoint.MESSAGE_TYPE_KEY).isEqualTo(MsgType.EMAIL)).
                bean(new CountDownLatchDecrementer("message", receivedMessageLatch));
        }
    };
    
    context.addRoutes(routes);
    
    LOG.info("Starting Camel context");
    context.start();
    
    if (!logonLatch.await(5L, TimeUnit.SECONDS)) {
        throw new IllegalStateException("Logon did not succeed");
    }
    
    String marketUri = "quickfix:examples/inprocess.cfg?sessionID=FIX.4.2:TRADER->MARKET";
    Producer producer = context.getEndpoint(marketUri).createProducer();
    
    Email email = TestSupport.createEmailMessage("Example");
    Exchange exchange = producer.createExchange(ExchangePattern.InOnly);
    exchange.getIn().setBody(email);
    producer.process(exchange);            

    if (!receivedMessageLatch.await(5L, TimeUnit.SECONDS)) {
        throw new IllegalStateException("Message did not reach market");
    }
    
    LOG.info("Message received, shutting down Camel context");
    
    context.stop();
    
    LOG.info("Example complete");
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:57,代码来源:SimpleMessagingExample.java

示例12: run

import org.apache.camel.impl.DefaultCamelContext; //导入方法依赖的package包/类
public void run() throws Exception {        
    DefaultCamelContext context = new DefaultCamelContext();
    
    final CountDownLatch logoutLatch = new CountDownLatch(1);
    
    RouteBuilder routes = new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            // Modify the outgoing logon message to add a password
            // The modified message will be sent from the FIX engine when the message exchange completes
            from("quickfix:examples/inprocess.cfg?sessionID=FIX.4.2:TRADER->MARKET").
                filter(PredicateBuilder.and(
                        header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AdminMessageSent),
                        header(QuickfixjEndpoint.MESSAGE_TYPE_KEY).isEqualTo(MsgType.LOGON))).
                bean(new CredentialInjector("PASSWORD"));

            // Release latch when the trader received a logout message
            from("quickfix:examples/inprocess.cfg?sessionID=FIX.4.2:TRADER->MARKET").
                filter(header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.SessionLogoff)).
                bean(new CountDownLatchDecrementer("logout", logoutLatch));

            // Reject all logons on market side
            // Demonstrates how to validate logons
            from("quickfix:examples/inprocess.cfg?sessionID=FIX.4.2:MARKET->TRADER").
                filter(PredicateBuilder.and(
                        header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AdminMessageReceived),
                        header(QuickfixjEndpoint.MESSAGE_TYPE_KEY).isEqualTo(MsgType.LOGON))).
                bean(new LogonAuthenticator());
        }
    };
    
    context.addRoutes(routes);
    
    LOG.info("Starting Camel context");
    context.start();
    
    if (!logoutLatch.await(5L, TimeUnit.SECONDS)) {
        throw new IllegalStateException("Logout was not received");
    }
            
    context.stop();
    
    LOG.info("Example complete");
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:45,代码来源:AuthenticationExample.java

示例13: testDoesNotGetThroughFilter

import org.apache.camel.impl.DefaultCamelContext; //导入方法依赖的package包/类
@Test
public void testDoesNotGetThroughFilter() throws Exception {
    final String sqsURI = String.format("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient"
            // note we will NOT delete if this message gets filtered out
            + "&deleteIfFiltered=false"
            + "&defaultVisibilityTimeout=1");

    AmazonSQSClientMock clientMock = new AmazonSQSClientMock();
    populateMessages(clientMock);
    SimpleRegistry registry = new SimpleRegistry();

    DefaultCamelContext ctx = new DefaultCamelContext(registry);
    ctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from(sqsURI)
                    // try to filter using a non-existent header... should not go through
                    .filter(simple("${header.login} == true"))
                    .to("mock:result");

        }
    });
    MockEndpoint result = MockEndpoint.resolve(ctx, "mock:result");
    clientMock.setScheduler(ctx.getExecutorServiceManager().newScheduledThreadPool(clientMock, "ClientMock Scheduler", 1));
    registry.put("amazonSQSClient", clientMock);

    result.expectedMessageCount(0);

    ctx.start();

    // we shouldn't get
    assertIsSatisfied(2000, TimeUnit.MILLISECONDS);

    // however, the message should not be deleted, that is, it should be left on the queue
    String response = ctx.createConsumerTemplate().receiveBody(sqsURI, 5000, String.class);

    assertEquals(response, "Message: hello, world!");

    ctx.stop();
    clientMock.shutdown();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:42,代码来源:SqsFilterMessagesWithNoDeleteTest.java

示例14: testGetThroughFilter

import org.apache.camel.impl.DefaultCamelContext; //导入方法依赖的package包/类
@Test
public void testGetThroughFilter() throws Exception {
    final String sqsURI = String.format("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient"
            // note we will NOT delete if this message gets filtered out, but if it goes
            // through filter, it should be deleted!
            + "&deleteIfFiltered=false"
            + "&defaultVisibilityTimeout=1");

    AmazonSQSClientMock clientMock = new AmazonSQSClientMock();
    populateMessages(clientMock);
    SimpleRegistry registry = new SimpleRegistry();

    DefaultCamelContext ctx = new DefaultCamelContext(registry);
    ctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from(sqsURI)
                    .setHeader("login", constant(true))

                    // this filter should allow the message to pass..
                    .filter(simple("${header.login} == true"))
                    .to("mock:result");

        }
    });
    MockEndpoint result = MockEndpoint.resolve(ctx, "mock:result");
    registry.put("amazonSQSClient", clientMock);
    clientMock.setScheduler(ctx.getExecutorServiceManager().newScheduledThreadPool(clientMock, "ClientMock Scheduler", 1));

    result.expectedMessageCount(1);
    ctx.start();

    // the message should get through filter and mock should assert this
    assertIsSatisfied(2000, TimeUnit.MILLISECONDS);

    // however, the message should not be deleted, that is, it should be left on the queue
    String response = ctx.createConsumerTemplate().receiveBody(sqsURI, 5000, String.class);

    assertNull(response);

    ctx.stop();
    clientMock.shutdown();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:44,代码来源:SqsFilterMessagesWithNoDeleteTest.java


注:本文中的org.apache.camel.impl.DefaultCamelContext.stop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。