ibspan.ecap.shared.util
Class ScheduledExecutorCompletionService<RES>

java.lang.Object
  extended by ibspan.ecap.shared.util.ScheduledExecutorCompletionService<RES>
Type Parameters:
RES - the type of the results returned by the executed tasks
All Implemented Interfaces:
java.util.concurrent.CompletionService<RES>

public class ScheduledExecutorCompletionService<RES>
extends java.lang.Object
implements java.util.concurrent.CompletionService<RES>

A CompletionService that uses a supplied ScheduledExecutorService to schedule and execute tasks. This class arranges that submitted tasks are, upon completion, placed on a queue accessible using take. This class is based on the ExecutorCompletionService.

Author:
Micha³ Drozdowicz

Constructor Summary
ScheduledExecutorCompletionService(java.util.concurrent.ScheduledExecutorService scheduler)
          Creates a ScheduledExecutorCompletionService using the supplied scheduler for base task execution and a LinkedBlockingQueue as a completion queue.
ScheduledExecutorCompletionService(java.util.concurrent.ScheduledExecutorService scheduler, java.util.concurrent.BlockingQueue<java.util.concurrent.Future<RES>> completionQueue)
          Creates a ScheduledExecutorCompletionService using the supplied scheduler for base task execution and the supplied queue as its completion queue.
 
Method Summary
 java.util.concurrent.Future<RES> poll()
           
 java.util.concurrent.Future<RES> poll(long timeout, java.util.concurrent.TimeUnit unit)
           
 java.util.concurrent.ScheduledFuture<RES> schedule(java.util.concurrent.Callable<RES> callable, long delay, java.util.concurrent.TimeUnit unit)
          Creates and executes a ScheduledFuture that becomes enabled after the given delay.
 java.util.concurrent.ScheduledFuture<?> schedule(java.lang.Runnable command, long delay, java.util.concurrent.TimeUnit unit)
          Creates and executes a one-shot action that becomes enabled after the given delay.
 java.util.concurrent.Future<RES> submit(java.util.concurrent.Callable<RES> task)
           
 java.util.concurrent.Future<RES> submit(java.lang.Runnable task, RES result)
           
 java.util.concurrent.Future<RES> take()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScheduledExecutorCompletionService

public ScheduledExecutorCompletionService(java.util.concurrent.ScheduledExecutorService scheduler)
Creates a ScheduledExecutorCompletionService using the supplied scheduler for base task execution and a LinkedBlockingQueue as a completion queue.

Parameters:
scheduler - the scheduler to use
Throws:
java.lang.NullPointerException - if scheduler is null

ScheduledExecutorCompletionService

public ScheduledExecutorCompletionService(java.util.concurrent.ScheduledExecutorService scheduler,
                                          java.util.concurrent.BlockingQueue<java.util.concurrent.Future<RES>> completionQueue)
Creates a ScheduledExecutorCompletionService using the supplied scheduler for base task execution and the supplied queue as its completion queue.

Parameters:
scheduler - the scheduler to use
completionQueue - the queue to use as the completion queue normally one dedicated for use by this service
Throws:
java.lang.NullPointerException - if scheduler or completionQueue are null
Method Detail

submit

public java.util.concurrent.Future<RES> submit(java.util.concurrent.Callable<RES> task)
Specified by:
submit in interface java.util.concurrent.CompletionService<RES>

submit

public java.util.concurrent.Future<RES> submit(java.lang.Runnable task,
                                               RES result)
Specified by:
submit in interface java.util.concurrent.CompletionService<RES>

schedule

public java.util.concurrent.ScheduledFuture<?> schedule(java.lang.Runnable command,
                                                        long delay,
                                                        java.util.concurrent.TimeUnit unit)
Creates and executes a one-shot action that becomes enabled after the given delay.

Parameters:
command - the task to execute.
delay - the time from now to delay execution.
unit - the time unit of the delay parameter.
Returns:
a Future representing pending completion of the task, and whose get() method will return null upon completion.
Throws:
RejectedExecutionException - if task cannot be scheduled for execution.
java.lang.NullPointerException - if command is null

schedule

public java.util.concurrent.ScheduledFuture<RES> schedule(java.util.concurrent.Callable<RES> callable,
                                                          long delay,
                                                          java.util.concurrent.TimeUnit unit)
Creates and executes a ScheduledFuture that becomes enabled after the given delay.

Parameters:
callable - the function to execute.
delay - the time from now to delay execution.
unit - the time unit of the delay parameter.
Returns:
a ScheduledFuture that can be used to extract result or cancel.
Throws:
RejectedExecutionException - if task cannot be scheduled for execution.
java.lang.NullPointerException - if callable is null

take

public java.util.concurrent.Future<RES> take()
                                      throws java.lang.InterruptedException
Specified by:
take in interface java.util.concurrent.CompletionService<RES>
Throws:
java.lang.InterruptedException

poll

public java.util.concurrent.Future<RES> poll()
Specified by:
poll in interface java.util.concurrent.CompletionService<RES>

poll

public java.util.concurrent.Future<RES> poll(long timeout,
                                             java.util.concurrent.TimeUnit unit)
                                      throws java.lang.InterruptedException
Specified by:
poll in interface java.util.concurrent.CompletionService<RES>
Throws:
java.lang.InterruptedException