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 theApplicationReadyEventorApplicationFailedEventis 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_PRECEDENCEFields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
ConstructorsConstructorDescriptionTaskLifecycleListener(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-TaskRepositoryto record executions.taskNameResolver-TaskNameResolverused to determine task name for task execution.applicationArguments-ApplicationArgumentsto be used for task execution.taskExplorer-TaskExplorerto be used for task execution.taskProperties-TaskPropertiesto be used for the task execution.taskListenerExecutorObjectFactory-TaskListenerExecutorObjectFactoryto initialize TaskListenerExecutor for a task
-
-
Method Details
-
onApplicationEvent
public void onApplicationEvent(org.springframework.context.ApplicationEvent applicationEvent) UtilizesApplicationEvents to determine the end and failure of a task. Specifically:ApplicationReadyEvent- Successful end of a taskApplicationFailedEvent- Failure of a task
- Specified by:
onApplicationEventin interfaceorg.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>- Parameters:
applicationEvent- The application being listened for.
-
isAutoStartup
public boolean isAutoStartup()- Specified by:
isAutoStartupin interfaceorg.springframework.context.SmartLifecycle
-
stop
- Specified by:
stopin interfaceorg.springframework.context.SmartLifecycle
-
start
public void start()- Specified by:
startin interfaceorg.springframework.context.Lifecycle
-
stop
public void stop()- Specified by:
stopin interfaceorg.springframework.context.Lifecycle
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceorg.springframework.context.Lifecycle
-
getPhase
public int getPhase()- Specified by:
getPhasein interfaceorg.springframework.context.Phased- Specified by:
getPhasein interfaceorg.springframework.context.SmartLifecycle
-
destroy
public void destroy()- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean
-
getOrder
public int getOrder()- Specified by:
getOrderin interfaceorg.springframework.core.Ordered
-