TriggerHandler

public interface TriggerHandler

Service responsible for handling triggers. When registered for an event with a specific subject, it will act as MotechEvent listener for it. That means, when the event with the subject handled by this handler is fired, the handler will retrieve all active tasks with triggers corresponding to this event and execute them.

Methods

addDataProvider

void addDataProvider(DataProvider provider)

Adds org.motechproject.commons.api.DataProvider for this handler.

Parameters:
  • provider – DataProvider to be added

handle

void handle(MotechEvent event)

Handles the given event. This method is responsible for retrieving active tasks with triggers corresponding to this event and then executing them. It is called by the event system.

Parameters:
  • event – the event, not null
Throws:

handleRetry

void handleRetry(MotechEvent event)

Handles the given event. This method is responsible for handling task retry.

Parameters:
  • event – the event, not null

registerHandlerFor

void registerHandlerFor(String subject)

Registers this handler to listen for events with the given subject. This handler will now act as a MotechEvent listener for the given subject and will get called by the event system when an event with the given subject is fired.

Parameters:
  • subject – the event subject, not null

registerHandlerFor

void registerHandlerFor(String subject, boolean isRetryHandler)

Registers this handler to listen for events with the given subject. This handler will now act as a MotechEvent listener for the given subject and will get called by the event system when an event with the given subject is fired. If a task is using retry system, the additional retry handler should be registered. The flag isRetryHandler should be use to choose what kind of handler will be registered.

Parameters:
  • subject – the event subject, not null
  • isRetryHandler – true if handler is for task retry system; false otherwise

removeDataProvider

void removeDataProvider(String taskDataProviderId)

Removes org.motechproject.commons.api.DataProvider from this handler.

Parameters:
  • taskDataProviderId – ID of the DataProvider to be removed, passed as a String

retryTask

void retryTask(Long activityId)

Retries task execution for activity with the given ID.

Parameters:
  • activityId – the ID of activity for which task should be retried