org.opentox.toxotis.util
Class TaskRunner

java.lang.Object
  extended by org.opentox.toxotis.util.TaskRunner
All Implemented Interfaces:
Callable<Task>

public class TaskRunner
extends Object
implements Callable<Task>

Reloads a task until its status is no longer Task.Status.RUNNING.

Author:
Pantelis Sopasakis, Charalampos Chomenides
See Also:
Task

Constructor Summary
TaskRunner(Task task)
           
TaskRunner(Task task, AuthenticationToken token)
           
 
Method Summary
 Task call()
          Runs a remote task until it completes.
 Task getTask()
           
 AuthenticationToken getToken()
           
 void setDelay(long delay)
          Specify the delay between successive reloads of the task resource from the remote location.
 void setTask(Task task)
           
 void setToken(AuthenticationToken token)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TaskRunner

public TaskRunner(Task task)

TaskRunner

public TaskRunner(Task task,
                  AuthenticationToken token)
Method Detail

getTask

public Task getTask()

setTask

public void setTask(Task task)

getToken

public AuthenticationToken getToken()

setToken

public void setToken(AuthenticationToken token)

setDelay

public void setDelay(long delay)
Specify the delay between successive reloads of the task resource from the remote location.

Parameters:
delay - Delay in milliseconds.

call

public Task call()
          throws ServiceInvocationException
Runs a remote task until it completes. As long as the task returns a 202 or 201 status code, the client keeps monitoring the progress of the task every a certain time period which is specified by the method setDelay. When the task is over (completed), this method returns the updated task which points to the result (see Task.getResultUri(). If the task fails to complete, i.e. it has some status different from running or queued, then the task is updated and returned directly to the invoker, but no exception is thrown in such a case. The invoking method should always check the status of the returned task!

Specified by:
call in interface Callable<Task>
Returns:
Completed or Failed Task
Throws:
ServiceInvocationException - In case the remote service is not accessible/available, the connection breaks or other unexpected exception is caught.


Copyright © 2011-2012 OpenTox. All Rights Reserved.