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 * @deprecated Instead of using a {@link ForwardingService}, consider using the 
028 * {@link Service.Listener} functionality to hook into the {@link Service} 
029 * lifecycle, or if you really do need to provide access to some Service 
030 * methods, consider just providing the few that you actually need (e.g. just 
031 * {@link #startAndWait()}) and not implementing Service.
032 *
033 * @author Chris Nokleberg
034 * @since 1.0
035 */
036@Beta
037@Deprecated
038public abstract class ForwardingService extends ForwardingObject
039    implements Service {
040
041  /** Constructor for use by subclasses. */
042  protected ForwardingService() {}
043
044  @Override protected abstract Service delegate();
045
046  @Override public ListenableFuture<State> start() {
047    return delegate().start();
048  }
049
050  @Override public State state() {
051    return delegate().state();
052  }
053
054  @Override public ListenableFuture<State> stop() {
055    return delegate().stop();
056  }
057
058  @Override public State startAndWait() {
059    return delegate().startAndWait();
060  }
061
062  @Override public State stopAndWait() {
063    return delegate().stopAndWait();
064  }
065
066  @Override public boolean isRunning() {
067    return delegate().isRunning();
068  }
069  
070  /**
071   * @since 13.0
072   */
073  @Override public void addListener(Listener listener, Executor executor) {
074    delegate().addListener(listener, executor);
075  }
076
077  /**
078   * @since 14.0
079   */
080  @Override public Throwable failureCause() {
081    return delegate().failureCause();
082  }
083
084  /**
085   * A sensible default implementation of {@link #startAndWait()}, in terms of
086   * {@link #start}. If you override {@link #start}, you may wish to override
087   * {@link #startAndWait()} to forward to this implementation.
088   * @since 9.0
089   */
090  protected State standardStartAndWait() {
091    return Futures.getUnchecked(start());
092  }
093
094  /**
095   * A sensible default implementation of {@link #stopAndWait()}, in terms of
096   * {@link #stop}. If you override {@link #stop}, you may wish to override
097   * {@link #stopAndWait()} to forward to this implementation.
098   * @since 9.0
099   */
100  protected State standardStopAndWait() {
101    return Futures.getUnchecked(stop());
102  }
103}