Package com.spotify.apollo.core
Interface Service.Instance
-
- All Superinterfaces:
AutoCloseable
,Closeable
- Enclosing interface:
- Service
public static interface Service.Instance extends Closeable
A running service instance.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description com.google.common.io.Closer
getCloser()
Returns aCloser
for convenience, where you can registerCloseable
s that should be closed when the application exits.com.typesafe.config.Config
getConfig()
Returns the configuration for this service instance.com.google.common.util.concurrent.ListeningExecutorService
getExecutorService()
Returns a sharedListeningExecutorService
that has virtually infinite capacity and that can be used for long-running jobs.com.google.common.util.concurrent.ListeningScheduledExecutorService
getScheduledExecutorService()
Returns a sharedListeningScheduledExecutorService
that has capacity appropriate for scheduled jobs, i.e.Service
getService()
Returns the service that this is an instance of.Service.Signaller
getSignaller()
Returns a signaller that can be used to send signals to this service instance.com.google.common.collect.ImmutableList<String>
getUnprocessedArgs()
Returns the list of command-line arguments that were not recognized by Apollo, in order.boolean
isShutdown()
Returns whether the service has gotten a shutdown signal, meaning thatwaitForShutdown()
will not block.<T> T
resolve(Class<T> type)
Get an instance provided by one of the Apollo modules.void
waitForShutdown()
A method that will block until the service has stopped.
-
-
-
Method Detail
-
getService
Service getService()
Returns the service that this is an instance of.- Returns:
- The service that this is an instance of.
-
getConfig
com.typesafe.config.Config getConfig()
Returns the configuration for this service instance.- Returns:
- The configuration for this service instance.
-
getExecutorService
com.google.common.util.concurrent.ListeningExecutorService getExecutorService()
Returns a sharedListeningExecutorService
that has virtually infinite capacity and that can be used for long-running jobs. This executor is scoped along with the service instance, which avoids the need to use the very problematic daemon threads.- Returns:
- A shared
ListeningExecutorService
.
-
getScheduledExecutorService
com.google.common.util.concurrent.ListeningScheduledExecutorService getScheduledExecutorService()
Returns a sharedListeningScheduledExecutorService
that has capacity appropriate for scheduled jobs, i.e. jobs that run periodically and have a limited execution time. UsegetExecutorService()
for jobs that run forever. This executor is scoped along with the service instance, which avoids the need to use the very problematic daemon threads.- Returns:
- A shared
ListeningScheduledExecutorService
.
-
getCloser
com.google.common.io.Closer getCloser()
Returns aCloser
for convenience, where you can registerCloseable
s that should be closed when the application exits.- Returns:
- A
Closer
for convenience.
-
getUnprocessedArgs
com.google.common.collect.ImmutableList<String> getUnprocessedArgs()
Returns the list of command-line arguments that were not recognized by Apollo, in order.- Returns:
- The list of command-line arguments that were not recognized by Apollo, in order.
-
getSignaller
Service.Signaller getSignaller()
Returns a signaller that can be used to send signals to this service instance. It can be used to send signals to a running service instance, but after the service instance has exited, sending signals will be no-ops.- Returns:
- a signaller that can be used to send signals to this service instance.
-
resolve
<T> T resolve(Class<T> type)
Get an instance provided by one of the Apollo modules.- Parameters:
type
- the type of the instance to get.- Returns:
- an instance of this type.
- Throws:
ApolloConfigurationException
- if no suitable instance of this type can be found.
-
waitForShutdown
void waitForShutdown() throws InterruptedException
A method that will block until the service has stopped. This will wait until a signal from the environment tells the service to shutdown, or an error occurs.- Throws:
InterruptedException
-
isShutdown
boolean isShutdown()
Returns whether the service has gotten a shutdown signal, meaning thatwaitForShutdown()
will not block.- Returns:
- whether the service has gotten a shutdown signal.
-
-