use of zmq.util.ValueReference in project jeromq by zeromq.
the class Server method xrecv.
@Override
protected Msg xrecv() {
Msg msg;
ValueReference<Pipe> pipe = new ValueReference<>();
msg = fq.recvPipe(errno, pipe);
// Drop any messages with more flag
while (msg != null && msg.hasMore()) {
// drop all frames of the current multi-frame message
msg = fq.recvPipe(errno, null);
while (msg != null && msg.hasMore()) {
msg = fq.recvPipe(errno, null);
}
// get the new message
if (msg != null) {
msg = fq.recvPipe(errno, pipe);
}
}
if (msg == null) {
return msg;
}
assert (pipe.get() != null);
int routingId = pipe.get().getRoutingId();
msg.setRoutingId(routingId);
return msg;
}
use of zmq.util.ValueReference 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.util.ValueReference in project jeromq by zeromq.
the class AbstractDecoderTest method testReader.
@Test
public void testReader() {
ByteBuffer in = decoder.getBuffer();
int insize = readShortMessage(in);
assertThat(insize, is(7));
in.flip();
ValueReference<Integer> process = new ValueReference<>(0);
decoder.decode(in, insize, process);
assertThat(process.get(), is(7));
Msg msg = decoder.msg();
assertThat(msg, notNullValue());
assertThat(msg.flags(), is(1));
}
use of zmq.util.ValueReference in project jeromq by zeromq.
the class AbstractDecoderTest method testReaderLong.
@Test
public void testReaderLong() {
ByteBuffer in = decoder.getBuffer();
int insize = readLongMessage1(in);
assertThat(insize, is(64));
in.flip();
ValueReference<Integer> process = new ValueReference<>(0);
decoder.decode(in, insize, process);
assertThat(process.get(), is(64));
in = decoder.getBuffer();
assertThat(in.capacity(), is(200));
assertThat(in.position(), is(62));
in.put("23456789".getBytes(ZMQ.CHARSET));
insize = readLongMessage2(in);
assertThat(insize, is(200));
decoder.decode(in, 138, process);
assertThat(process.get(), is(138));
assertThat(in.array()[199], is((byte) 'x'));
Msg msg = decoder.msg();
assertThat(msg, notNullValue());
byte last = msg.data()[199];
assertThat(last, is((byte) 'x'));
assertThat(msg.size(), is(200));
assertThat(msg.flags(), is(1));
}
use of zmq.util.ValueReference in project jeromq by zeromq.
the class AbstractDecoderTest method testReaderExtraLong.
@Test
public void testReaderExtraLong() {
ByteBuffer in = decoder.getBuffer();
int insize = readExtraLongMessage(in);
// assertThat(insize, is(62));
in.flip();
ValueReference<Integer> process = new ValueReference<>(0);
decoder.decode(in, insize, process);
assertThat(process.get(), is(insize));
in = decoder.getBuffer();
assertThat(in.capacity(), is(330));
assertThat(in.position(), is(52));
in.put("23456789".getBytes(ZMQ.CHARSET));
in.put("0123456789".getBytes(ZMQ.CHARSET));
insize = readLongMessage2(in);
assertThat(insize, is(200));
insize = readLongMessage2(in);
assertThat(insize, is(330));
decoder.decode(in, 278, process);
assertThat(process.get(), is(278));
assertThat(in.array()[329], is((byte) 'x'));
Msg msg = decoder.msg();
assertThat(msg, notNullValue());
byte last = msg.data()[329];
assertThat(last, is((byte) 'x'));
assertThat(msg.size(), is(330));
}
Aggregations