use of org.apache.camel.Service in project camel by apache.
the class DefaultCamelContext method doAddService.
private void doAddService(Object object, boolean stopOnShutdown, boolean forceStart) throws Exception {
// inject CamelContext
if (object instanceof CamelContextAware) {
CamelContextAware aware = (CamelContextAware) object;
aware.setCamelContext(this);
}
if (object instanceof Service) {
Service service = (Service) object;
for (LifecycleStrategy strategy : lifecycleStrategies) {
if (service instanceof Endpoint) {
// use specialized endpoint add
strategy.onEndpointAdd((Endpoint) service);
} else {
strategy.onServiceAdd(this, service, null);
}
}
if (!forceStart) {
// now start the service (and defer starting if CamelContext is starting up itself)
deferStartService(object, stopOnShutdown);
} else {
// only add to services to close if its a singleton
// otherwise we could for example end up with a lot of prototype scope endpoints
// assume singleton by default
boolean singleton = true;
if (object instanceof IsSingleton) {
singleton = ((IsSingleton) service).isSingleton();
}
// do not add endpoints as they have their own list
if (singleton && !(service instanceof Endpoint)) {
// only add to list of services to stop if its not already there
if (stopOnShutdown && !hasService(service)) {
servicesToStop.add(service);
}
}
ServiceHelper.startService(service);
}
}
}
use of org.apache.camel.Service in project camel by apache.
the class CamelJaxbNoNamespaceSchemaLocationSpringTest method createCamelContext.
protected CamelContext createCamelContext() throws Exception {
setUseRouteBuilder(false);
final AbstractXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/jaxb/CamelJaxbNoNamespaceSchemaLocationTest.xml");
setCamelContextService(new Service() {
public void start() throws Exception {
applicationContext.start();
}
public void stop() throws Exception {
applicationContext.stop();
}
});
return SpringCamelContext.springCamelContext(applicationContext);
}
Aggregations