Search in sources :

Example 21 with Service

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;
}
Also used : IsSingleton(org.apache.camel.IsSingleton) CamelContextAware(org.apache.camel.CamelContextAware) Language(org.apache.camel.spi.Language) Service(org.apache.camel.Service) StatefulService(org.apache.camel.StatefulService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) SuspendableService(org.apache.camel.SuspendableService) RuntimeCamelException(org.apache.camel.RuntimeCamelException) MalformedObjectNameException(javax.management.MalformedObjectNameException) VetoCamelContextStartException(org.apache.camel.VetoCamelContextStartException) IOException(java.io.IOException) LoadPropertiesException(org.apache.camel.util.LoadPropertiesException) NoSuchEndpointException(org.apache.camel.NoSuchEndpointException) ResolveEndpointFailedException(org.apache.camel.ResolveEndpointFailedException) NoFactoryAvailableException(org.apache.camel.NoFactoryAvailableException) FailedToStartRouteException(org.apache.camel.FailedToStartRouteException)

Example 22 with Service

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);
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Service(org.apache.camel.Service) AbstractXmlApplicationContext(org.springframework.context.support.AbstractXmlApplicationContext)

Example 23 with Service

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);
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Service(org.apache.camel.Service) AbstractXmlApplicationContext(org.springframework.context.support.AbstractXmlApplicationContext)

Example 24 with Service

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);
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Service(org.apache.camel.Service) AbstractXmlApplicationContext(org.springframework.context.support.AbstractXmlApplicationContext) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 25 with Service

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);
                }
            }
        }
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) Service(org.apache.camel.Service) ShutdownPrepared(org.apache.camel.spi.ShutdownPrepared) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

Service (org.apache.camel.Service)32 SuspendableService (org.apache.camel.SuspendableService)8 LifecycleStrategy (org.apache.camel.spi.LifecycleStrategy)8 AbstractXmlApplicationContext (org.springframework.context.support.AbstractXmlApplicationContext)8 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)8 StatefulService (org.apache.camel.StatefulService)7 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)6 ArrayList (java.util.ArrayList)5 Processor (org.apache.camel.Processor)5 Route (org.apache.camel.Route)5 IOException (java.io.IOException)4 Endpoint (org.apache.camel.Endpoint)4 MalformedObjectNameException (javax.management.MalformedObjectNameException)3 CamelContextAware (org.apache.camel.CamelContextAware)3 FailedToStartRouteException (org.apache.camel.FailedToStartRouteException)3 NoFactoryAvailableException (org.apache.camel.NoFactoryAvailableException)3 NoSuchEndpointException (org.apache.camel.NoSuchEndpointException)3 ResolveEndpointFailedException (org.apache.camel.ResolveEndpointFailedException)3 RuntimeCamelException (org.apache.camel.RuntimeCamelException)3 VetoCamelContextStartException (org.apache.camel.VetoCamelContextStartException)3