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

java.lang.Object
  extended by com.veriplace.client.util.MemoryRequestStore<ResultType>
All Implemented Interfaces:
RequestStore<ResultType>

public class MemoryRequestStore<ResultType>
extends java.lang.Object
implements RequestStore<ResultType>

In-memory implementation of RequestStore.


Nested Class Summary
protected static class MemoryRequestStore.RequestStatus<ResultType>
           
 
Field Summary
protected  long allocator
           
protected  java.util.SortedMap<java.lang.Long,java.util.LinkedList<java.lang.Long>> expiration
          Map from expiration time (in seconds) to identifier(s).
protected static long FIVE_MINUTES
           
protected  java.util.Map<java.lang.Long,MemoryRequestStore.RequestStatus<ResultType>> requests
          Map from identifier to result
 
Constructor Summary
MemoryRequestStore()
           
 
Method Summary
 long add()
          Allocate a unique identifier for a subsequent response.
 ResultType get(long id)
          Get the result of a request.
 void put(long id, ResultType result)
          Save the result of a completed request.
 boolean waitForCompletion(long id)
          Wait for the result to be available for a previously submitted request.
 boolean waitForCompletion(long id, long timeout)
          Wait for the result to be available for a previously submitted request, but wait no more the timeout milliseconds.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIVE_MINUTES

protected static final long FIVE_MINUTES
See Also:
Constant Field Values

allocator

protected long allocator

requests

protected java.util.Map<java.lang.Long,MemoryRequestStore.RequestStatus<ResultType>> requests
Map from identifier to result


expiration

protected java.util.SortedMap<java.lang.Long,java.util.LinkedList<java.lang.Long>> expiration
Map from expiration time (in seconds) to identifier(s).

Constructor Detail

MemoryRequestStore

public MemoryRequestStore()
Method Detail

add

public long add()
Description copied from interface: RequestStore
Allocate a unique identifier for a subsequent response.

Specified by:
add in interface RequestStore<ResultType>

waitForCompletion

public boolean waitForCompletion(long id)
Description copied from interface: RequestStore
Wait for the result to be available for a previously submitted request.

Specified by:
waitForCompletion in interface RequestStore<ResultType>
Returns:
true

waitForCompletion

public boolean waitForCompletion(long id,
                                 long timeout)
Description copied from interface: RequestStore
Wait for the result to be available for a previously submitted request, but wait no more the timeout milliseconds.

Specified by:
waitForCompletion in interface RequestStore<ResultType>
Returns:
if the result was available or a timeout occurred

put

public void put(long id,
                ResultType result)
Description copied from interface: RequestStore
Save the result of a completed request.

Specified by:
put in interface RequestStore<ResultType>

get

public ResultType get(long id)
Description copied from interface: RequestStore
Get the result of a request.

Specified by:
get in interface RequestStore<ResultType>