use of org.apache.camel.Consumer in project camel by apache.
the class SedaEndpointTest method testSedaEndpoint.
public void testSedaEndpoint() throws Exception {
SedaEndpoint seda = new SedaEndpoint("seda://foo", context.getComponent("seda"), queue);
assertNotNull(seda);
assertEquals(1000, seda.getSize());
assertSame(queue, seda.getQueue());
assertEquals(1, seda.getConcurrentConsumers());
Producer prod = seda.createProducer();
seda.onStarted((SedaProducer) prod);
assertEquals(1, seda.getProducers().size());
Consumer cons = seda.createConsumer(new Processor() {
public void process(Exchange exchange) throws Exception {
// do nothing
}
});
seda.onStarted((SedaConsumer) cons);
assertEquals(1, seda.getConsumers().size());
assertEquals(0, seda.getExchanges().size());
}
use of org.apache.camel.Consumer in project camel by apache.
the class SedaEndpointTest method testSedaEndpointUnboundedQueue.
public void testSedaEndpointUnboundedQueue() throws Exception {
BlockingQueue<Exchange> unbounded = new LinkedBlockingQueue<Exchange>();
SedaEndpoint seda = new SedaEndpoint("seda://foo", context.getComponent("seda"), unbounded);
assertNotNull(seda);
assertEquals(Integer.MAX_VALUE, seda.getSize());
assertSame(unbounded, seda.getQueue());
assertEquals(1, seda.getConcurrentConsumers());
Producer prod = seda.createProducer();
seda.onStarted((SedaProducer) prod);
assertEquals(1, seda.getProducers().size());
Consumer cons = seda.createConsumer(new Processor() {
public void process(Exchange exchange) throws Exception {
// do nothing
}
});
seda.onStarted((SedaConsumer) cons);
assertEquals(1, seda.getConsumers().size());
assertEquals(0, seda.getExchanges().size());
}
use of org.apache.camel.Consumer in project camel by apache.
the class RetryRouteScopedUntilRecipientListIssueTest method createCamelContext.
@Override
protected CamelContext createCamelContext() throws Exception {
CamelContext context = super.createCamelContext();
context.addEndpoint("fail", new DefaultEndpoint() {
public Producer createProducer() throws Exception {
return new DefaultProducer(this) {
public void process(Exchange exchange) throws Exception {
exchange.setException(new IllegalArgumentException("Damn"));
}
};
}
public Consumer createConsumer(Processor processor) throws Exception {
return null;
}
@Override
protected String createEndpointUri() {
return "fail";
}
public boolean isSingleton() {
return true;
}
});
context.addEndpoint("not-fail", new DefaultEndpoint() {
public Producer createProducer() throws Exception {
return new DefaultProducer(this) {
public void process(Exchange exchange) throws Exception {
// noop
}
};
}
public Consumer createConsumer(Processor processor) throws Exception {
return null;
}
@Override
protected String createEndpointUri() {
return "not-fail";
}
public boolean isSingleton() {
return true;
}
});
return context;
}
use of org.apache.camel.Consumer in project camel by apache.
the class DefaultPollingEndpoint method createConsumer.
public Consumer createConsumer(Processor processor) throws Exception {
Consumer result = new DefaultScheduledPollConsumer(this, processor);
configureConsumer(result);
return result;
}
use of org.apache.camel.Consumer in project camel by apache.
the class DefaultCamelContext method doStop.
protected synchronized void doStop() throws Exception {
stopWatch.restart();
log.info("Apache Camel " + getVersion() + " (CamelContext: " + getName() + ") is shutting down");
EventHelper.notifyCamelContextStopping(this);
// stop route inputs in the same order as they was started so we stop the very first inputs first
try {
// force shutting down routes as they may otherwise cause shutdown to hang
shutdownStrategy.shutdownForced(this, getRouteStartupOrder());
} catch (Throwable e) {
log.warn("Error occurred while shutting down routes. This exception will be ignored.", e);
}
// shutdown await manager to trigger interrupt of blocked threads to attempt to free these threads graceful
shutdownServices(asyncProcessorAwaitManager);
shutdownServices(getRouteStartupOrder().stream().sorted(Comparator.comparing(RouteStartupOrder::getStartupOrder).reversed()).map(DefaultRouteStartupOrder.class::cast).map(DefaultRouteStartupOrder::getRouteService).collect(Collectors.toList()), false);
// do not clear route services or startup listeners as we can start Camel again and get the route back as before
getRouteStartupOrder().clear();
// but clear any suspend routes
suspendedRouteServices.clear();
// which we need to stop after the routes, as a POJO consumer is essentially a route also
for (Service service : servicesToStop) {
if (service instanceof Consumer) {
shutdownServices(service);
}
}
// shutdown default error handler thread pool
if (errorHandlerExecutorService != null) {
// force shutting down the thread pool
getExecutorServiceManager().shutdownNow(errorHandlerExecutorService);
errorHandlerExecutorService = null;
}
// shutdown debugger
ServiceHelper.stopAndShutdownService(getDebugger());
shutdownServices(endpoints.values());
endpoints.clear();
shutdownServices(components.values());
components.clear();
shutdownServices(languages.values());
languages.clear();
try {
for (LifecycleStrategy strategy : lifecycleStrategies) {
strategy.onContextStop(this);
}
} catch (Throwable e) {
log.warn("Error occurred while stopping lifecycle strategies. This exception will be ignored.", e);
}
// shutdown services as late as possible
shutdownServices(servicesToStop);
servicesToStop.clear();
// must notify that we are stopped before stopping the management strategy
EventHelper.notifyCamelContextStopped(this);
// stop the notifier service
for (EventNotifier notifier : getManagementStrategy().getEventNotifiers()) {
shutdownServices(notifier);
}
// shutdown executor service and management as the last one
shutdownServices(executorServiceManager);
shutdownServices(managementStrategy);
shutdownServices(managementMBeanAssembler);
shutdownServices(lifecycleStrategies);
// do not clear lifecycleStrategies as we can start Camel again and get the route back as before
// stop the lazy created so they can be re-created on restart
forceStopLazyInitialization();
// stop to clear introspection cache
IntrospectionSupport.stop();
stopWatch.stop();
if (log.isInfoEnabled()) {
log.info("Apache Camel " + getVersion() + " (CamelContext: " + getName() + ") uptime {}", getUptime());
log.info("Apache Camel " + getVersion() + " (CamelContext: " + getName() + ") is shutdown in " + TimeUtils.printDuration(stopWatch.taken()));
}
// and clear start date
startDate = null;
// [TODO] Remove in 3.0
Container.Instance.unmanage(this);
}
Aggregations