Class SingleInstanceTaskListener
java.lang.Object
org.springframework.cloud.task.configuration.SingleInstanceTaskListener
- All Implemented Interfaces:
EventListener
,org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>
public class SingleInstanceTaskListener
extends Object
implements org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>
When spring.cloud.task.single-instance-enabled is set to true this listener will create
a lock for the task based on the spring.cloud.task.name. If a lock already exists this
Listener will throw a TaskExecutionException. If this listener is added manually, then
it should be added as the first listener in the chain.
- Since:
- 2.0.0
- Author:
- Glenn Renfro, Mahmoud Ben Hassine
-
Constructor Summary
ConstructorDescriptionSingleInstanceTaskListener
(DataSource dataSource, TaskNameResolver taskNameResolver, TaskProperties taskProperties, org.springframework.context.ApplicationEventPublisher applicationEventPublisher, org.springframework.context.ApplicationContext applicationContext) SingleInstanceTaskListener
(org.springframework.integration.support.locks.LockRegistry lockRegistry, TaskNameResolver taskNameResolver, TaskProperties taskProperties, org.springframework.context.ApplicationEventPublisher applicationEventPublisher, org.springframework.context.ApplicationContext applicationContext) -
Method Summary
Modifier and TypeMethodDescriptionvoid
lockTask
(TaskExecution taskExecution) void
onApplicationEvent
(org.springframework.context.ApplicationEvent applicationEvent) void
unlockTaskOnEnd
(TaskExecution taskExecution) void
unlockTaskOnError
(TaskExecution taskExecution, Throwable throwable)
-
Constructor Details
-
SingleInstanceTaskListener
public SingleInstanceTaskListener(org.springframework.integration.support.locks.LockRegistry lockRegistry, TaskNameResolver taskNameResolver, TaskProperties taskProperties, org.springframework.context.ApplicationEventPublisher applicationEventPublisher, org.springframework.context.ApplicationContext applicationContext) -
SingleInstanceTaskListener
public SingleInstanceTaskListener(DataSource dataSource, TaskNameResolver taskNameResolver, TaskProperties taskProperties, org.springframework.context.ApplicationEventPublisher applicationEventPublisher, org.springframework.context.ApplicationContext applicationContext)
-
-
Method Details
-
lockTask
-
unlockTaskOnEnd
- Throws:
Exception
-
unlockTaskOnError
@FailedTask public void unlockTaskOnError(TaskExecution taskExecution, Throwable throwable) throws Exception - Throws:
Exception
-
onApplicationEvent
public void onApplicationEvent(org.springframework.context.ApplicationEvent applicationEvent) - Specified by:
onApplicationEvent
in interfaceorg.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>
-