Search in sources :

Example 91 with Msg

use of zmq.Msg in project jeromq by zeromq.

the class StreamEngine method producePingMessage.

private Msg producePingMessage() {
    assert (mechanism != null);
    Msg msg = new Msg(7 + heartbeatContext.length);
    msg.setFlags(Msg.COMMAND);
    msg.putShortString("PING");
    Wire.putUInt16(msg, options.heartbeatTtl);
    msg.put(heartbeatContext);
    msg = mechanism.encode(msg);
    nextMsg = pullAndEncode;
    if (!hasTimeoutTimer && heartbeatTimeout > 0) {
        ioObject.addTimer(heartbeatTimeout, HEARTBEAT_TIMEOUT_TIMER_ID);
        hasTimeoutTimer = true;
    }
    return msg;
}
Also used : Msg(zmq.Msg)

Example 92 with Msg

use of zmq.Msg in project jeromq by zeromq.

the class StreamEngine method error.

// Function to handle network disconnections.
private void error(ErrorReason error) {
    if (options.rawSocket) {
        // For raw sockets, send a final 0-length message to the application
        // so that it knows the peer has been disconnected.
        Msg terminator = new Msg();
        processMsg.apply(terminator);
    }
    assert (session != null);
    socket.eventDisconnected(endpoint, fd);
    session.flush();
    session.engineError(!handshaking && (mechanism == null || mechanism.status() != Mechanism.Status.HANDSHAKING), error);
    unplug();
    destroy();
}
Also used : Msg(zmq.Msg)

Example 93 with Msg

use of zmq.Msg in project jeromq by zeromq.

the class StreamEngine method restartInput.

@Override
public void restartInput() {
    assert (inputStopped);
    assert (session != null);
    assert (decoder != null);
    Msg msg = decoder.msg();
    if (!processMsg.apply(msg)) {
        if (errno.is(ZError.EAGAIN)) {
            session.flush();
        } else {
            error(ErrorReason.PROTOCOL);
        }
        return;
    }
    boolean decodingSuccess = decodeCurrentInputs();
    if (!decodingSuccess && errno.is(ZError.EAGAIN)) {
        session.flush();
    } else if (ioError) {
        error(ErrorReason.CONNECTION);
    } else if (!decodingSuccess) {
        error(ErrorReason.PROTOCOL);
    } else {
        inputStopped = false;
        ioObject.setPollIn(handle);
        session.flush();
        // Speculative read.
        inEvent();
    }
}
Also used : Msg(zmq.Msg)

Example 94 with Msg

use of zmq.Msg in project jeromq by zeromq.

the class StreamEngine method pullAndEncode.

private Msg pullAndEncode() {
    assert (mechanism != null);
    Msg msg = session.pullMsg();
    if (msg == null) {
        return null;
    }
    msg = mechanism.encode(msg);
    return msg;
}
Also used : Msg(zmq.Msg)

Example 95 with Msg

use of zmq.Msg in project jeromq by zeromq.

the class V1EncoderTest method testReaderLong.

@Test
public void testReaderLong() {
    Msg msg = readLongMessage1();
    ValueReference<ByteBuffer> ref = new ValueReference<>();
    int outsize = encoder.encode(ref, 0);
    assertThat(outsize, is(0));
    ByteBuffer out = ref.get();
    assertThat(out, nullValue());
    encoder.loadMsg(msg);
    outsize = encoder.encode(ref, 64);
    assertThat(outsize, is(64));
    out = ref.get();
    int position = out.position();
    int limit = out.limit();
    assertThat(limit, is(64));
    assertThat(position, is(64));
    ref.set(null);
    outsize = encoder.encode(ref, 64);
    assertThat(outsize, is(138));
    out = ref.get();
    position = out.position();
    limit = out.limit();
    assertThat(position, is(62));
    assertThat(limit, is(200));
}
Also used : Msg(zmq.Msg) ByteBuffer(java.nio.ByteBuffer) ValueReference(zmq.util.ValueReference) Test(org.junit.Test)

Aggregations

Msg (zmq.Msg)124 Test (org.junit.Test)45 SocketBase (zmq.SocketBase)37 Ctx (zmq.Ctx)32 ByteBuffer (java.nio.ByteBuffer)16 ValueReference (zmq.util.ValueReference)16 Pipe (zmq.pipe.Pipe)13 Blob (zmq.util.Blob)7 ArrayList (java.util.ArrayList)5 OutputStream (java.io.OutputStream)4 Socket (java.net.Socket)4 HashSet (java.util.HashSet)3 ExecutorService (java.util.concurrent.ExecutorService)2 Metadata (zmq.io.Metadata)2 InputStream (java.io.InputStream)1 List (java.util.List)1 Event (zmq.ZMQ.Event)1 ZObject (zmq.ZObject)1 Step (zmq.io.coder.IDecoder.Step)1 RawDecoder (zmq.io.coder.raw.RawDecoder)1