com.veriplace.client.util
Class AbstractRequestManager<ResultType>

java.lang.Object
  extended by com.veriplace.client.util.AbstractRequestManager<ResultType>
Direct Known Subclasses:
GetLocationRequestManager

public class AbstractRequestManager<ResultType>
extends java.lang.Object

Abstraction around making a Veriplace API request and retrieving the result.

Requests can block for some time, and the user interface should not be coupled too tightly with the request behavior. This implementation performs all requests on background threads. The caller can then block for the result at any time; typically the blocking wait will happen after we've displayed an automatically-refreshing "please wait" page.


Nested Class Summary
static class AbstractRequestManager.AbstractRequest<ResultType>
          Generic inner class for background requests.
 
Field Summary
protected  RequestStore<ResultWrapper<ResultType>> requestStore
           
 
Constructor Summary
AbstractRequestManager()
           
 
Method Summary
 ResultType getResult(long id)
          Get (and remove) the result returned for the given request id, assuming that the request has completed.
 ResultWrapper<ResultType> getResultAndToken(long id)
          Get (and remove) the result returned for the given request id, assuming that the request has completed.
 void setExecutorService(java.util.concurrent.ExecutorService executor)
           
 void setRequestStore(RequestStore<ResultWrapper<ResultType>> requestStore)
           
 long submitRequest(AbstractRequestManager.AbstractRequest<ResultType> request)
          Submit a request object (which was created by some method of the specific AbstractRequestManager sucblass) for asynchronous processing.
 boolean waitForCompletion(long id)
          Wait for the result of a request to be available.
 boolean waitForCompletion(long id, long timeout)
          Wait for the result of a request to be available.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

requestStore

protected RequestStore<ResultWrapper<ResultType>> requestStore
Constructor Detail

AbstractRequestManager

public AbstractRequestManager()
Method Detail

setRequestStore

public void setRequestStore(RequestStore<ResultWrapper<ResultType>> requestStore)

setExecutorService

public void setExecutorService(java.util.concurrent.ExecutorService executor)

submitRequest

public long submitRequest(AbstractRequestManager.AbstractRequest<ResultType> request)
Submit a request object (which was created by some method of the specific AbstractRequestManager sucblass) for asynchronous processing.

Returns:
the new request ID.

waitForCompletion

public boolean waitForCompletion(long id)
Wait for the result of a request to be available.

Returns:
true

waitForCompletion

public boolean waitForCompletion(long id,
                                 long timeout)
Wait for the result of a request to be available.

Returns:
if the result was available or a timeout occurred

getResult

public ResultType getResult(long id)
                     throws VeriplaceException
Get (and remove) the result returned for the given request id, assuming that the request has completed.

Returns:
the result obtained, or null if the request has not completed
Throws:
VeriplaceException - if the request completed with an error result

getResultAndToken

public ResultWrapper<ResultType> getResultAndToken(long id)
                                            throws VeriplaceException
Get (and remove) the result returned for the given request id, assuming that the request has completed.

Returns:
an object containing the result obtained, and the access token that was used for the request
Throws:
VeriplaceException - if the request completed with an error result
BadParameterException - if the request ID does not exist or the request has not completed