|
QJCC homepage | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object biz.chitec.quarterback.gjsa.SyncBurstReceiver
Abstract class for handling synchronous bursts on client side. The both most interesting classes, initBurst() and handleBurstPart() are declared abstract and to be implemented by a subclass. This class itself handles the complete burst handling, e.g. doing the right calls to the server and looping as long as more results are available.
This class implements the Runnable interface, so that it can be used very simply in a separate thread. Of course, one has to take care that no other thread uses the SessionConnector while this class' thread being active. To archieve this, the caller must not use the SessionConnector between calling start() and any of the finished...() methods being called.
The run()-loop is worked through as long as the burst is not finished. With no errors occurring, finishedCorrectly() is called after the last data has been processed. If the server returns an errornous reply, the loop is aborted and finishedWithError() is called. In case of any client-side exceptions, finishedWithThrowable() is called.
Handling the answer may be stopped by calling stopHandleBurstPart(). Note that that method returns immideately, even though the main thread may continue running for some time as the current burst chunk request is always processed completely. Especially, it is not guaranteed that the SessionConnector may be used immideately after stopHandleBurstPart() returns.
For this case, the method stopHandleBurstPartAndWait() exists. That one initiates an abortion of the loop and waits synchronously afterwards until the loop and the appropriate finish...() method have completed. With this method, it is guaranteed that the SessionConnector is free to use afterwards.
Beside all the multi-thread-stuff, it is also possible to call the run() method of the object synchronously and run the complete receiver in the current thread. For convenience reasons, the runSynchronously() method exists. It can be used like this:
SessionConnector sc=... // define connector in which way ever SyncBurstReceiver.runSynchronously(sc,new SyncBurstReceiver() { public ServerReply initBurst() throws IOException { return sc.query(ServerCommands.GETMAGICLIST); } public void handleBurstPart(final List v) { for (int i=0;i<v.size();i++) System.out.println(v.get(i)); } });
Field Summary | |
private boolean |
background
|
protected boolean |
doclientloop
Flag whether the loop shell be run through once again depending on client state. |
private java.lang.Object |
doloopfinishwaiter
|
private boolean |
dolooprunning
|
protected boolean |
doserverloop
Flag whether the loop shell be run through once again depending on server transmissions. |
protected ServerConnector |
sc
The connection object to the server. |
Constructor Summary | |
SyncBurstReceiver()
Parameterless constructor. |
|
SyncBurstReceiver(ServerConnector scx)
Standard constructor. |
Method Summary | |
void |
finishedByInterrupt()
Callback for correct, but interrupted finishing. |
void |
finishedCorrectly()
Callback for correct finishing. |
void |
finishedWithError(ServerReply sr)
Callback for server-side errornous finishing. |
void |
finishedWithThrowable(java.lang.Throwable t)
Callback for client-side errornous finishung. |
abstract void |
handleBurstPart(java.util.List v)
Burst part handling method. |
abstract ServerReply |
initBurst()
Burst initialisation method. |
void |
run()
The run loop. |
static void |
runSynchronously(ServerConnector sc,
boolean background,
SyncBurstReceiver sbr)
Run a SyncBurstReceiver synchronously. |
static void |
runSynchronously(ServerConnector sc,
SyncBurstReceiver sbr)
Run a SyncBurstReceiver synchronously without yielding in the receiver loop. |
void |
setServerConnector(ServerConnector scx)
Sets the ServerConnector. |
void |
stopHandleBurstPart()
Stop the handling. |
void |
stopHandleBurstPartAndWait()
Stop handling and wait until it is stopped. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private boolean background
private boolean dolooprunning
private java.lang.Object doloopfinishwaiter
protected ServerConnector sc
protected boolean doserverloop
protected boolean doclientloop
Constructor Detail |
public SyncBurstReceiver()
public SyncBurstReceiver(ServerConnector scx)
Method Detail |
public abstract ServerReply initBurst() throws java.io.IOException
java.io.IOException
public abstract void handleBurstPart(java.util.List v)
public void stopHandleBurstPart()
public void stopHandleBurstPartAndWait()
public void setServerConnector(ServerConnector scx)
public void finishedCorrectly()
public void finishedByInterrupt()
public void finishedWithError(ServerReply sr)
public void finishedWithThrowable(java.lang.Throwable t)
public final void run()
run
in interface java.lang.Runnable
public static void runSynchronously(ServerConnector sc, SyncBurstReceiver sbr)
sc
- ServerConnector to connect the receiver to.sbr
- SyncBurstReceiver which is run.public static void runSynchronously(ServerConnector sc, boolean background, SyncBurstReceiver sbr)
sc
- ServerConnector to connect the receiver to.background
- Flag whether the receiver should run with reduced prioritysbr
- SyncBurstReceiver which is run.
|
QJCC homepage | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |