use of zmq.util.ValueReference in project jeromq by zeromq.
the class Router method xhasIn.
@Override
protected boolean xhasIn() {
// definitely more parts available.
if (moreIn) {
return true;
}
// We may already have a message pre-fetched.
if (prefetched) {
return true;
}
// Try to read the next message.
// The message, if read, is kept in the pre-fetch buffer.
ValueReference<Pipe> pipe = new ValueReference<>();
prefetchedMsg = fq.recvPipe(errno, pipe);
// TODO: handle the situation when the peer changes its identity.
while (prefetchedMsg != null && prefetchedMsg.isIdentity()) {
prefetchedMsg = fq.recvPipe(errno, pipe);
}
if (prefetchedMsg == null) {
return false;
}
assert (pipe.get() != null);
Blob identity = pipe.get().getIdentity();
prefetchedId = new Msg(identity.data());
prefetchedId.setFlags(Msg.MORE);
prefetched = true;
identitySent = false;
return true;
}
use of zmq.util.ValueReference in project jeromq by zeromq.
the class Router method xrecv.
@Override
protected Msg xrecv() {
Msg msg;
if (prefetched) {
if (!identitySent) {
msg = prefetchedId;
prefetchedId = null;
identitySent = true;
} else {
msg = prefetchedMsg;
prefetchedMsg = null;
prefetched = false;
}
moreIn = msg.hasMore();
return msg;
}
ValueReference<Pipe> pipe = new ValueReference<>();
msg = fq.recvPipe(errno, pipe);
// TODO: handle the situation when the peer changes its identity.
while (msg != null && msg.isIdentity()) {
msg = fq.recvPipe(errno, pipe);
}
if (msg == null) {
return null;
}
assert (pipe.get() != null);
// If we are in the middle of reading a message, just return the next part.
if (moreIn) {
moreIn = msg.hasMore();
} else {
// We are at the beginning of a message.
// Keep the message part we have in the prefetch buffer
// and return the ID of the peer instead.
prefetchedMsg = msg;
prefetched = true;
Blob identity = pipe.get().getIdentity();
msg = new Msg(identity.data());
msg.setFlags(Msg.MORE);
identitySent = true;
}
return msg;
}
use of zmq.util.ValueReference in project jeromq by zeromq.
the class Stream method xhasIn.
@Override
protected boolean xhasIn() {
// We may already have a message pre-fetched.
if (prefetched) {
return true;
}
// Try to read the next message.
// The message, if read, is kept in the pre-fetch buffer.
ValueReference<Pipe> pipe = new ValueReference<>();
prefetchedMsg = fq.recvPipe(errno, pipe);
if (prefetchedMsg == null) {
return false;
}
assert (pipe.get() != null);
assert (!prefetchedMsg.hasMore());
Blob identity = pipe.get().getIdentity();
prefetchedId = new Msg(identity.data());
// forward metadata (if any)
Metadata metadata = prefetchedMsg.getMetadata();
if (metadata != null) {
prefetchedId.setMetadata(metadata);
}
prefetchedId.setFlags(Msg.MORE);
prefetched = true;
identitySent = false;
return true;
}
use of zmq.util.ValueReference in project jeromq by zeromq.
the class Stream method xrecv.
@Override
public Msg xrecv() {
Msg msg;
if (prefetched) {
if (!identitySent) {
msg = prefetchedId;
prefetchedId = null;
identitySent = true;
} else {
msg = prefetchedMsg;
prefetchedMsg = null;
prefetched = false;
}
return msg;
}
ValueReference<Pipe> pipe = new ValueReference<>();
prefetchedMsg = fq.recvPipe(errno, pipe);
// TODO DIFF V4 we sometimes need to process the commands to receive data, let's just return and give it another chance
if (prefetchedMsg == null) {
errno.set(ZError.EAGAIN);
return null;
}
assert (pipe.get() != null);
assert (!prefetchedMsg.hasMore());
// We have received a frame with TCP data.
// Rather than sending this frame, we keep it in prefetched
// buffer and send a frame with peer's ID.
Blob identity = pipe.get().getIdentity();
msg = new Msg(identity.data());
// forward metadata (if any)
Metadata metadata = prefetchedMsg.getMetadata();
if (metadata != null) {
msg.setMetadata(metadata);
}
msg.setFlags(Msg.MORE);
prefetched = true;
identitySent = true;
return msg;
}
Aggregations