Package org.springframework.cloud.task.configuration

# 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

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SingleInstanceTaskListener(DataSource dataSource, TaskNameResolver taskNameResolver, TaskProperties taskProperties, org.springframework.context.ApplicationEventPublisher applicationEventPublisher)`
  `SingleInstanceTaskListener(org.springframework.integration.support.locks.LockRegistry lockRegistry, TaskNameResolver taskNameResolver, TaskProperties taskProperties, org.springframework.context.ApplicationEventPublisher applicationEventPublisher)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `lockTask(TaskExecution taskExecution)`
  `void`
  `onApplicationEvent(org.springframework.context.ApplicationEvent applicationEvent)`
  `void`
  `unlockTaskOnEnd(TaskExecution taskExecution)`
  `void`
  `unlockTaskOnError(TaskExecution taskExecution, Throwable throwable)`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### SingleInstanceTaskListener

    public SingleInstanceTaskListener(org.springframework.integration.support.locks.LockRegistry lockRegistry, TaskNameResolver taskNameResolver, TaskProperties taskProperties, org.springframework.context.ApplicationEventPublisher applicationEventPublisher)

  - ### SingleInstanceTaskListener

    public SingleInstanceTaskListener(DataSource dataSource, TaskNameResolver taskNameResolver, TaskProperties taskProperties, org.springframework.context.ApplicationEventPublisher applicationEventPublisher)

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