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; 023import java.util.concurrent.TimeUnit; 024import java.util.concurrent.TimeoutException; 025 026/** 027 * A {@link Service} that forwards all method calls to another service. 028 * 029 * @deprecated Instead of using a {@link ForwardingService}, consider using the 030 * {@link Service.Listener} functionality to hook into the {@link Service} 031 * lifecycle, or if you really do need to provide access to some Service 032 * methods, consider just providing the few that you actually need (e.g. just 033 * {@link #startAndWait()}) and not implementing Service. 034 * 035 * @author Chris Nokleberg 036 * @since 1.0 037 */ 038@Beta 039@Deprecated 040public abstract class ForwardingService extends ForwardingObject 041 implements Service { 042 043 /** Constructor for use by subclasses. */ 044 protected ForwardingService() {} 045 046 @Override protected abstract Service delegate(); 047 048 @Deprecated 049 @Override 050 public ListenableFuture<State> start() { 051 return delegate().start(); 052 } 053 054 @Override public State state() { 055 return delegate().state(); 056 } 057 058 @Deprecated 059 @Override 060 public ListenableFuture<State> stop() { 061 return delegate().stop(); 062 } 063 064 @Deprecated 065 @Override 066 public State startAndWait() { 067 return delegate().startAndWait(); 068 } 069 070 @Deprecated 071 @Override 072 public State stopAndWait() { 073 return delegate().stopAndWait(); 074 } 075 076 @Override public boolean isRunning() { 077 return delegate().isRunning(); 078 } 079 080 /** 081 * @since 13.0 082 */ 083 @Override public void addListener(Listener listener, Executor executor) { 084 delegate().addListener(listener, executor); 085 } 086 087 /** 088 * @since 14.0 089 */ 090 @Override public Throwable failureCause() { 091 return delegate().failureCause(); 092 } 093 094 /** 095 * @since 15.0 096 */ 097 @Override public Service startAsync() { 098 delegate().startAsync(); 099 return this; 100 } 101 102 /** 103 * @since 15.0 104 */ 105 @Override public Service stopAsync() { 106 delegate().stopAsync(); 107 return this; 108 } 109 /** 110 * @since 15.0 111 */ 112 @Override public void awaitRunning() { 113 delegate().awaitRunning(); 114 } 115 116 /** 117 * @since 15.0 118 */ 119 @Override public void awaitRunning(long timeout, TimeUnit unit) throws TimeoutException { 120 delegate().awaitRunning(timeout, unit); 121 } 122 123 /** 124 * @since 15.0 125 */ 126 @Override public void awaitTerminated() { 127 delegate().awaitTerminated(); 128 } 129 130 /** 131 * @since 15.0 132 */ 133 @Override public void awaitTerminated(long timeout, TimeUnit unit) throws TimeoutException { 134 delegate().awaitTerminated(timeout, unit); 135 } 136 137 /** 138 * A sensible default implementation of {@link #startAndWait()}, in terms of 139 * {@link #start}. If you override {@link #start}, you may wish to override 140 * {@link #startAndWait()} to forward to this implementation. 141 * @since 9.0 142 */ 143 protected State standardStartAndWait() { 144 return Futures.getUnchecked(start()); 145 } 146 147 /** 148 * A sensible default implementation of {@link #stopAndWait()}, in terms of 149 * {@link #stop}. If you override {@link #stop}, you may wish to override 150 * {@link #stopAndWait()} to forward to this implementation. 151 * @since 9.0 152 */ 153 protected State standardStopAndWait() { 154 return Futures.getUnchecked(stop()); 155 } 156}