CloudPlugs REST Library  1.0.0
for Java
RestJob Class Reference

An instance of this class is an enqueued request execution obtained by RestBaseManager#getJobOf(int). More...

Inheritance diagram for RestJob:

Public Member Functions

final void run ()
 
boolean cancel (boolean mayInterruptIfRunning)
 
boolean cancel ()
 
boolean isCancelled ()
 
boolean isDone ()
 
Response get () throws InterruptedException, ExecutionException
 
Response get (long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
 
Response getResponse ()
 
Request getRequest ()
 
int getTimeout ()
 
RestCallback getCallback ()
 

Protected Member Functions

 RestJob (RestSpooler spooler, Request request, int timeout, RestCallback cb)
 

Detailed Description

An instance of this class is an enqueued request execution obtained by RestBaseManager#getJobOf(int).

Constructor & Destructor Documentation

◆ RestJob()

RestJob ( RestSpooler  spooler,
Request  request,
int  timeout,
RestCallback  cb 
)
protected

Member Function Documentation

◆ cancel() [1/2]

boolean cancel ( boolean  mayInterruptIfRunning)

Attempts to cancel execution of this task. This attempt will fail if the task has already completed, has already been cancelled, or could not be cancelled for some other reason. If successful, and this task has not started when cancel is called, this task should never run. If the task has already started, then the mayInterruptIfRunning parameter determines whether the thread executing this task should be interrupted in an attempt to stop the task.

After this method returns, subsequent calls to isDone will always return true. Subsequent calls to isCancelled will always return true if this method returned true.

Parameters
mayInterruptIfRunningtrue if the thread executing this task should be interrupted; otherwise, in-progress tasks are allowed to complete
Returns
false if the task could not be cancelled, typically because it has already completed normally; true otherwise

◆ cancel() [2/2]

boolean cancel ( )

◆ get() [1/2]

Response get ( ) throws InterruptedException, ExecutionException

Waits if necessary for the computation to complete, and then retrieves its result.

Returns
the computed result
Exceptions
java.util.concurrent.ExecutionExceptionif the computation threw an exception
InterruptedExceptionif the current thread was interrupted while waiting

◆ get() [2/2]

Response get ( long  timeout,
TimeUnit  unit 
) throws InterruptedException, ExecutionException, TimeoutException

Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.

Parameters
timeoutthe maximum time to wait
unitthe time unit of the timeout argument
Returns
the computed result
Exceptions
java.util.concurrent.ExecutionExceptionif the computation threw an exception
InterruptedExceptionif the current thread was interrupted while waiting
java.util.concurrent.TimeoutExceptionif the wait timed out

◆ getCallback()

RestCallback getCallback ( )

Retrieve the callback to invoke upon the competition of this job.

Returns
the callback or null if there is no callback associated to this job

◆ getRequest()

Request getRequest ( )

Retrieve the request of this job.

Returns
the produced HTTP request of this job

◆ getResponse()

Response getResponse ( )

Obtain the response of this job.

Returns
the resulting HTTP response

◆ getTimeout()

int getTimeout ( )

Retrieve the connection timeout applied when sending the HTTP request of this job.

Returns
the connection timeout in seconds

◆ isCancelled()

boolean isCancelled ( )

Returns true if this task was cancelled before it completed normally.

Returns
true if this task was cancelled before it completed

◆ isDone()

boolean isDone ( )

Returns true if this task completed.

Completion may be due to normal termination, an exception, or cancellation – in all of these cases, this method will return true.

Returns
true if this task completed

◆ run()

final void run ( )

Runnable implementation executed in the spooler thread. Do not directly invoke this method.