@Override public void contextCreated(CamelContext camelContext) { camelContext.addLifecycleStrategy(new LifecycleStrategySupport() { @Override public void onContextStop(CamelContext context) { names.remove(context.getName()); } }); names.add(camelContext.getName()); }
public DocumenterPlugin() { customizer = camelContext -> camelContext.addLifecycleStrategy(new LifecycleStrategySupport() { @Override public void onContextStart(CamelContext context) throws VetoCamelContextStartException { routeDocumentations = iterableList(context.getRouteDefinitions()).map(RouteDocumentation::fromRoute); } }); exchangesListener = log::addExchange; Collector.addListener(exchangesListener); mapper = new ObjectMapper(); SimpleModule fjModule = new SimpleModule(); fjModule.addSerializer(List.class, new JsonSerializer<List>() { @Override public void serialize( List value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException { serializers.defaultSerializeValue(value.toJavaList(), gen); } }); mapper.registerModule(fjModule); }
/** * @throws Exception */ public void testUserSpecifiedCamelContext() throws Exception { final AtomicInteger cnt = new AtomicInteger(); // Create a CamelContext with a probe that'll help us know if it has been used. CamelContext context = new DefaultCamelContext(); context.setTracing(true); context.addLifecycleStrategy(new LifecycleStrategySupport() { @Override public void onEndpointAdd(Endpoint endpoint) { cnt.incrementAndGet(); } }); streamer.setSingleTupleExtractor(singleTupleExtractor()); streamer.setCamelContext(context); // Subscribe to cache PUT events. CountDownLatch latch = subscribeToPutEvents(50); // Action time. streamer.start(); // Send messages. sendMessages(0, 50, false); // Assertions. assertTrue(latch.await(10, TimeUnit.SECONDS)); assertCacheEntriesLoaded(50); assertTrue(cnt.get() > 0); }