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.FAILED
state.AutoRestartingService(java.util.function.Supplier<S> factory, ServiceRestartPolicy policy)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.void
awaitRunning()
void
awaitRunning(long timeout, java.util.concurrent.TimeUnit unit)
void
awaitTerminated()
void
awaitTerminated(long timeout, java.util.concurrent.TimeUnit unit)
java.lang.Throwable
failureCause()
protected S
getDelegate()
Used for testing only.boolean
isRunning()
AutoRestartingService
startAsync()
If the service state isService.State.NEW
,Service.State.FAILED
,Service.State.TERMINATED
this initiates service startup and returns immediately.com.google.common.util.concurrent.Service.State
state()
void
stopAndAwait()
void
stopAndAwait(long timeout, java.util.concurrent.TimeUnit unit)
AutoRestartingService
stopAsync()
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.FAILED
state 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.FAILED
state.- 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:RestartableService
If the service state isService.State.NEW
,Service.State.FAILED
,Service.State.TERMINATED
this initiates service startup and returns immediately.- Specified by:
startAsync
in interfaceRestartableService
- Specified by:
startAsync
in interfacecom.google.common.util.concurrent.Service
- Returns:
- this
-
isRunning
public boolean isRunning()
- Specified by:
isRunning
in interfacecom.google.common.util.concurrent.Service
-
state
public com.google.common.util.concurrent.Service.State state()
- Specified by:
state
in interfacecom.google.common.util.concurrent.Service
-
stopAsync
public AutoRestartingService stopAsync()
Description copied from interface:RestartableService
Stops the service.- Specified by:
stopAsync
in interfaceRestartableService
- Specified by:
stopAsync
in 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:
stopAndAwait
in interfaceRestartableService
- Throws:
java.util.concurrent.TimeoutException
-
stopAndAwait
public void stopAndAwait()
- Specified by:
stopAndAwait
in interfaceRestartableService
-
awaitRunning
public void awaitRunning()
- Specified by:
awaitRunning
in interfacecom.google.common.util.concurrent.Service
-
awaitRunning
public void awaitRunning(long timeout, java.util.concurrent.TimeUnit unit) throws java.util.concurrent.TimeoutException
- Specified by:
awaitRunning
in interfacecom.google.common.util.concurrent.Service
- Throws:
java.util.concurrent.TimeoutException
-
awaitTerminated
public void awaitTerminated()
- Specified by:
awaitTerminated
in interfacecom.google.common.util.concurrent.Service
-
awaitTerminated
public void awaitTerminated(long timeout, java.util.concurrent.TimeUnit unit) throws java.util.concurrent.TimeoutException
- Specified by:
awaitTerminated
in interfacecom.google.common.util.concurrent.Service
- Throws:
java.util.concurrent.TimeoutException
-
failureCause
public java.lang.Throwable failureCause()
- Specified by:
failureCause
in 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:
addListener
in interfacecom.google.common.util.concurrent.Service
-
-