Package org.zeromq.ZMQ

Examples of org.zeromq.ZMQ.PollItem


        //  Hold actual handler+arg so we can call this later
        Socket socket = ctx.createSocket(type);
        socket.bind(endpoint);
        voterFn = handler;
        voterArg = arg;
        PollItem poller = new PollItem(socket, ZMQ.Poller.POLLIN);
        return loop.addPoller(poller, VoterReady, this);
    }
View Full Code Here


        //  We route topic updates from frontend to backend, and
        //  we handle subscriptions by sending whatever we cached,
        //  if anything:
        while (true) {
            PollItem[] items = {
                    new PollItem(frontend, ZMQ.Poller.POLLIN),
                    new PollItem(backend, ZMQ.Poller.POLLIN),
            };
            if (ZMQ.poll(items, 1000) == -1)
                break;              //  Interrupted

            //  Any new topic data we cache and then forward
View Full Code Here

        //  Send out heartbeats at regular intervals
        long heartbeat_at = System.currentTimeMillis() + HEARTBEAT_INTERVAL;

        while (true) {
            PollItem items [] = {
                new PollItem( backend,  ZMQ.Poller.POLLIN ),
                new PollItem( frontend, ZMQ.Poller.POLLIN )
            };
            //  Poll frontend only if we have available workers
            int rc = ZMQ.poll (items, workers.size() > 0 ? 2:1,
                HEARTBEAT_INTERVAL );
            if (rc == -1)
View Full Code Here

            //  Set random identity to make tracing easier
            String identity = String.format("%04X-%04X", rand.nextInt(), rand.nextInt());
            client.setIdentity(identity.getBytes());
            client.connect("tcp://localhost:5570");

            PollItem[] items = new PollItem[] { new PollItem(client, Poller.POLLIN) };

            int requestNbr = 0;
            while (!Thread.currentThread().isInterrupted()) {
                //  Tick once per second, pulling in arriving messages
                for (int centitick = 0; centitick < 100; centitick++) {
View Full Code Here

        //  Set timer for next outgoing state message
        long sendStateAt = System.currentTimeMillis() + HEARTBEAT;
        while (!Thread.currentThread().isInterrupted()) {
            PollItem[] items = {
                    new PollItem(frontend, ZMQ.Poller.POLLIN),
                    new PollItem(statesub, ZMQ.Poller.POLLIN),
            };
            int timeLeft = (int) ((sendStateAt - System.currentTimeMillis()));
            if (timeLeft < 0)
                timeLeft = 0;
            int rc = ZMQ.poll(items, 2, timeLeft);
View Full Code Here

        //  Queue of available workers
        ArrayList<ZFrame> workers = new ArrayList<ZFrame> ();
       
        //  The body of this example is exactly the same as lruqueue2.
        while (true) {
            PollItem items [] = {
                new PollItem( backend,  Poller.POLLIN ),
                new PollItem( frontend, Poller.POLLIN )
            };
            int rc = ZMQ.poll (items, workers.size() > 0 ? 2 : 1, -1);

            //  Poll frontend only if we have available workers
            if (rc == -1)
View Full Code Here

        //  Register state change handlers
        bStar.newActive(new NewActive(), this);
        bStar.newPassive(new NewPassive(), this);

        //  Register our other handlers with the bstar reactor
        PollItem poller = new PollItem(collector, ZMQ.Poller.POLLIN);

        bStar.zloop().addPoller(poller, new Collector(), this);
        bStar.zloop().addTimer(1000, 0, new FlushTTL(), this);
        bStar.zloop().addTimer(1000, 0, new SendHugz(), this);
View Full Code Here

            srv.active = true;
            srv.passive = false;

            //  Stop subscribing to updates
            PollItem poller = new PollItem(srv.subscriber, ZMQ.Poller.POLLIN);
            srv.bStar.zloop().removePoller(poller);

            //  Apply pending list to own hash table
            for (kvmsg msg: srv.pending) {
                msg.setSequence(++srv.sequence);
View Full Code Here

            }
            srv.active = false;
            srv.passive = true;

            //  Start subscribing to updates
            PollItem poller = new PollItem(srv.subscriber, ZMQ.Poller.POLLIN);
            srv.bStar.zloop().addPoller(poller, new Subscriber(), srv);
            return 0;
        }
View Full Code Here

        ZThread.start(new TitanicClose());

        //  Main dispatcher loop
        while (true) {
            //  We'll dispatch once per second, if there's no activity
            PollItem items [] = { new PollItem(requestPipe, ZMQ.Poller.POLLIN) };
            int rc = ZMQ.poll(items, 1, 1000);
            if (rc == -1)
                break;              //  Interrupted
            if (items [0].isReadable()) {
                //  Ensure message directory exists
View Full Code Here

TOP

Related Classes of org.zeromq.ZMQ.PollItem

Copyright © 2018 www.massapicom. 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.