Search in sources :

Example 11 with Msg

use of zmq.Msg in project jeromq by zeromq.

the class Dish method xleave.

@Override
protected boolean xleave(String group) {
    if (group.length() > Msg.MAX_GROUP_LENGTH) {
        errno.set(ZError.EINVAL);
        return false;
    }
    if (!subscriptions.remove(group)) {
        errno.set(ZError.EINVAL);
        return false;
    }
    Msg msg = new Msg();
    msg.initLeave();
    msg.setGroup(group);
    dist.sendToAll(msg);
    return true;
}
Also used : Msg(zmq.Msg)

Example 12 with Msg

use of zmq.Msg in project jeromq by zeromq.

the class Dish method sendSubscriptions.

private void sendSubscriptions(Pipe pipe) {
    for (String s : subscriptions) {
        Msg msg = new Msg();
        msg.initJoin();
        msg.setGroup(s);
        pipe.write(msg);
    }
    pipe.flush();
}
Also used : Msg(zmq.Msg)

Example 13 with Msg

use of zmq.Msg in project jeromq by zeromq.

the class Dish method xjoin.

@Override
protected boolean xjoin(String group) {
    if (group.length() > Msg.MAX_GROUP_LENGTH) {
        errno.set(ZError.EINVAL);
        return false;
    }
    // User cannot join same group twice
    if (!subscriptions.add(group)) {
        errno.set(ZError.EINVAL);
        return false;
    }
    Msg msg = new Msg();
    msg.initJoin();
    msg.setGroup(group);
    dist.sendToAll(msg);
    return true;
}
Also used : Msg(zmq.Msg)

Example 14 with Msg

use of zmq.Msg in project jeromq by zeromq.

the class Req method recvReplyPipe.

private Msg recvReplyPipe() {
    while (true) {
        ValueReference<Pipe> pipe = new ValueReference<>();
        Msg msg = super.recvpipe(pipe);
        if (msg == null) {
            return null;
        }
        if (replyPipe.get() == null || replyPipe.get() == pipe.get()) {
            return msg;
        }
    }
}
Also used : Msg(zmq.Msg) Pipe(zmq.pipe.Pipe) ValueReference(zmq.util.ValueReference)

Example 15 with Msg

use of zmq.Msg in project jeromq by zeromq.

the class Req method xsend.

@Override
public boolean xsend(final Msg msg) {
    // we can't send another request.
    if (receivingReply) {
        if (strict) {
            errno.set(ZError.EFSM);
            return false;
        }
        receivingReply = false;
        messageBegins = true;
    }
    // First part of the request is the request identity.
    if (messageBegins) {
        replyPipe.set(null);
        if (requestIdFramesEnabled) {
            requestId++;
            final Msg id = new Msg(4);
            Wire.putUInt32(id.buf(), requestId);
            id.setFlags(Msg.MORE);
            boolean rc = super.sendpipe(id, replyPipe);
            if (!rc) {
                return false;
            }
        }
        Msg bottom = new Msg();
        bottom.setFlags(Msg.MORE);
        boolean rc = super.sendpipe(bottom, replyPipe);
        if (!rc) {
            return false;
        }
        assert (replyPipe.get() != null);
        messageBegins = false;
        // An hour later REQ sends a request to B. B's old reply is used.
        while (true) {
            Msg drop = super.xrecv();
            if (drop == null) {
                break;
            }
        }
    }
    boolean more = msg.hasMore();
    boolean rc = super.xsend(msg);
    if (!rc) {
        return false;
    }
    // If the request was fully sent, flip the FSM into reply-receiving state.
    if (!more) {
        receivingReply = true;
        messageBegins = true;
    }
    return true;
}
Also used : Msg(zmq.Msg)

Aggregations

Msg (zmq.Msg)124 Test (org.junit.Test)45 SocketBase (zmq.SocketBase)37 Ctx (zmq.Ctx)32 ByteBuffer (java.nio.ByteBuffer)16 ValueReference (zmq.util.ValueReference)16 Pipe (zmq.pipe.Pipe)13 Blob (zmq.util.Blob)7 ArrayList (java.util.ArrayList)5 OutputStream (java.io.OutputStream)4 Socket (java.net.Socket)4 HashSet (java.util.HashSet)3 ExecutorService (java.util.concurrent.ExecutorService)2 Metadata (zmq.io.Metadata)2 InputStream (java.io.InputStream)1 List (java.util.List)1 Event (zmq.ZMQ.Event)1 ZObject (zmq.ZObject)1 Step (zmq.io.coder.IDecoder.Step)1 RawDecoder (zmq.io.coder.raw.RawDecoder)1