Search in sources :

Example 1 with Suspendable

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

the class ServiceHelper method suspendService.

/**
     * Suspends the given {@code service}.
     * <p/>
     * If {@code service} is both {@link org.apache.camel.Suspendable} and {@link org.apache.camel.SuspendableService} then
     * its {@link org.apache.camel.SuspendableService#suspend()} is called but
     * <b>only</b> if {@code service} is <b>not</b> already
     * {@link #isSuspended(Object) suspended}.
     * <p/>
     * If {@code service} is <b>not</b> a
     * {@link org.apache.camel.Suspendable} and {@link org.apache.camel.SuspendableService} then its
     * {@link org.apache.camel.Service#stop()} is called.
     * <p/>
     * Calling this method has no effect if {@code service} is {@code null}.
     * 
     * @param service the service
     * @return <tt>true</tt> if either the <tt>suspend</tt> method or
     *         {@link #stopService(Object)} was called, <tt>false</tt>
     *         otherwise.
     * @throws Exception is thrown if error occurred
     * @see #stopService(Object)
     */
public static boolean suspendService(Object service) throws Exception {
    if (service instanceof Suspendable && service instanceof SuspendableService) {
        SuspendableService ss = (SuspendableService) service;
        if (!ss.isSuspended()) {
            LOG.trace("Suspending service {}", service);
            ss.suspend();
            return true;
        } else {
            return false;
        }
    } else {
        stopService(service);
        return true;
    }
}
Also used : SuspendableService(org.apache.camel.SuspendableService) Suspendable(org.apache.camel.Suspendable)

Example 2 with Suspendable

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

the class ServiceHelper method resumeService.

/**
     * Resumes the given {@code service}.
     * <p/>
     * If {@code service} is both {@link org.apache.camel.Suspendable} and {@link org.apache.camel.SuspendableService} then
     * its {@link org.apache.camel.SuspendableService#resume()} is called but
     * <b>only</b> if {@code service} is already {@link #isSuspended(Object)
     * suspended}.
     * <p/>
     * If {@code service} is <b>not</b> a
     * {@link org.apache.camel.Suspendable} and {@link org.apache.camel.SuspendableService} then its
     * {@link org.apache.camel.Service#start()} is called.
     * <p/>
     * Calling this method has no effect if {@code service} is {@code null}.
     * 
     * @param service the service
     * @return <tt>true</tt> if either <tt>resume</tt> method or
     *         {@link #startService(Service)} was called, <tt>false</tt>
     *         otherwise.
     * @throws Exception is thrown if error occurred
     * @see #startService(Service)
     */
public static boolean resumeService(Object service) throws Exception {
    if (service instanceof Suspendable && service instanceof SuspendableService) {
        SuspendableService ss = (SuspendableService) service;
        if (ss.isSuspended()) {
            LOG.debug("Resuming service {}", service);
            ss.resume();
            return true;
        } else {
            return false;
        }
    } else {
        startService(service);
        return true;
    }
}
Also used : SuspendableService(org.apache.camel.SuspendableService) Suspendable(org.apache.camel.Suspendable)

Example 3 with Suspendable

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

the class ManagedService method suspend.

public void suspend() throws Exception {
    if (!context.getStatus().isStarted()) {
        throw new IllegalArgumentException("CamelContext is not started");
    }
    if (service instanceof Suspendable && service instanceof SuspendableService) {
        SuspendableService ss = (SuspendableService) service;
        ss.suspend();
    } else {
        throw new UnsupportedOperationException("suspend() is not a supported operation");
    }
}
Also used : SuspendableService(org.apache.camel.SuspendableService) Suspendable(org.apache.camel.Suspendable)

Aggregations

Suspendable (org.apache.camel.Suspendable)3 SuspendableService (org.apache.camel.SuspendableService)3