use of org.apache.camel.Service in project camel by apache.
the class DefaultCamelContext method resolveLanguage.
// Helper methods
// -----------------------------------------------------------------------
public Language resolveLanguage(String language) {
Language answer;
synchronized (languages) {
answer = languages.get(language);
// check if the language is singleton, if so return the shared instance
if (answer instanceof IsSingleton) {
boolean singleton = ((IsSingleton) answer).isSingleton();
if (singleton) {
return answer;
}
}
// language not known or not singleton, then use resolver
answer = getLanguageResolver().resolveLanguage(language, this);
// inject CamelContext if aware
if (answer != null) {
if (answer instanceof CamelContextAware) {
((CamelContextAware) answer).setCamelContext(this);
}
if (answer instanceof Service) {
try {
startService((Service) answer);
} catch (Exception e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
}
}
languages.put(language, answer);
}
}
return answer;
}
use of org.apache.camel.Service in project camel by apache.
the class SpringTestHelper method createSpringCamelContext.
public static CamelContext createSpringCamelContext(ContextTestSupport test, String classpathUri) throws Exception {
test.setUseRouteBuilder(false);
final AbstractXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(classpathUri);
test.setCamelContextService(new Service() {
public void start() throws Exception {
applicationContext.start();
}
public void stop() throws Exception {
applicationContext.stop();
}
});
return SpringCamelContext.springCamelContext(applicationContext);
}
use of org.apache.camel.Service in project camel by apache.
the class SpringMarshalOmitFieldsTest method createCamelContext.
protected CamelContext createCamelContext() throws Exception {
setUseRouteBuilder(false);
final AbstractXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/dataformat/xstream/SpringMarshalOmitFieldsTest.xml");
setCamelContextService(new Service() {
public void start() throws Exception {
applicationContext.start();
}
public void stop() throws Exception {
applicationContext.stop();
}
});
return SpringCamelContext.springCamelContext(applicationContext);
}
use of org.apache.camel.Service in project camel by apache.
the class JibxDataFormatSpringDslTest method createCamelContext.
protected CamelContext createCamelContext() throws Exception {
setUseRouteBuilder(false);
final AbstractXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/dataformat/jibx/SpringJibxConfigurationTest.xml");
setCamelContextService(new Service() {
public void start() throws Exception {
applicationContext.start();
}
public void stop() throws Exception {
applicationContext.stop();
}
});
return SpringCamelContext.springCamelContext(applicationContext);
}
use of org.apache.camel.Service in project camel by apache.
the class DefaultShutdownStrategy method prepareShutdown.
/**
* Prepares the services for shutdown, by invoking the {@link ShutdownPrepared#prepareShutdown(boolean, boolean)} method
* on the service if it implement this interface.
*
* @param service the service
* @param forced whether to force shutdown
* @param includeChildren whether to prepare the child of the service as well
*/
private static void prepareShutdown(Service service, boolean suspendOnly, boolean forced, boolean includeChildren, boolean suppressLogging) {
Set<Service> list;
if (includeChildren) {
// include error handlers as we want to prepare them for shutdown as well
list = ServiceHelper.getChildServices(service, true);
} else {
list = new LinkedHashSet<Service>(1);
list.add(service);
}
for (Service child : list) {
if (child instanceof ShutdownPrepared) {
try {
LOG.trace("Preparing {} shutdown on {}", forced ? "forced" : "", child);
((ShutdownPrepared) child).prepareShutdown(suspendOnly, forced);
} catch (Exception e) {
if (suppressLogging) {
LOG.trace("Error during prepare shutdown on " + child + ". This exception will be ignored.", e);
} else {
LOG.warn("Error during prepare shutdown on " + child + ". This exception will be ignored.", e);
}
}
}
}
}
Aggregations