Search in sources :

Example 1 with ValueReference

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;
}
Also used : Msg(zmq.Msg) Pipe(zmq.pipe.Pipe) ValueReference(zmq.util.ValueReference)

Example 2 with ValueReference

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;
        }
    }
}
Also used : Msg(zmq.Msg) Pipe(zmq.pipe.Pipe) ValueReference(zmq.util.ValueReference)

Example 3 with ValueReference

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));
}
Also used : Msg(zmq.Msg) ByteBuffer(java.nio.ByteBuffer) ValueReference(zmq.util.ValueReference) Test(org.junit.Test)

Example 4 with ValueReference

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));
}
Also used : Msg(zmq.Msg) ByteBuffer(java.nio.ByteBuffer) ValueReference(zmq.util.ValueReference) Test(org.junit.Test)

Example 5 with ValueReference

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));
}
Also used : Msg(zmq.Msg) ByteBuffer(java.nio.ByteBuffer) ValueReference(zmq.util.ValueReference) Test(org.junit.Test)

Aggregations

ValueReference (zmq.util.ValueReference)19 Msg (zmq.Msg)16 ByteBuffer (java.nio.ByteBuffer)11 Test (org.junit.Test)10 Pipe (zmq.pipe.Pipe)6 Blob (zmq.util.Blob)4 Step (zmq.io.coder.IDecoder.Step)3 Metadata (zmq.io.Metadata)2 IDecoder (zmq.io.coder.IDecoder)1 IEncoder (zmq.io.coder.IEncoder)1 V1Decoder (zmq.io.coder.v1.V1Decoder)1 V1Encoder (zmq.io.coder.v1.V1Encoder)1 V2Decoder (zmq.io.coder.v2.V2Decoder)1 V2Encoder (zmq.io.coder.v2.V2Encoder)1 Mechanisms (zmq.io.mechanism.Mechanisms)1 SelectorProviderChooser (zmq.io.net.SelectorProviderChooser)1 TcpAddressMask (zmq.io.net.tcp.TcpAddress.TcpAddressMask)1 MsgAllocator (zmq.msg.MsgAllocator)1 MsgAllocatorThreshold (zmq.msg.MsgAllocatorThreshold)1