Class TaskLifecycleListener
java.lang.Object
org.springframework.cloud.task.listener.TaskLifecycleListener
- All Implemented Interfaces:
EventListener
,org.springframework.beans.factory.DisposableBean
,org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>
,org.springframework.context.Lifecycle
,org.springframework.context.Phased
,org.springframework.context.SmartLifecycle
,org.springframework.core.Ordered
public class TaskLifecycleListener
extends Object
implements org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>, org.springframework.context.SmartLifecycle, org.springframework.beans.factory.DisposableBean, org.springframework.core.Ordered
Monitors the lifecycle of a task. This listener will record both the start and end of a
task in the registered
TaskRepository
.
The following events are used to identify the start and end of a task:
Lifecycle.start()
- Used to identify the start of a task. A task is expected to contain a single application context.ApplicationReadyEvent
- Used to identify the successful end of a task.ApplicationFailedEvent
- Used to identify the failure of a task.Lifecycle.stop()
- Used to identify the end of a task, if theApplicationReadyEvent
orApplicationFailedEvent
is not emitted. This can occur if an error occurs while executing a BeforeTask.
spring.cloud.task.closecontext_enabled
(defaults to false). If the spring.cloud.task.closecontext_enabled
is set
to true, then the context will be closed upon task completion regardless if non-daemon
threads are still running. Also if the context did not start, the FailedTask and
TaskEnd may not have all the dependencies met.- Author:
- Michael Minella, Glenn Renfro
-
Field Summary
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE
-
Constructor Summary
ConstructorDescriptionTaskLifecycleListener
(TaskRepository taskRepository, TaskNameResolver taskNameResolver, org.springframework.boot.ApplicationArguments applicationArguments, TaskExplorer taskExplorer, TaskProperties taskProperties, TaskListenerExecutorObjectFactory taskListenerExecutorObjectFactory, io.micrometer.observation.ObservationRegistry observationRegistry, TaskObservationCloudKeyValues taskObservationCloudKeyValues) -
Method Summary
-
Constructor Details
-
TaskLifecycleListener
public TaskLifecycleListener(TaskRepository taskRepository, TaskNameResolver taskNameResolver, org.springframework.boot.ApplicationArguments applicationArguments, TaskExplorer taskExplorer, TaskProperties taskProperties, TaskListenerExecutorObjectFactory taskListenerExecutorObjectFactory, @Autowired(required=false) io.micrometer.observation.ObservationRegistry observationRegistry, TaskObservationCloudKeyValues taskObservationCloudKeyValues) - Parameters:
taskRepository
-TaskRepository
to record executions.taskNameResolver
-TaskNameResolver
used to determine task name for task execution.applicationArguments
-ApplicationArguments
to be used for task execution.taskExplorer
-TaskExplorer
to be used for task execution.taskProperties
-TaskProperties
to be used for the task execution.taskListenerExecutorObjectFactory
-TaskListenerExecutorObjectFactory
to initialize TaskListenerExecutor for a task
-
-
Method Details
-
onApplicationEvent
public void onApplicationEvent(org.springframework.context.ApplicationEvent applicationEvent) UtilizesApplicationEvent
s to determine the end and failure of a task. Specifically:ApplicationReadyEvent
- Successful end of a taskApplicationFailedEvent
- Failure of a task
- Specified by:
onApplicationEvent
in interfaceorg.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>
- Parameters:
applicationEvent
- The application being listened for.
-
isAutoStartup
public boolean isAutoStartup()- Specified by:
isAutoStartup
in interfaceorg.springframework.context.SmartLifecycle
-
stop
- Specified by:
stop
in interfaceorg.springframework.context.SmartLifecycle
-
start
public void start()- Specified by:
start
in interfaceorg.springframework.context.Lifecycle
-
stop
public void stop()- Specified by:
stop
in interfaceorg.springframework.context.Lifecycle
-
isRunning
public boolean isRunning()- Specified by:
isRunning
in interfaceorg.springframework.context.Lifecycle
-
getPhase
public int getPhase()- Specified by:
getPhase
in interfaceorg.springframework.context.Phased
- Specified by:
getPhase
in interfaceorg.springframework.context.SmartLifecycle
-
destroy
public void destroy()- Specified by:
destroy
in interfaceorg.springframework.beans.factory.DisposableBean
-
getOrder
public int getOrder()- Specified by:
getOrder
in interfaceorg.springframework.core.Ordered
-