com.google.common.util.concurrent
Class AbstractIdleService
java.lang.Object
com.google.common.util.concurrent.AbstractIdleService
- All Implemented Interfaces:
- Service
@Beta
public abstract class AbstractIdleService
- extends java.lang.Object
- implements Service
Base class for services that do not need a thread while "running"
but may need one during startup and shutdown. Subclasses can
implement startUp() and shutDown() methods, each
which run in a executor which by default uses a separate thread
for each method.
- Since:
- 1
- Author:
- Chris Nokleberg
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
AbstractIdleService
public AbstractIdleService()
startUp
protected abstract void startUp()
throws java.lang.Exception
- Start the service.
- Throws:
java.lang.Exception
shutDown
protected abstract void shutDown()
throws java.lang.Exception
- Stop the service.
- Throws:
java.lang.Exception
executor
protected java.util.concurrent.Executor executor(Service.State state)
- Returns the
Executor that will be used to run this service.
Subclasses may override this method to use a custom Executor, which
may configure its worker thread with a specific name, thread group or
priority. The returned executor's execute() method is called when this service is started and stopped,
and should return promptly.
- Parameters:
state - Service.State.STARTING or
Service.State.STOPPING, used by the
default implementation for naming the thread
toString
public java.lang.String toString()
- Overrides:
toString in class java.lang.Object
start
public final java.util.concurrent.Future<Service.State> start()
- Specified by:
start in interface Service
startAndWait
public final Service.State startAndWait()
- Specified by:
startAndWait in interface Service
isRunning
public final boolean isRunning()
- Specified by:
isRunning in interface Service
state
public final Service.State state()
- Specified by:
state in interface Service
stop
public final java.util.concurrent.Future<Service.State> stop()
- Specified by:
stop in interface Service
stopAndWait
public final Service.State stopAndWait()
- Specified by:
stopAndWait in interface Service
Copyright © 2010 Google. All Rights Reserved.