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;
}
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();
}
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;
}
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;
}
}
}
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;
}
Aggregations