Package zmq

Examples of zmq.Msg


        }

        MsgIterator it = ZPUtils.iterator(sock.base().recv(0), true);

        while (it.hasNext()) {
            Msg header = it.next();
            if (it.hasNext()) {
                Msg data = it.next();
                result.add(new Message(header.data(), data.data()));
            } else
                break;
        }

        return result;
View Full Code Here


        private int pushMsg()
        {
            if (count == 0)
                return 0;

            Msg msg = new Msg(4);
            msg.setFlags(Msg.MORE);
            ByteBuffer.wrap(msg.data()).putInt(count);

            int rc = msg_sink.pushMsg(msg);
            if (rc != 0) {
                if (rc != ZError.EAGAIN) {
                    decodingError();
View Full Code Here

        {
            if (!identity_received) {
                if (msg_sink == null)
                    return false;

                Msg msg = new Msg(msg_size);
                assert (msg_flags == 0);
                msg.setFlags(msg_flags);

                buffer.get(msg.data());
                int rc = msg_sink.pushMsg(msg);
                if (rc != 0) {
                    if (rc != ZError.EAGAIN)
                        decodingError();
View Full Code Here

            status = in_progress.data()[0];
            if (type == MESSAGE_FILE) {
                process_file();

                in_progress = new Msg(1);
                in_progress.setFlags(Msg.MORE);
                in_progress.put((byte) status);
            }

            return encode_message();
View Full Code Here

        boolean success = true;
        boolean sentAddress = false;
        boolean recvAddress = false;
        int rc;
        boolean more;
        Msg msg;
        byte[] target;
        int size = identities.size();
        PollItem items[] = new PollItem[2];

        if (front_.getSocketOpt(ZMQ.ZMQ_TYPE) != ZMQ.ZMQ_ROUTER ||
                backend_.getSocketOpt(ZMQ.ZMQ_TYPE) != ZMQ.ZMQ_ROUTER) {
            throw new IllegalArgumentException("Both router socket is required");
        }

        items[0] = new PollItem(front_, ZMQ.ZMQ_POLLIN);
        items[1] = new PollItem(backend_, ZMQ.ZMQ_POLLIN);

        Selector selector;
        try {
            selector = Selector.open();
        } catch (IOException e) {
            throw new ZError.IOException(e);
        }

        while (success) {
            //  Wait while there are either requests or replies to process.
            rc = ZMQ.zmq_poll(selector, items, -1);
            if (rc < 0)
                break;

            //  Process a request.
            if (items[0].isReadable()) {
                while (true) {
                    msg = front_.recv(0);
                    if (msg == null) {
                        success = false;
                        break;
                    }

                    if (!sentAddress) {
                        int hint = (int) msg.data()[0];
                        if (hint < 0) {
                            hint = (0xFF) & hint;
                        }
                        target = identities.get(hint % size);
                        // routing address
                        success = backend_.send(new Msg(target), ZMQ.ZMQ_SNDMORE);
                        if (!success) {
                            System.out.println("send 0 failed");

                            break;
                        }
                        sentAddress = true;
                    }

                    more = msg.hasMore();

                    success = backend_.send(msg, more ? ZMQ.ZMQ_SNDMORE : 0);
                    if (!success) {
                        System.out.println("send failed");
                        break;
                    }

                    if (!more) {
                        sentAddress = false;
                        break;
                    }
                }
            }
            //  Process a reply.
            if (success && items[1].isReadable()) {
                while (true) {
                    msg = backend_.recv(0);
                    if (msg == null) {
                        System.out.println("recv failed");

                        success = false;
                        break;
                    }

                    if (!recvAddress) {
                        // don't care worker's address
                        recvAddress = true;
                        continue;
                    }

                    more = msg.hasMore();

                    success = front_.send(msg, more ? ZMQ.ZMQ_SNDMORE : 0);
                    if (!success) {
                        System.out.println("send 2 failed");
View Full Code Here

        boolean success = true;
        boolean sentAddress = false;
        boolean recvAddress = false;
        int rc;
        boolean more;
        Msg msg;
        byte[] target;
        int size = identities.size();
        int available = size;
        PollItem items[] = new PollItem[2];

        if (front_.getSocketOpt(ZMQ.ZMQ_TYPE) != ZMQ.ZMQ_ROUTER ||
                backend_.getSocketOpt(ZMQ.ZMQ_TYPE) != ZMQ.ZMQ_ROUTER) {
            throw new IllegalArgumentException("Both router socket is required");
        }

        items[0] = new PollItem(front_, ZMQ.ZMQ_POLLIN);
        items[1] = new PollItem(backend_, ZMQ.ZMQ_POLLIN);

        Selector selector;
        try {
            selector = Selector.open();
        } catch (IOException e) {
            throw new ZError.IOException(e);
        }

        while (success) {
            //  Wait while there are either requests or replies to process.
            if (available == 0)
                items[0].interestOps(0);
            else
                items[0].interestOps(ZMQ.ZMQ_POLLIN);

            rc = ZMQ.zmq_poll(selector, items, -1);
            if (rc < 0)
                break;

            //  Process a request.
            if (items[0].isReadable()) {
                while (true) {
                    msg = front_.recv(0);
                    if (msg == null) {
                        success = false;
                        break;
                    }

                    if (!sentAddress) {
                        target = identities.get(--available);
                        // routing address
                        success = backend_.send(new Msg(target), ZMQ.ZMQ_SNDMORE);
                        if (!success) {
                            if (backend_.errno() != ZError.EHOSTUNREACH)
                                continue;
                            else
                                break;
                        }
                        sentAddress = true;
                    }

                    more = msg.hasMore();

                    success = backend_.send(msg, more ? ZMQ.ZMQ_SNDMORE : 0);
                    if (!success)
                        break;
                    if (!more) {
                        sentAddress = false;
                        break;
                    }
                }
            }
            //  Process a reply.
            if (success && items[1].isReadable()) {
                while (true) {
                    msg = backend_.recv(0);
                    if (msg == null) {
                        success = false;
                        break;
                    }

                    if (!recvAddress) {
                        identities.set(available++, msg.data());
                        recvAddress = true;
                        continue;
                    }

                    more = msg.hasMore();

                    success = front_.send(msg, more ? ZMQ.ZMQ_SNDMORE : 0);

                    if (!success)
                        break;
View Full Code Here

    {

        Map.Entry<Long, Segment> entry = segments.floorEntry(start);
        List<Msg> results = new ArrayList<Msg>();
        MappedByteBuffer buf;
        Msg msg;

        if (entry == null) {
            return results;
        }
        buf = entry.getValue().getBuffer(false);
        buf.position((int) (start - entry.getKey()));

        MsgIterator it = new MsgIterator(buf, conf.allow_empty_message);

        while (it.hasNext()) {
            msg = it.next();
            if (msg == null)
                break;
            max = max - msg.size();
            if (max <= 0)
                break;
            results.add(msg);
        }
View Full Code Here

    {

        int count = 0;
        Map.Entry<Long, Segment> entry = segments.floorEntry(start);
        MappedByteBuffer buf;
        Msg msg;

        if (entry == null) {
            return count;
        }
        buf = entry.getValue().getBuffer(false);
        buf.position((int) (start - entry.getKey()));

        MsgIterator it = new MsgIterator(buf, conf.allow_empty_message);

        while (it.hasNext()) {
            msg = it.next();
            if (msg == null)
                break;
            max = max - msg.size();
            if (max <= 0)
                break;
            count++;
        }
View Full Code Here

            try {
                MappedByteBuffer buf = ch.map(MapMode.READ_ONLY, 0, ch.size());
                int pos = 0;
                MsgIterator it = new MsgIterator(buf, allowEmpty);
                while (it.hasNext()) {
                    Msg msg = it.next();
                    if (msg == null)
                        break;
                    pos = buf.position();
                }
View Full Code Here

TOP

Related Classes of zmq.Msg

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.