Class SQSTaskQueue

java.lang.Object
org.duracloud.common.queue.aws.SQSTaskQueue
All Implemented Interfaces:
TaskQueue

public class SQSTaskQueue extends Object implements TaskQueue
SQSTaskQueue acts as the interface for interacting with an Amazon Simple Queue Service (SQS) queue. This class provides a way to interact with a remote SQS Queue, it emulates the functionality of a queue.
Author:
Erik Paulsson Date: 10/21/13
  • Constructor Details

    • SQSTaskQueue

      public SQSTaskQueue(String queueName)
      Creates a SQSTaskQueue that serves as a handle to interacting with a remote Amazon SQS Queue. The AmazonSQSClient will search for Amazon credentials on the system as described here: http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/DefaultAWSCredentialsProviderChain.html Moreover, it is possible to set the region to use via the AWS_REGION environment variable or one of the other methods described here: http://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/java-dg-region-selection.html
    • SQSTaskQueue

      public SQSTaskQueue(com.amazonaws.services.sqs.AmazonSQS sqsClient, String queueName)
  • Method Details

    • getName

      public String getName()
      Description copied from interface: TaskQueue
      A name identifying the queue used for logging and analysis purposes.
      Specified by:
      getName in interface TaskQueue
      Returns:
    • marshallTask

      protected Task marshallTask(com.amazonaws.services.sqs.model.Message msg)
    • unmarshallTask

      protected String unmarshallTask(Task task)
    • put

      public void put(Task task)
      Description copied from interface: TaskQueue
      puts a task on the queue
      Specified by:
      put in interface TaskQueue
    • put

      public void put(Task... tasks)
      Convenience method that calls put(Set)
      Specified by:
      put in interface TaskQueue
      Parameters:
      tasks -
    • put

      public void put(Set<Task> tasks)
      Puts multiple tasks on the queue using batch puts. The tasks argument can contain more than 10 Tasks, in that case there will be multiple SQS batch send requests made each containing up to 10 messages.
      Specified by:
      put in interface TaskQueue
      Parameters:
      tasks -
    • take

      public Set<Task> take(int maxTasks) throws TimeoutException
      Description copied from interface: TaskQueue
      Take a max of specified number of tasks. Blocks until at least one task is available.
      Specified by:
      take in interface TaskQueue
      Parameters:
      maxTasks - to take from queue. Must be between 1 and 10 inclusive.
      Returns:
      Throws:
      TimeoutException
    • take

      public Task take() throws TimeoutException
      Description copied from interface: TaskQueue
      Blocks until a task is available
      Specified by:
      take in interface TaskQueue
      Returns:
      Throws:
      TimeoutException
    • extendVisibilityTimeout

      public void extendVisibilityTimeout(Task task) throws TaskNotFoundException
      Description copied from interface: TaskQueue
      Responsible for robustly extending the visibility timeout of a Task.
      Specified by:
      extendVisibilityTimeout in interface TaskQueue
      Throws:
      TaskNotFoundException
    • deleteTask

      public void deleteTask(Task task) throws TaskNotFoundException
      Description copied from interface: TaskQueue
      Deletes a task from the queue.
      Specified by:
      deleteTask in interface TaskQueue
      Throws:
      TaskNotFoundException
    • deleteTasks

      public void deleteTasks(Set<Task> tasks) throws TaskException
      Description copied from interface: TaskQueue
      Deletes a set of tasks
      Specified by:
      deleteTasks in interface TaskQueue
      Throws:
      TaskException
    • requeue

      public void requeue(Task task)
      Description copied from interface: TaskQueue
      Requeues the task by deleting the task, incrementing the "attempts" counter, and re-adding back to the queue. Any subsequent calls on the requeued task via the task queue should fail due to the task not being found.
      Specified by:
      requeue in interface TaskQueue
    • size

      public Integer size()
      Specified by:
      size in interface TaskQueue
      Returns:
      The approximate number of elements in this queue (does not include invisible and delayed tasks).
    • sizeIncludingInvisibleAndDelayed

      public Integer sizeIncludingInvisibleAndDelayed()
      Specified by:
      sizeIncludingInvisibleAndDelayed in interface TaskQueue
      Returns:
      The approximate number of elements in this queue including all items that are visible (available for takes), invisible (in process - not yet completed), and delayed (pending addition to the queue).