use of zmq.io.Metadata in project jeromq by zeromq.
the class ZMetadata method read.
public static ZMetadata read(String meta) {
if (meta == null || meta.length() == 0) {
return null;
}
try {
ByteBuffer buffer = ZMQ.CHARSET.newEncoder().encode(CharBuffer.wrap(meta));
Metadata data = new Metadata();
data.read(buffer, 0, null);
return new ZMetadata(data);
} catch (CharacterCodingException e) {
e.printStackTrace();
return null;
}
}
use of zmq.io.Metadata in project jeromq by zeromq.
the class ZMQ method getMessageMetadata.
// Get message metadata string
public static String getMessageMetadata(Msg msg, String property) {
String data = null;
Metadata metadata = msg.getMetadata();
if (metadata != null) {
data = metadata.get(property);
}
return data;
}
use of zmq.io.Metadata 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.io.Metadata 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