Search in sources :

Example 26 with Msg

use of zmq.Msg in project jeromq by zeromq.

the class RawDecoder method decode.

@Override
public Step.Result decode(ByteBuffer buffer, int size, ValueReference<Integer> processed) {
    processed.set(size);
    inProgress = new Msg(size);
    inProgress.put(buffer);
    return Step.Result.DECODED;
}
Also used : Msg(zmq.Msg)

Example 27 with Msg

use of zmq.Msg in project jeromq by zeromq.

the class ZSocket method sendFrame.

/**
 * Send a frame
 *
 * @param frame
 * @param flags
 * @return return true if successful
 */
public boolean sendFrame(ZFrame frame, int flags) {
    final byte[] data = frame.getData();
    final Msg msg = new Msg(data);
    if (socketBase.send(msg, flags)) {
        return true;
    }
    mayRaise();
    return false;
}
Also used : Msg(zmq.Msg)

Example 28 with Msg

use of zmq.Msg in project jeromq by zeromq.

the class ZSocket method send.

public int send(byte[] b, int flags) {
    final Msg msg = new Msg(b);
    if (socketBase.send(msg, flags)) {
        return msg.size();
    }
    mayRaise();
    return -1;
}
Also used : Msg(zmq.Msg)

Example 29 with Msg

use of zmq.Msg in project jeromq by zeromq.

the class SessionBase method pullMsg.

protected Msg pullMsg() {
    if (pipe == null) {
        return null;
    }
    Msg msg = pipe.read();
    if (msg == null) {
        return null;
    }
    incompleteIn = msg.hasMore();
    return msg;
}
Also used : Msg(zmq.Msg)

Example 30 with Msg

use of zmq.Msg in project jeromq by zeromq.

the class SessionBase method zapConnect.

public int zapConnect() {
    assert (zapPipe == null);
    Ctx.Endpoint peer = findEndpoint("inproc://zeromq.zap.01");
    if (peer.socket == null) {
        errno.set(ZError.ECONNREFUSED);
        return ZError.ECONNREFUSED;
    }
    if (peer.options.type != ZMQ.ZMQ_REP && peer.options.type != ZMQ.ZMQ_ROUTER && peer.options.type != ZMQ.ZMQ_SERVER) {
        errno.set(ZError.ECONNREFUSED);
        return ZError.ECONNREFUSED;
    }
    // Create a bi-directional pipe that will connect
    // session with zap socket.
    ZObject[] parents = { this, peer.socket };
    int[] hwms = { 0, 0 };
    boolean[] conflates = { false, false };
    Pipe[] pipes = Pipe.pair(parents, hwms, conflates);
    // Attach local end of the pipe to this socket object.
    zapPipe = pipes[0];
    zapPipe.setNoDelay();
    zapPipe.setEventSink(this);
    sendBind(peer.socket, pipes[1], false);
    // Send empty identity if required by the peer.
    if (peer.options.recvIdentity) {
        Msg id = new Msg();
        id.setFlags(Msg.IDENTITY);
        zapPipe.write(id);
        zapPipe.flush();
    }
    return 0;
}
Also used : Msg(zmq.Msg) Ctx(zmq.Ctx) Pipe(zmq.pipe.Pipe) ZObject(zmq.ZObject)

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