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 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

      @BeforeTask public void lockTask(TaskExecution taskExecution)
    • unlockTaskOnEnd

      @AfterTask public void unlockTaskOnEnd(TaskExecution taskExecution) throws Exception
      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 interface org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>