Example usage for com.google.common.util.concurrent Service state

List of usage examples for com.google.common.util.concurrent Service state

Introduction

In this page you can find the example usage for com.google.common.util.concurrent Service state.

Prototype

State state();

Source Link

Document

Returns the lifecycle state of the service.

Usage

From source file:org.midonet.midolman.services.MidolmanService.java

@Override
protected void doStop() {

    try {/*from w  w  w. j  a v a  2s  .  c  o  m*/
        if (jmxReporter != null) {
            jmxReporter.stop();
        }
    } catch (Exception e) {
        log.error("Could not stop jmx reporter", e);
        notifyFailed(e);
    }

    List<Service> services = services();
    Collections.reverse(services);
    log.info("Stopping services");
    for (Service service : services) {
        boolean running = service.state() == State.RUNNING;
        try {
            if (running) {
                log.info("Stopping service: {}", service);
                service.stopAsync().awaitTerminated();
            }
        } catch (Exception e) {
            log.error("Exception while stopping the service {}", service, e);
            notifyFailed(e);
            // Keep stopping services.
        }
    }

    log.info("Stopping executors");
    try {
        virtualTopology.vtExecutor().shutdown();
        virtualTopology.ioExecutor().shutdown();
        if (!virtualTopology.vtExecutor().awaitTermination(5, TimeUnit.SECONDS)) {
            log.warn("Stopping the VT executor timed out");
            virtualTopology.vtExecutor().shutdownNow();
        }
        if (!virtualTopology.ioExecutor().awaitTermination(5, TimeUnit.SECONDS)) {
            log.warn("Stopping the I/O executor timed out");
            virtualTopology.ioExecutor().shutdownNow();
        }
    } catch (InterruptedException e) {
        log.error("Exception while stopping the executors", e);
    }

    virtualTopology.stopRuleLogEventChannel();

    if (state() != State.FAILED)
        notifyStopped();
}

From source file:dk.dma.commons.app.AbstractDmaApplication.java

void awaitServiceStopped(Service s) throws InterruptedException {
    State st = s.state();
    CountDownLatch cdl = null;//ww w . ja v a 2s.  co  m
    while (st == State.RUNNING || st == State.NEW) {
        if (cdl != null) {
            cdl.await();
        }
        final CountDownLatch c = cdl = new CountDownLatch(1);
        s.addListener(new Service.Listener() {
            public void terminated(State from) {
                c.countDown();
            }

            @Override
            public void stopping(State from) {
                c.countDown();
            }

            @Override
            public void starting() {
                c.countDown();
            }

            @Override
            public void running() {
                c.countDown();
            }

            @Override
            public void failed(State from, Throwable failure) {
                c.countDown();
            }
        }, MoreExecutors.sameThreadExecutor());
    }
}

From source file:io.pravega.service.server.containers.StreamSegmentContainer.java

private Throwable getFailureCause(Service... services) {
    Throwable result = null;//  w ww  .  ja va2s.  c  o  m
    for (Service s : services) {
        if (s.state() == State.FAILED) {
            Throwable realEx = ExceptionHelpers.getRealException(s.failureCause());
            if (result == null) {
                result = realEx;
            } else {
                result.addSuppressed(realEx);
            }
        }
    }

    return result;
}

From source file:co.cask.cdap.internal.app.runtime.ProgramRunners.java

/**
 * Impersonates as the given user to start a guava service
 *
 * @param user user to impersonate/*from   w ww. j  a v  a 2  s . co m*/
 * @param service guava service start start
 */
public static void startAsUser(String user, final Service service) throws IOException, InterruptedException {
    runAsUser(user, new Callable<ListenableFuture<Service.State>>() {
        @Override
        public ListenableFuture<Service.State> call() throws Exception {
            return service.start();
        }
    });
}

From source file:io.pravega.segmentstore.server.IllegalContainerStateException.java

public IllegalContainerStateException(int containerId, Service.State expectedState,
        Service.State desiredState) {
    super(String.format("Container %d is in an invalid state for this operation. Expected: %s; Actual: %s.",
            containerId, desiredState, expectedState));
}

From source file:com.continuuity.weave.common.Services.java

/**
 * Starts a list of {@link Service} one by one. Starting of next Service is triggered from the callback listener
 * thread of the previous Service.//from  w w  w .ja  v  a2s.  c  o  m
 *
 * @param firstService First service to start.
 * @param moreServices The rest services to start.
 * @return A {@link ListenableFuture} that will be completed when all services are started, with the
 *         result carries the completed {@link ListenableFuture} of each corresponding service in the
 *         same order as they are passed to this method.
 */
public static ListenableFuture<List<ListenableFuture<Service.State>>> chainStart(Service firstService,
        Service... moreServices) {
    return doChain(true, firstService, moreServices);
}

From source file:org.invenzzia.helium.behaviors.ILifecycle.java

public Service.State startAndWait();

From source file:org.invenzzia.helium.behaviors.ILifecycle.java

public Service.State stopAndWait();

From source file:co.cask.cdap.app.runtime.workflow.WorkflowStatus.java

public WorkflowStatus(Service.State state, WorkflowActionSpecification currentAction, int currentStep) {
    this.state = state;
    this.currentAction = currentAction;
    this.currentStep = currentStep;
}

From source file:org.invenzzia.helium.behaviors.ILifecycle.java

public Service.State state();