Package org.zper.base

Examples of org.zper.base.ZLog


    public void testOffset() throws Exception
    {
        Context ctx = ZMQ.context(1);
        Socket sock = ctx.socket(ZMQ.DEALER);

        ZLog zlog = ZLogManager.instance().get(topic);
        SegmentInfo[] infos = zlog.segments();

        sock.setIdentity(ZPUtils.genTopicIdentity(topic, 0));
        sock.setLinger(100);

        sock.connect("tcp://127.0.0.1:6556");
View Full Code Here


    public void testFetch() throws Exception
    {
        Context ctx = ZMQ.context(1);
        Socket sock = ctx.socket(ZMQ.DEALER);

        ZLog zlog = ZLogManager.instance().get(topic);
        SegmentInfo[] infos = zlog.segments();
        SegmentInfo last = infos[infos.length - 1];

        sock.setIdentity(ZPUtils.genTopicIdentity(topic, 0));

        sock.connect("tcp://127.0.0.1:6556");
View Full Code Here

        int state = START;

        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()
View Full Code Here

        int flag = 0;
        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;
View Full Code Here

    public void testSend() throws Exception
    {
        Context ctx = ZMQ.context(1);
        Socket sock = ctx.socket(ZMQ.DEALER);

        ZLog zlog = ZLogManager.instance().get(topic);
        long offset = zlog.offset();
        String data = "hello";

        System.out.println("previous offset " + zlog.path().getAbsolutePath() + ":" + offset);

        sock.setIdentity(ZPUtils.genTopicIdentity(topic, 0));
        sock.setLinger(100);

        sock.connect("tcp://127.0.0.1:5557");


        boolean ret = sock.send(data);
        assertTrue(ret);

        // wait until flush
        Thread.sleep(1000);
        zlog.flush();

        assertEquals(zlog.offset(), offset + data.length() + 2);

        sock.close();
        ctx.term();
    }
View Full Code Here

    public void testSendPush() throws Exception
    {
        Context ctx = ZMQ.context(1);
        Socket sock = ctx.socket(ZMQ.PUSH);

        ZLog zlog = ZLogManager.instance().get(topic);
        long offset = zlog.offset();
        String data = "hello";

        System.out.println("previous offset " + zlog.path().getAbsolutePath() + ":" + offset);

        sock.setIdentity(ZPUtils.genTopicIdentity(topic, 0));
        sock.setLinger(100);

        sock.connect("tcp://127.0.0.1:5557");


        boolean ret = sock.send(data);
        assertTrue(ret);

        // wait until flush
        Thread.sleep(1000);
        zlog.flush();

        assertEquals(zlog.offset(), offset + data.length() + 2);

        sock.close();
        ctx.term();
    }
View Full Code Here

    private static void countMsg(String[] argv) throws Exception
    {
        ZLogConfig zc = ZLogManager.instance().config();
        zc.set("base_dir", argv[1]);

        ZLog log = ZLogManager.instance().get(argv[2]);
        SegmentInfo[] segments = log.segments();
        long total = 0;

        for (SegmentInfo seg : segments) {
            int count = log.countMsg(seg.start(), seg.offset() - seg.start());
            System.out.println(String.format("%020d : %d", seg.start(), count));
            total += count;
        }
        System.out.println("Total : " + total);
    }
View Full Code Here

TOP

Related Classes of org.zper.base.ZLog

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.