Object
LazyService
- All Implemented Interfaces:
AutoCloseable
Simple implementation of service lifecycle.
Lifecycle phases:
- not started
- started
- stopped
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Stops the service if it is not yet stopped (idempotent operation).protected abstract void
onClose()
Called only once during service lifetime.protected abstract void
onStart()
Called only once during service lifetime when no exception is thrown.void
Starts the service if it is not yet started (idempotent operation).
-
Constructor Details
-
LazyService
public LazyService()
-
-
Method Details
-
startLazy
public void startLazy()Starts the service if it is not yet started (idempotent operation). -
onStart
protected abstract void onStart()Called only once during service lifetime when no exception is thrown. If it throws an exception then service will not be started and can be retried later again until it finishes without exceptions. -
onClose
protected abstract void onClose()Called only once during service lifetime. Service will be marked as closed even if exception is thrown -
close
public void close()Stops the service if it is not yet stopped (idempotent operation).- Specified by:
close
in interfaceAutoCloseable
-