Examples of Poller


Examples of org.zeromq.ZMQ.Poller

      pipe.send("READY"); // optional

      Socket snapshot = ctx.createSocket(ZMQ.ROUTER);
      snapshot.bind("tcp://*:5556");

      Poller poller = new ZMQ.Poller(2);
      poller.register(pipe, ZMQ.Poller.POLLIN);
      poller.register(snapshot, ZMQ.Poller.POLLIN);

      long stateSequence = 0;
      while (!Thread.currentThread().isInterrupted()) {
        if (poller.poll() < 0)
                    break;              //  Context has been shut down

        // apply state updates from main thread
        if (poller.pollin(0)) {
          kvsimple kvMsg = kvsimple.recv(pipe);
                    if (kvMsg == null)
                        break;
          StateManager.kvMap.put(kvMsg.getKey(), kvMsg);
          stateSequence = kvMsg.getSequence();
        }

        // execute state snapshot request
        if (poller.pollin(1)) {
          byte[] identity = snapshot.recv(0);
                    if (identity == null)
                        break;
          String request = new String(snapshot.recv(0));

View Full Code Here

Examples of org.zeromq.ZMQ.Poller

        //  us an API that does more with fewer calls:

        while (!Thread.currentThread().isInterrupted()) {

            //  Initialize poll set
            Poller items = new Poller (2);

            //  Always poll for worker activity on backend
            items.register(backend, Poller.POLLIN);

            //  Poll front-end only if we have available workers
            if(workerQueue.size() > 0)
                items.register(frontend, Poller.POLLIN);

            if (items.poll() < 0)
                break;      //  Interrupted

            //  Handle worker activity on backend
            if (items.pollin(0)) {

                ZMsg msg = ZMsg.recvMsg (backend);
                if (msg == null)
                    break//  Interrupted

                ZFrame identity = msg.unwrap ();
                //  Queue worker address for LRU routing
                workerQueue.add (identity);

                //  Forward message to client if it's not a READY
                ZFrame frame = msg.getFirst ();
                if (Arrays.equals (frame.getData (), WORKER_READY))
                    msg.destroy ();
                else
                    msg.send (frontend);
            }

            if (items.pollin(1)) {
                //  Get client request, route to first available worker
                ZMsg msg = ZMsg.recvMsg (frontend);
                if (msg != null) {
                    msg.wrap (workerQueue.poll ());
                    msg.send (backend);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.