Package org.deltafi.common.action
Class ActionEventQueue
java.lang.Object
org.deltafi.common.action.ActionEventQueue
Service for pushing and popping action events to a redis queue.
-
Constructor Summary
ConstructorsConstructorDescriptionActionEventQueue(ActionEventQueueProperties actionEventQueueProperties, int poolSize) -
Method Summary
Modifier and TypeMethodDescriptionstatic ActionEventconvertEvent(String element) static ActionInputconvertInput(String element) voidFetches and returns a list of tasks that have been running for longer than the specified duration threshold.keys()booleanlongRunningTaskExists(String clazz, String action, String did) Check if a specific long-running task exists and if its heartbeat is within the acceptable threshold.voidputActions(List<ActionInput> actionInputs, boolean checkUnique) Puts the given action inputs into the appropriate Redis queue(s).voidputResult(ActionEvent result, String returnAddress) Submit a result object for action processingvoidputResults(List<ActionEvent> results, String returnAddress) Submit a List of result objects for action processingbooleanqueueHasTaskingForAction(ActionInput actionInput) Checks if the queue has a tasking for the specified action.voidrecordLongRunningTask(ActionExecution actionExecution) Records a long-running task in Redis.voidRemoves long-running tasks from Redis that have heartbeat times exceeding the specified duration threshold.voidremoveLongRunningTask(ActionExecution actionExecution) Removes the specified long-running task from Redis.voidsetHeartbeat(String key) longtakeAction(String actionClassName) Request an ActionInput object from the ActionEvent queue for the specified actiontakeResult(String returnAddress)
-
Constructor Details
-
ActionEventQueue
public ActionEventQueue(ActionEventQueueProperties actionEventQueueProperties, int poolSize) throws URISyntaxException - Throws:
URISyntaxException
-
-
Method Details
-
queueHasTaskingForAction
Checks if the queue has a tasking for the specified action.- Parameters:
actionInput- the action input object containing the queue name and action context- Returns:
- true if a tasking for the action exists in the queue, false otherwise
-
putActions
Puts the given action inputs into the appropriate Redis queue(s). If thecheckUniqueparameter is set totrue, this method will ensure that no other item with the same 'did' field value already exists in the queue before adding an action input.Note that checking for uniqueness is an expensive operation as it involves scanning the Redis set, which can be slow and resource-intensive, particularly for larger sets. Therefore, it's recommended to use this option only in requeue scenarios.
If the conversion of an action input to JSON fails, the method will log an error and skip that input.
- Parameters:
actionInputs- a list of action inputs to be queuedcheckUnique- iftrue, the method will check for uniqueness of 'did' field values before queuing an action input; iffalse, the method will queue all action inputs without checking for uniqueness
-
takeAction
public ActionInput takeAction(String actionClassName) throws com.fasterxml.jackson.core.JsonProcessingException Request an ActionInput object from the ActionEvent queue for the specified action- Parameters:
actionClassName- Name of action for Action event request- Returns:
- next Action on the queue for the given action name
- Throws:
com.fasterxml.jackson.core.JsonProcessingException- if the incoming event cannot be serialized
-
putResult
public void putResult(ActionEvent result, String returnAddress) throws com.fasterxml.jackson.core.JsonProcessingException Submit a result object for action processing- Parameters:
result- ActionEvent result to be posted to the action queue- Throws:
com.fasterxml.jackson.core.JsonProcessingException- if the outgoing event cannot be deserialized
-
putResults
public void putResults(List<ActionEvent> results, String returnAddress) throws com.fasterxml.jackson.core.JsonProcessingException Submit a List of result objects for action processing- Parameters:
results- List of ActionEvent results to be posted to the action queue- Throws:
com.fasterxml.jackson.core.JsonProcessingException- if any of the outgoing events cannot be deserialized
-
takeResult
public ActionEvent takeResult(String returnAddress) throws com.fasterxml.jackson.core.JsonProcessingException - Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
convertEvent
public static ActionEvent convertEvent(String element) throws com.fasterxml.jackson.core.JsonProcessingException - Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
convertInput
public static ActionInput convertInput(String element) throws com.fasterxml.jackson.core.JsonProcessingException - Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
setHeartbeat
-
drop
-
keys
-
size
-
recordLongRunningTask
Records a long-running task in Redis. Serializes the givenActionExecutionobject and stores it in Redis along with its start time and the current time as the heartbeat.- Parameters:
actionExecution- theActionExecutionobject representing the task
-
removeLongRunningTask
Removes the specified long-running task from Redis. Deletes the givenActionExecutionobject from the Redis hash, thus marking it as no longer a long-running task.- Parameters:
actionExecution- theActionExecutionobject to be removed
-
getLongRunningTasks
Fetches and returns a list of tasks that have been running for longer than the specified duration threshold. Deserializes tasks from Redis and filters out those which have heartbeat times within the acceptable range.- Returns:
- a list of
ActionExecutionobjects representing tasks that have been running beyond the threshold
-
removeExpiredLongRunningTasks
public void removeExpiredLongRunningTasks()Removes long-running tasks from Redis that have heartbeat times exceeding the specified duration threshold. Iterates over tasks in Redis, deserializing and checking their heartbeat times. If a task's heartbeat is older than the threshold or if its data is malformed, it's removed from Redis. -
longRunningTaskExists
Check if a specific long-running task exists and if its heartbeat is within the acceptable threshold.- Parameters:
clazz- The class name.action- The action name.did- The did value.- Returns:
- true if the task exists and its heartbeat is within the threshold, false otherwise.
-