36 lines
622 B
Java
36 lines
622 B
Java
|
|
package ei.engine.network.response;
|
||
|
|
|
||
|
|
|
||
|
|
public abstract class ResponseEvent {
|
||
|
|
private byte[] rsp = null;
|
||
|
|
|
||
|
|
public synchronized boolean handleResponse(byte[] rsp) {
|
||
|
|
this.rsp = rsp;
|
||
|
|
notify();
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
public synchronized void waitForResponse() {
|
||
|
|
while(!gotResponse()) {
|
||
|
|
try {
|
||
|
|
this.wait();
|
||
|
|
} catch (InterruptedException e) {
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
responseEvent(rsp);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void handleResponse(){
|
||
|
|
if(gotResponse()){
|
||
|
|
responseEvent(rsp);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public boolean gotResponse(){
|
||
|
|
return (rsp != null);
|
||
|
|
}
|
||
|
|
|
||
|
|
protected abstract void responseEvent(byte[] rsp);
|
||
|
|
}
|