Search in sources :

Example 26 with Service

use of org.apache.camel.Service in project camel by apache.

the class RouteService method gatherChildServices.

/**
     * Gather all child services
     */
private Set<Service> gatherChildServices(Route route, boolean includeErrorHandler) {
    // gather list of services to stop as we need to start child services as well
    List<Service> services = new ArrayList<Service>();
    services.addAll(route.getServices());
    // also get route scoped services
    doGetRouteScopedServices(services, route);
    Set<Service> list = new LinkedHashSet<Service>();
    for (Service service : services) {
        list.addAll(ServiceHelper.getChildServices(service));
    }
    if (includeErrorHandler) {
        // also get route scoped error handler (which must be done last)
        doGetRouteScopedErrorHandler(list, route);
    }
    Set<Service> answer = new LinkedHashSet<Service>();
    answer.addAll(list);
    return answer;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) Service(org.apache.camel.Service)

Example 27 with Service

use of org.apache.camel.Service in project camel by apache.

the class ServiceHelper method stopService.

/**
     * Stops the given {@code value}, rethrowing the first exception caught.
     * <p/>
     * Calling this method has no effect if {@code value} is {@code null}.
     * 
     * @see Service#stop()
     * @see #stopServices(Collection)
     */
public static void stopService(Object value) throws Exception {
    if (isStopped(value)) {
        // only stop service if not already stopped
        LOG.trace("Service already stopped: {}", value);
        return;
    }
    if (value instanceof Service) {
        Service service = (Service) value;
        LOG.trace("Stopping service {}", value);
        service.stop();
    } else if (value instanceof Collection) {
        stopServices((Collection<?>) value);
    }
}
Also used : ShutdownableService(org.apache.camel.ShutdownableService) SuspendableService(org.apache.camel.SuspendableService) Service(org.apache.camel.Service) StatefulService(org.apache.camel.StatefulService) Collection(java.util.Collection)

Example 28 with Service

use of org.apache.camel.Service in project camel by apache.

the class PolicyDefinition method createProcessor.

@Override
public Processor createProcessor(RouteContext routeContext) throws Exception {
    Policy policy = resolvePolicy(routeContext);
    ObjectHelper.notNull(policy, "policy", this);
    // before wrap
    policy.beforeWrap(routeContext, this);
    // create processor after the before wrap
    Processor childProcessor = this.createChildProcessor(routeContext, true);
    // wrap
    Processor target = policy.wrap(routeContext, childProcessor);
    if (!(target instanceof Service)) {
        // wrap the target so it becomes a service and we can manage its lifecycle
        target = new WrapProcessor(target, childProcessor);
    }
    return target;
}
Also used : TransactedPolicy(org.apache.camel.spi.TransactedPolicy) Policy(org.apache.camel.spi.Policy) Processor(org.apache.camel.Processor) WrapProcessor(org.apache.camel.processor.WrapProcessor) WrapProcessor(org.apache.camel.processor.WrapProcessor) Service(org.apache.camel.Service)

Example 29 with Service

use of org.apache.camel.Service in project camel by apache.

the class CMTest method testHostUnavailableException.

@Test(expected = HostUnavailableException.class)
public void testHostUnavailableException() throws Throwable {
    // cm-sms://sgw01.cm.nl/gateway.ashx?defaultFrom=MyBusiness&defaultMaxNumberOfParts=8&productToken=ea723fd7-da81-4826-89bc-fa7144e71c40&testConnectionOnStartup=true
    String schemedUri = "cm-sms://dummy.sgw01.cm.nl/gateway.ashx?defaultFrom=MyBusiness&defaultMaxNumberOfParts=8&productToken=ea723fd7-da81-4826-89bc-fa7144e71c40&testConnectionOnStartup=true";
    Service service = camelContext.getEndpoint(schemedUri).createProducer();
    service.start();
}
Also used : Service(org.apache.camel.Service) Test(org.junit.Test)

Example 30 with Service

use of org.apache.camel.Service in project camel by apache.

the class DefaultCamelContext method deferStartService.

public void deferStartService(Object object, boolean stopOnShutdown) throws Exception {
    if (object instanceof Service) {
        Service service = (Service) object;
        // 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);
            }
        }
        // are we already started?
        if (isStarted()) {
            ServiceHelper.startService(service);
        } else {
            deferStartupListener.addService(service);
        }
    }
}
Also used : IsSingleton(org.apache.camel.IsSingleton) Endpoint(org.apache.camel.Endpoint) Service(org.apache.camel.Service) StatefulService(org.apache.camel.StatefulService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) SuspendableService(org.apache.camel.SuspendableService)

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