001/*
002 * Copyright (C) 2009 The Guava Authors
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package com.google.common.util.concurrent;
018
019import com.google.common.annotations.Beta;
020import com.google.common.collect.ForwardingObject;
021
022import java.util.concurrent.Executor;
023
024/**
025 * A {@link Service} that forwards all method calls to another service.
026 *
027 * @author Chris Nokleberg
028 * @since 1.0
029 */
030@Beta
031public abstract class ForwardingService extends ForwardingObject
032    implements Service {
033
034  /** Constructor for use by subclasses. */
035  protected ForwardingService() {}
036
037  @Override protected abstract Service delegate();
038
039  @Override public ListenableFuture<State> start() {
040    return delegate().start();
041  }
042
043  @Override public State state() {
044    return delegate().state();
045  }
046
047  @Override public ListenableFuture<State> stop() {
048    return delegate().stop();
049  }
050
051  @Override public State startAndWait() {
052    return delegate().startAndWait();
053  }
054
055  @Override public State stopAndWait() {
056    return delegate().stopAndWait();
057  }
058
059  @Override public boolean isRunning() {
060    return delegate().isRunning();
061  }
062  
063  /**
064   * @since 13.0
065   */
066  @Override public void addListener(Listener listener, Executor executor) {
067    delegate().addListener(listener, executor);
068  }
069
070  /**
071   * @since 14.0
072   */
073  @Override public Throwable failureCause() {
074    return delegate().failureCause();
075  }
076
077  /**
078   * A sensible default implementation of {@link #startAndWait()}, in terms of
079   * {@link #start}. If you override {@link #start}, you may wish to override
080   * {@link #startAndWait()} to forward to this implementation.
081   * @since 9.0
082   */
083  protected State standardStartAndWait() {
084    return Futures.getUnchecked(start());
085  }
086
087  /**
088   * A sensible default implementation of {@link #stopAndWait()}, in terms of
089   * {@link #stop}. If you override {@link #stop}, you may wish to override
090   * {@link #stopAndWait()} to forward to this implementation.
091   * @since 9.0
092   */
093  protected State standardStopAndWait() {
094    return Futures.getUnchecked(stop());
095  }
096}