Package com.google.common.util.concurrent.Service

Examples of com.google.common.util.concurrent.Service.State


   * @throws IllegalStateException if any of the Services are not {@link State#NEW new} when the
   *     method is called.
   */
  public ServiceManager startAsync() {
    for (Service service : services) {
      State state = service.state();
      checkState(state == NEW, "Service %s is %s, cannot start it.", service, state);
    }
    for (Service service : services) {
      try {
        service.startAsync();
View Full Code Here


  @Deprecated
  @Override
  public final ListenableFuture<State> stop() {
    if (monitor.enterIf(isStoppable)) {
      try {
        State previous = state();
        switch (previous) {
          case NEW:
            snapshot = new StateSnapshot(TERMINATED);
            terminated(NEW);
            break;
View Full Code Here

  }

  @Override public final void awaitTerminated(long timeout, TimeUnit unit) throws TimeoutException {
    if (monitor.enterWhenUninterruptibly(isStopped, timeout, unit)) {
      try {
        State state = state();
        checkCurrentState(TERMINATED);
      } finally {
        monitor.leave();
      }
    } else {
View Full Code Here

  }

  /** Checks that the current state is equal to the expected state. */
  @GuardedBy("monitor")
  private void checkCurrentState(State expected) {
    State actual = state();
    if (actual != expected) {
      if (actual == FAILED) {
        // Handle this specially so that we can include the failureCause, if there is one.
        throw new IllegalStateException("Expected the service to be " + expected
            + ", but the service has FAILED", failureCause());
View Full Code Here

  protected final void notifyStopped() {
    monitor.enter();
    try {
      // We check the internal state of the snapshot instead of state() directly so we don't allow
      // notifyStopped() to be called while STARTING, even if stop() has already been called.
      State previous = snapshot.state;
      if (previous != STOPPING && previous != RUNNING) {
        IllegalStateException failure = new IllegalStateException(
            "Cannot notifyStopped() when the service is " + previous);
        notifyFailed(failure);
        throw failure;
View Full Code Here

  protected final void notifyFailed(Throwable cause) {
    checkNotNull(cause);

    monitor.enter();
    try {
      State previous = state();
      switch (previous) {
        case NEW:
        case TERMINATED:
          throw new IllegalStateException("Failed while in state:" + previous, cause);
        case RUNNING:
View Full Code Here

  public final void addListener(Listener listener, Executor executor) {
    checkNotNull(listener, "listener");
    checkNotNull(executor, "executor");
    monitor.enter();
    try {
      State currentState = state();
      if (currentState != TERMINATED && currentState != FAILED) {
        listeners.add(new ListenerExecutorPair(listener, executor));
      }
    } finally {
      monitor.leave();
View Full Code Here

        IllegalStateException failure = new IllegalStateException(
            "Cannot notifyStopped() when the service is " + snapshot.state);
        notifyFailed(failure);
        throw failure;
      }
      State previous = snapshot.state;
      snapshot = new StateSnapshot(State.TERMINATED);
      terminated(previous);
    } finally {
      lock.unlock();
      executeListeners();
View Full Code Here

        case TERMINATED:
          throw new IllegalStateException("Failed while in state:" + snapshot.state, cause);
        case RUNNING:
        case STARTING:
        case STOPPING:
          State previous = snapshot.state;
          snapshot = new StateSnapshot(State.FAILED, false, cause);
          failed(previous, cause);
          break;
        case FAILED:
          // Do nothing
View Full Code Here

  private void awaitStopped(long time, TimeUnit unit) throws InterruptedException {
    assertTrue(terminalLatch.await(time, unit));
  }

  private void assertTerminated() {
    State state = service.state();
    if (state != State.TERMINATED) {
      if (state == State.FAILED) {
        throw new AssertionError(service.failureCause());
      }
      fail("Expected service to be terminated but was: " + state);
View Full Code Here

TOP

Related Classes of com.google.common.util.concurrent.Service.State

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.