use of suite.concurrent.Condition in project suite by stupidsing.
the class RequestResponseMatcher method requestForResponse.
public Bytes requestForResponse(RequestResponseNioChannel channel, Bytes request, int timeOut) {
Integer token = Util.temp();
Mutable<Bytes> holder = Mutable.nil();
Condition condition = new Condition(() -> holder.get() != null);
return condition.waitThen(() -> {
requests.put(token, Pair.of(holder, condition));
channel.send(RequestResponseNioChannel.REQUEST, token, request);
}, () -> {
requests.remove(token);
return holder.get();
});
}
use of suite.concurrent.Condition in project suite by stupidsing.
the class RequestResponseMatcher method onResponseReceived.
public void onResponseReceived(int token, Bytes response) {
Pair<Mutable<Bytes>, Condition> pair = requests.get(token);
Mutable<Bytes> holder = pair.t0;
Condition condition = pair.t1;
condition.thenNotify(() -> holder.set(response));
}