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
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 the
ApplicationReadyEvent
or ApplicationFailedEvent
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.Constructor and Description |
---|
TaskLifecycleListener(TaskRepository taskRepository,
TaskNameResolver taskNameResolver,
org.springframework.boot.ApplicationArguments applicationArguments,
TaskExplorer taskExplorer,
TaskProperties taskProperties,
TaskListenerExecutorObjectFactory taskListenerExecutorObjectFactory) |
Modifier and Type | Method and Description |
---|---|
void |
destroy() |
int |
getOrder() |
int |
getPhase() |
boolean |
isAutoStartup() |
boolean |
isRunning() |
void |
onApplicationEvent(org.springframework.context.ApplicationEvent applicationEvent)
Utilizes
ApplicationEvent s to determine the end and failure of a task. |
void |
start() |
void |
stop() |
void |
stop(Runnable callback) |
public TaskLifecycleListener(TaskRepository taskRepository, TaskNameResolver taskNameResolver, org.springframework.boot.ApplicationArguments applicationArguments, TaskExplorer taskExplorer, TaskProperties taskProperties, TaskListenerExecutorObjectFactory taskListenerExecutorObjectFactory)
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 taskpublic void onApplicationEvent(org.springframework.context.ApplicationEvent applicationEvent)
ApplicationEvent
s to determine the end and failure of a task.
Specifically:
ApplicationReadyEvent
- Successful end of a taskApplicationFailedEvent
- Failure of a taskonApplicationEvent
in interface org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>
applicationEvent
- The application being listened for.public boolean isAutoStartup()
isAutoStartup
in interface org.springframework.context.SmartLifecycle
public void stop(Runnable callback)
stop
in interface org.springframework.context.SmartLifecycle
public void start()
start
in interface org.springframework.context.Lifecycle
public void stop()
stop
in interface org.springframework.context.Lifecycle
public boolean isRunning()
isRunning
in interface org.springframework.context.Lifecycle
public int getPhase()
getPhase
in interface org.springframework.context.Phased
getPhase
in interface org.springframework.context.SmartLifecycle
public void destroy()
destroy
in interface org.springframework.beans.factory.DisposableBean
public int getOrder()
getOrder
in interface org.springframework.core.Ordered
Copyright © 2021 Pivotal Software, Inc.. All rights reserved.