Home | History | Annotate | Download | only in concurrent
      1 /*
      2  * Copyright (C) 2009 The Guava Authors
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  * http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.google.common.util.concurrent;
     18 
     19 import com.google.common.annotations.Beta;
     20 import com.google.common.collect.ForwardingObject;
     21 
     22 /**
     23  * A {@link Service} that forwards all method calls to another service.
     24  *
     25  * @author Chris Nokleberg
     26  * @since 1.0
     27  */
     28 @Beta
     29 public abstract class ForwardingService extends ForwardingObject
     30     implements Service {
     31 
     32   /** Constructor for use by subclasses. */
     33   protected ForwardingService() {}
     34 
     35   @Override protected abstract Service delegate();
     36 
     37   @Override public ListenableFuture<State> start() {
     38     return delegate().start();
     39   }
     40 
     41   @Override public State state() {
     42     return delegate().state();
     43   }
     44 
     45   @Override public ListenableFuture<State> stop() {
     46     return delegate().stop();
     47   }
     48 
     49   @Override public State startAndWait() {
     50     return delegate().startAndWait();
     51   }
     52 
     53   @Override public State stopAndWait() {
     54     return delegate().stopAndWait();
     55   }
     56 
     57   @Override public boolean isRunning() {
     58     return delegate().isRunning();
     59   }
     60 
     61   /**
     62    * A sensible default implementation of {@link #startAndWait()}, in terms of
     63    * {@link #start}. If you override {@link #start}, you may wish to override
     64    * {@link #startAndWait()} to forward to this implementation.
     65    * @since 9.0
     66    */
     67   protected State standardStartAndWait() {
     68     return Futures.getUnchecked(start());
     69   }
     70 
     71   /**
     72    * A sensible default implementation of {@link #stopAndWait()}, in terms of
     73    * {@link #stop}. If you override {@link #stop}, you may wish to override
     74    * {@link #stopAndWait()} to forward to this implementation.
     75    * @since 9.0
     76    */
     77   protected State standardStopAndWait() {
     78     return Futures.getUnchecked(stop());
     79   }
     80 }
     81