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;
}
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);
}
}
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;
}
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();
}
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);
}
}
}
Aggregations