Search in sources :

Example 26 with ZFrame

use of org.zeromq.ZFrame in project jeromq by zeromq.

the class mdbroker method sendToWorker.

/**
     * Send message to worker. If message is provided, sends that message. Does
     * not destroy the message, this is the caller's job.
     */
public void sendToWorker(Worker worker, MDP command, String option, ZMsg msgp) {
    ZMsg msg = msgp == null ? new ZMsg() : msgp.duplicate();
    // Stack protocol envelope to start of message
    if (option != null)
        msg.addFirst(new ZFrame(option));
    msg.addFirst(command.newFrame());
    msg.addFirst(MDP.W_WORKER.newFrame());
    // Stack routing envelope to start of message
    msg.wrap(worker.address.duplicate());
    if (verbose) {
        log.format("I: sending %s to worker\n", command);
        msg.dump(log.out());
    }
    msg.send(socket);
}
Also used : ZFrame(org.zeromq.ZFrame) ZMsg(org.zeromq.ZMsg)

Example 27 with ZFrame

use of org.zeromq.ZFrame in project jeromq by zeromq.

the class lruqueue3 method run.

public void run() {
    ZContext context = new ZContext();
    //  Prepare our context and sockets
    Socket worker = context.createSocket(ZMQ.REQ);
    worker.connect("ipc://backend.ipc");
    ZFrame frame = new ZFrame(lruqueue3.LRU_READY);
    //  Tell backend we're ready for work
    frame.send(worker, 0);
    while (true) {
        ZMsg msg = ZMsg.recvMsg(worker);
        if (msg == null)
            break;
        msg.getLast().reset("OK".getBytes(ZMQ.CHARSET));
        msg.send(worker);
        System.out.println(Thread.currentThread().getName() + " Worker Sent OK");
    }
    context.destroy();
}
Also used : ZFrame(org.zeromq.ZFrame) ZContext(org.zeromq.ZContext) ZMsg(org.zeromq.ZMsg) Socket(org.zeromq.ZMQ.Socket)

Aggregations

ZFrame (org.zeromq.ZFrame)27 ZMsg (org.zeromq.ZMsg)20 ZContext (org.zeromq.ZContext)13 Socket (org.zeromq.ZMQ.Socket)13 Poller (org.zeromq.ZMQ.Poller)7 ArrayList (java.util.ArrayList)4 Random (java.util.Random)4 ZMQ (org.zeromq.ZMQ)4 PollItem (org.zeromq.ZMQ.PollItem)3 IOException (java.io.IOException)2 ZLoop (org.zeromq.ZLoop)2 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 RandomAccessFile (java.io.RandomAccessFile)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1