Package edu.wpi.grip.core.util.service
Class AutoRestartingService<S extends com.google.common.util.concurrent.Service>
- java.lang.Object
-
- edu.wpi.grip.core.util.service.AutoRestartingService<S>
-
- All Implemented Interfaces:
com.google.common.util.concurrent.Service,RestartableService
public class AutoRestartingService<S extends com.google.common.util.concurrent.Service> extends java.lang.Object implements RestartableService
A Restartable Service that will automatically restart itself if- See Also:
- Original version
-
-
Field Summary
-
Fields inherited from interface edu.wpi.grip.core.util.service.RestartableService
VALID_START_STATES
-
-
Constructor Summary
Constructors Constructor Description AutoRestartingService(java.util.function.Supplier<S> factory)This will create an AutoRestartingService that will always restart whenever the existing service enters theService.State.FAILEDstate.AutoRestartingService(java.util.function.Supplier<S> factory, ServiceRestartPolicy policy)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(com.google.common.util.concurrent.Service.Listener listener, java.util.concurrent.Executor executor)This is only guaranteed to add the listeners to future services.voidawaitRunning()voidawaitRunning(long timeout, java.util.concurrent.TimeUnit unit)voidawaitTerminated()voidawaitTerminated(long timeout, java.util.concurrent.TimeUnit unit)java.lang.ThrowablefailureCause()protected SgetDelegate()Used for testing only.booleanisRunning()AutoRestartingServicestartAsync()If the service state isService.State.NEW,Service.State.FAILED,Service.State.TERMINATEDthis initiates service startup and returns immediately.com.google.common.util.concurrent.Service.Statestate()voidstopAndAwait()voidstopAndAwait(long timeout, java.util.concurrent.TimeUnit unit)AutoRestartingServicestopAsync()Stops the service.
-
-
-
Constructor Detail
-
AutoRestartingService
public AutoRestartingService(java.util.function.Supplier<S> factory, ServiceRestartPolicy policy)
- Parameters:
factory- This should always supply a new instance of the service that can be restarted.policy- A policy that allows for custom logic to determine if a service that has entered theService.State.FAILEDstate should restart.
-
AutoRestartingService
public AutoRestartingService(java.util.function.Supplier<S> factory)
This will create an AutoRestartingService that will always restart whenever the existing service enters theService.State.FAILEDstate.- Parameters:
factory- This should always supply a new instance of the service that can be restarted.
-
-
Method Detail
-
getDelegate
protected S getDelegate()
Used for testing only.- Returns:
- delegate
-
startAsync
public AutoRestartingService startAsync()
Description copied from interface:RestartableServiceIf the service state isService.State.NEW,Service.State.FAILED,Service.State.TERMINATEDthis initiates service startup and returns immediately.- Specified by:
startAsyncin interfaceRestartableService- Specified by:
startAsyncin interfacecom.google.common.util.concurrent.Service- Returns:
- this
-
isRunning
public boolean isRunning()
- Specified by:
isRunningin interfacecom.google.common.util.concurrent.Service
-
state
public com.google.common.util.concurrent.Service.State state()
- Specified by:
statein interfacecom.google.common.util.concurrent.Service
-
stopAsync
public AutoRestartingService stopAsync()
Description copied from interface:RestartableServiceStops the service.- Specified by:
stopAsyncin interfaceRestartableService- Specified by:
stopAsyncin interfacecom.google.common.util.concurrent.Service- Returns:
- this
-
stopAndAwait
public void stopAndAwait(long timeout, java.util.concurrent.TimeUnit unit) throws java.util.concurrent.TimeoutException- Specified by:
stopAndAwaitin interfaceRestartableService- Throws:
java.util.concurrent.TimeoutException
-
stopAndAwait
public void stopAndAwait()
- Specified by:
stopAndAwaitin interfaceRestartableService
-
awaitRunning
public void awaitRunning()
- Specified by:
awaitRunningin interfacecom.google.common.util.concurrent.Service
-
awaitRunning
public void awaitRunning(long timeout, java.util.concurrent.TimeUnit unit) throws java.util.concurrent.TimeoutException- Specified by:
awaitRunningin interfacecom.google.common.util.concurrent.Service- Throws:
java.util.concurrent.TimeoutException
-
awaitTerminated
public void awaitTerminated()
- Specified by:
awaitTerminatedin interfacecom.google.common.util.concurrent.Service
-
awaitTerminated
public void awaitTerminated(long timeout, java.util.concurrent.TimeUnit unit) throws java.util.concurrent.TimeoutException- Specified by:
awaitTerminatedin interfacecom.google.common.util.concurrent.Service- Throws:
java.util.concurrent.TimeoutException
-
failureCause
public java.lang.Throwable failureCause()
- Specified by:
failureCausein interfacecom.google.common.util.concurrent.Service
-
addListener
public void addListener(com.google.common.util.concurrent.Service.Listener listener, java.util.concurrent.Executor executor)This is only guaranteed to add the listeners to future services. It will make a best effort attempt to add the listener to the existing service.- Specified by:
addListenerin interfacecom.google.common.util.concurrent.Service
-
-