Package akka.javasdk
Interface ServiceSetup
public interface ServiceSetup
Implement this on a single class per deployable service annotated with {
Setup} and
override one or more of the default methods to provide objects for dependency injection or act on
service lifecycle events.
Concrete classes can accept the following types to the constructor:
ComponentClientHttpClientProviderTimerSchedulerMaterializerConfigAgentRegistrySanitizer
-
Method Summary
Modifier and TypeMethodDescriptiondefault DependencyProviderInvoked once before the service is started, to create a dependency provider.Provides a set of components that should be disabled from running.default voidThe on shutdown hook runs on each service instance when it shuts down — not on the service as a whole.default voidThe on startup hook is called every time a service instance boots up.
-
Method Details
-
onStartup
default void onStartup()The on startup hook is called every time a service instance boots up. This can happen for very different reasons: restarting / redeploying the service, scaling up to more instances or even without any user-driven action (e.g.: Runtime versions being rolled out, infrastructure-related incidents, etc.). Therefore, one should carefully consider how to use this hook and its implementation.This hook is called after
createDependencyProvider(). -
onShutdown
default void onShutdown()The on shutdown hook runs on each service instance when it shuts down — not on the service as a whole. Just likeonStartup(), it can be triggered for many reasons (rolling restarts, redeploys, scaling down, runtime upgrades, infrastructure events, etc.), so consider carefully how to use it.It is called after the instance has stopped handling requests and any in-flight requests have completed, which makes it a good place to release resources allocated by the service setup or in
onStartup()— for example, closing a connection pool or releasing a file handle.Runs in the
service-stopphase of Akka Coordinated Shutdown. Exceptions thrown from this method are logged but do not block subsequent shutdown phases. -
createDependencyProvider
Invoked once before the service is started, to create a dependency provider. It is not possible to interact with components in this method.This hook is called before
onStartup(). -
disabledComponents
Provides a set of components that should be disabled from running.
-