javadoc.src-html.com.google.common.util.concurrent.ForwardingService.html Maven / Gradle / Ivy
The newest version!
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
017 package com.google.common.util.concurrent;
018
019 import com.google.common.annotations.Beta;
020 import com.google.common.collect.ForwardingObject;
021
022 /**
023 * A {@link Service} that forwards all method calls to another service.
024 *
025 * @author Chris Nokleberg
026 * @since 1.0
027 */
028 @Beta
029 public abstract class ForwardingService extends ForwardingObject
030 implements Service {
031
032 /** Constructor for use by subclasses. */
033 protected ForwardingService() {}
034
035 @Override protected abstract Service delegate();
036
037 @Override public ListenableFuture<State> start() {
038 return delegate().start();
039 }
040
041 @Override public State state() {
042 return delegate().state();
043 }
044
045 @Override public ListenableFuture<State> stop() {
046 return delegate().stop();
047 }
048
049 @Override public State startAndWait() {
050 return delegate().startAndWait();
051 }
052
053 @Override public State stopAndWait() {
054 return delegate().stopAndWait();
055 }
056
057 @Override public boolean isRunning() {
058 return delegate().isRunning();
059 }
060
061 /**
062 * A sensible default implementation of {@link #startAndWait()}, in terms of
063 * {@link #start}. If you override {@link #start}, you may wish to override
064 * {@link #startAndWait()} to forward to this implementation.
065 * @since 9.0
066 */
067 protected State standardStartAndWait() {
068 return Futures.getUnchecked(start());
069 }
070
071 /**
072 * A sensible default implementation of {@link #stopAndWait()}, in terms of
073 * {@link #stop}. If you override {@link #stop}, you may wish to override
074 * {@link #stopAndWait()} to forward to this implementation.
075 * @since 9.0
076 */
077 protected State standardStopAndWait() {
078 return Futures.getUnchecked(stop());
079 }
080 }
© 2015 - 2025 Weber Informatics LLC | Privacy Policy