|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.lsst.ccs.utilities.dispatch.InvocationDispenser
public class InvocationDispenser
Typical use of this pattern is to have two threads:
public synchronized void replytoA(Object elem1, elem2) {
//do something
}
public void sendCommandA(Object someData) {
String token = this.myInvocationDispenser.register( new Invoker() {
public void invoke(Object... args) {
//check args ?
replytoA(args[0], args[1]) ;
}
} ) ;
ACommand toBeSent = buildCommand(token, someData) ;
sendCommand(toBeSent)
}
The listening Thread :
public void run() {
while(doItAgain) {
// don't forget exception handling!
CommandData receivedData = readReply() ;
String correlationString = receivedData.getToken() ;
Object[] responseData = receivedData.getData() ;
myInvocationDispenser.callBack(correlationString, responseData) ;
}
}
| Nested Class Summary | |
|---|---|
static class |
InvocationDispenser.TokenLostException
|
| Constructor Summary | |
|---|---|
InvocationDispenser()
|
|
| Method Summary | |
|---|---|
Object |
call(String token,
Object... args)
calls the registered invoker which corresponds to the token. |
Object |
callBack(String token,
Object... args)
calls the registered invoker which corresponds to the token. |
void |
dumpTask(String token)
Removes a response task |
String |
generateToken()
generates a unique token (for this ClassLoader context!) |
boolean |
isTokenUsed(String token)
tells if the token is known. |
String |
register(Invoker invoker)
registers an Invoker and returns a token to be used to run the invocation code |
String |
register(String token,
Invoker invoker)
registers an invoker and the token is given by the calling code. |
Future |
registerFuture(String token,
Invoker invoker)
Gets a Future object from this task registration. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public InvocationDispenser()
| Method Detail |
|---|
public String generateToken()
public String register(Invoker invoker)
invoker - should not be null.
public String register(String token,
Invoker invoker)
token - invoker -
public Future registerFuture(String token,
Invoker invoker)
Exemple of call may be :
public String pleaseCall(String arg) {
String token = myInvocationDispenser.generateToken() ;
Future future = registerFuture(token, new Invoker() {
public Object invoke(Object... args) {
return args[0] ;
}
}
ACommand toBeSent = buildCommand(token, arg) ;
sendCommand(toBeSent)
return (String) future.get() ;
}
token - invoker -
public void dumpTask(String token)
token - public boolean isTokenUsed(String token)
token -
public Object callBack(String token,
Object... args)
throws Exception
token - args -
InvocationDispenser.TokenLostException
Exception
public Object call(String token,
Object... args)
throws Exception
token - args -
InvocationDispenser.TokenLostException
Exception
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||