Package zmq

Examples of zmq.Msg


        //  Earliest offset
        sock.sendMore("OFFSET");
        sock.send(ByteBuffer.allocate(8).putLong(-2).array());

        Msg status = sock.base().recv(0);
        assertTrue(status.hasMore());
        assertEquals(100, status.data()[0]);

        Msg oldest = sock.base().recv(0);
        assertFalse(oldest.hasMore());
        assertEquals(infos[0].start(), oldest.buf().getLong());

        //  Latest offset
        sock.sendMore("OFFSET");
        sock.send(ByteBuffer.allocate(8).putLong(-1).array());

        status = sock.base().recv(0);
        assertTrue(status.hasMore());
        assertEquals(100, status.data()[0]);

        Msg latest = sock.base().recv(0);
        assertTrue(latest.hasMore());
        assertEquals(infos[infos.length - 1].start(), latest.buf().getLong());

        Msg last = sock.base().recv(0);
        assertFalse(last.hasMore());
        assertEquals(infos[infos.length - 1].offset(), last.buf().getLong());

        //  Modified before
        sock.sendMore("OFFSET");
        sock.send(ByteBuffer.allocate(8).putLong(System.currentTimeMillis()).array());

        status = sock.base().recv(0);
        assertTrue(status.hasMore());
        assertEquals(100, status.data()[0]);

        List<Long> offsetList = new ArrayList<Long>();

        while (true) {
            Msg msg = sock.base().recv(0);
            offsetList.add(msg.buf().getLong());
            if (!msg.hasMore())
                break;
        }
        assertEquals(infos.length + 1, offsetList.size());
        for (int i = 0; i < infos.length; i++) {
            assertEquals(infos[i].start(), (long) offsetList.get(i));
View Full Code Here


        //  Latest offset
        sock.sendMore("FETCH");
        sock.sendMore(ByteBuffer.allocate(8).putLong(last.start()).array());
        sock.send(ByteBuffer.allocate(8).putLong(Integer.MAX_VALUE).array());

        Msg status = sock.base().recv(0);
        assertEquals(100, status.data()[0]);

        Msg result = sock.base().recv(0);
        assertEquals((int) (last.offset() - last.start()), result.size());

        Iterator<Msg> it = new MsgIterator(result.buf(), false);
        while (it.hasNext()) {
            it.next();
        }

        sock.close();
View Full Code Here

        String topic = null;
        boolean more = false;
        boolean stop = false;
        ZLog zlog = null;
        Msg msg;
        String command = "";
        List<Msg> args = new ArrayList<Msg>();

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

            msg = worker.base().recv(0);
            if (msg == null)
                break;
            more = msg.hasMore();

            switch (state) {
            case START:
                byte[] id = msg.data();
                if (id == null)
                    break;
                topic = ZPUtils.getTopic(id);
                state = TOPIC;
                zlog = logMgr.get(topic);

                worker.sendMore(msg.data());
                args.clear();
                break;

            case TOPIC:

                if (msg.size() == 0 && more) { // bottom
                    state = COMMAND;
                    worker.sendMore(msg.data());
                    break;
                }

            case COMMAND:

                command = new String(msg.data());
                state = ARGUMENT;
                break;

            case ARGUMENT:
View Full Code Here

        int count = 0;
        String topic = null;
        boolean more = false;
        boolean stop = false;
        ZLog zlog = null;
        Msg msg;
        ZMsg response = null;

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

            msg = worker.base().recv(0);
            if (msg == null)
                break;
            more = msg.hasMore();

            switch (state) {
            case START:
                byte[] id = msg.data();
                if (id == null)
                    break;
                flag = id[1];
                topic = ZPUtils.getTopic(id);
                if (topic == null) {
                    break;
                }
                state = TOPIC;
                zlog = logMgr.get(topic);

                if (flag > 0) {
                    response = new ZMsg();
                    response.add(id);
                }
                break;

            case TOPIC:

                if (msg.size() == 0 && more) { // bottom
                    state = COUNT;

                    if (flag > 0)
                        response.add(msg.data());
                    break;
                }

            case COUNT:

                if (decoder) {
                    count = ByteBuffer.wrap(msg.data()).getInt();
                    state = MESSAGE;
                    break;
                }
                else {
                    state = SINGLE;
                }

            case SINGLE:

                if (store(zlog, msg)) {
                    if (flag > 0 && zlog.flushed()) {
                        response.add(new ZFrame(msg.buf().array()));
                        response.send(worker);
                    }
                } else
                    stop = true;
                if (!more)
                    state = START;
                break;

            case MESSAGE:

                if (store(zlog, count, msg)) {
                    if (flag > 0 && zlog.flushed()) {
                        response.add(getLastFrame(msg.buf().duplicate()));
                        response.send(worker);
                    }
                } else
                    stop = true;
                if (!more)
View Full Code Here

    @Override
    public Msg next()
    {
        int limit = buf.limit();
        buf.limit(buf.position() + length);
        Msg msg = new Msg(buf.slice());
        if ((flag & Msg.MORE) > 0)
            msg.setFlags(Msg.MORE);

        buf.limit(limit);
        buf.position(buf.position() + length);
        valid = buf.position();
        return msg;
View Full Code Here

        ZLog log = m.get("new_topic");

        assertThat(log.start(), is(0L));
        assertThat(log.offset(), is(0L));

        long pos = log.append(new Msg("hello".getBytes()));
        assertThat(pos, is(7L));
        log.flush();

        assertThat(log.offset(), is(7L));
        log.close();
View Full Code Here

        ZLog log = m.get("new_topic");

        assertThat(log.start(), is(0L));
        assertThat(log.offset(), is(0L));

        log.append(new Msg("12345".getBytes()));
        assertThat(log.count(), is(1));
        long pos = log.append(new Msg("1234567890".getBytes()));
        assertThat(log.count(), is(2));
        assertThat(pos, is(19L));
        assertThat(log.offset(), is(19L));
        log.close();
    }
View Full Code Here

        m.shutdown();

        ZLog log = m.get("new_topic");
        assertThat(log.offset(), is(20L));

        log.append(new Msg("hello".getBytes()));
        assertThat(log.offset(), is(27L));

    }
View Full Code Here

    {
        reset(13L, 10000L);
        ZLogManager m = ZLogManager.instance();
        ZLog log = m.get("new_topic");

        log.append(new Msg("12345678".getBytes()));
        log.append(new Msg("12345".getBytes()));
        log.append(new Msg("123".getBytes()));
        log.flush();

        long[] offsets = log.offsets();
        assertThat(offsets[0], is(0L));
        assertThat(offsets[1], is(10L));
View Full Code Here

    {
        reset(13L, 10000L);
        ZLogManager m = ZLogManager.instance();
        ZLog log = m.get("new_topic");

        log.append(new Msg("12345678".getBytes()));
        log.append(new Msg("12345".getBytes()));
        log.append(new Msg("123".getBytes()));
        log.flush();

        FileChannel ch = log.open(10L);
        assertThat(log.offset(), is(22L));
        assertThat(ch.size(), is(12L));
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.