Search in sources :

Example 1 with Condition

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();
    });
}
Also used : Condition(suite.concurrent.Condition) Bytes(suite.primitive.Bytes)

Example 2 with Condition

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));
}
Also used : Condition(suite.concurrent.Condition) Mutable(suite.adt.Mutable) Bytes(suite.primitive.Bytes)

Aggregations

Condition (suite.concurrent.Condition)2 Bytes (suite.primitive.Bytes)2 Mutable (suite.adt.Mutable)1