|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.lang.Thread com.gridsystems.innergrid.kernel.genericutils.PagedRequest<E>
E
- Object type to be paged.public abstract class PagedRequest<E>
Base class for asynchronous paged requests.
Subclassing
Subclasses must implement the run()
method, and do it fill the
results
list.
The implementation should correctly (and regularly) check for interruption condition, as it is the mechanism used by PagedRequestManager to cancel request executions.
Usage
A typical iteration loop over a paged request that gets the results, concurrently to the request execution, will have the following layout:
PageRequestManager<MyBean> myManager = new PageRequestManager<MyBean>();
...
PagedRequest<MyBean> req = myManager.getPagedRequest(id);
while (true) {
try {
MyBean items[] = req.getResults(results.size(), N);
if (items == null) break; // No more items
// do something whith items
}
catch (PagedRequestTimeoutException e) {
// do nothing
}
catch (PagedRequestNoDataException e) {
// sleep some time
}
}
Or, if we just want to wait until the request execution is finished, and get all its results in one operation, we can do:
PagedRequest req = ...;
req.join();
int count = req.getResultsCount();
Object results[] = (count == 0) ? new Object[0] : req.getResults(0, count);
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.lang.Thread |
---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
Field Summary | |
---|---|
protected com.gridsystems.innergrid.kernel.server.KernelContext |
originalContext
Request user information. |
protected java.util.ArrayList<E> |
results
Results of the request. |
protected java.lang.Class<E> |
theClass
Class of type E. |
Fields inherited from class java.lang.Thread |
---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
---|---|
PagedRequest(com.gridsystems.innergrid.kernel.server.KernelContext context,
java.lang.Class<E> theClass,
boolean blockRequest)
Creates a new instance. |
Method Summary | |
---|---|
void |
clear()
Clears the Paged request. |
long |
getId()
Gets the identifier of the paged request. |
long |
getLastAccessTime()
Gets the time of the last access to this request data. |
E[] |
getResults(int from,
int count)
Calls getResultsTimeout() with an appropriate timeout value depending on the 'block' flag specified at construction time. |
int |
getResultsCount()
Gets the number of results of the paged request. |
E[] |
getResultsTimeout(int from,
int count,
long timeout)
Asks for 'count' results, starting at offset 'from'. |
long |
getTime()
Gets the hour of the paged request. |
java.lang.String |
getUser()
Gets the user of the paged request. |
abstract void |
run()
Subclasses must implement the request in this method. |
Methods inherited from class java.lang.Thread |
---|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected com.gridsystems.innergrid.kernel.server.KernelContext originalContext
protected java.util.ArrayList<E> results
protected final java.lang.Class<E> theClass
Constructor Detail |
---|
public PagedRequest(com.gridsystems.innergrid.kernel.server.KernelContext context, java.lang.Class<E> theClass, boolean blockRequest)
theClass
- Class of type Econtext
- The request contextblockRequest
- true if the request must be blockingMethod Detail |
---|
public abstract void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public long getId()
getId
in class java.lang.Thread
public java.lang.String getUser()
public long getTime()
public int getResultsCount()
public long getLastAccessTime()
public E[] getResultsTimeout(int from, int count, long timeout) throws PagedRequestNoDataException
The returned value depends on the following rules:
PagedRequestNoDataException
will be thrown.
null
will be returned. This marks the
end condition for a retrieval loop.
from
- The offset of the first result to getcount
- The number of results to gettimeout
- The max blocking time
PagedRequestNoDataException
- In case of timeoutpublic E[] getResults(int from, int count) throws PagedRequestNoDataException
from
- The initial offsetcount
- The number of results to retrieve
PagedRequestNoDataException
- if no results are available yetpublic void clear()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |