Examples of MessageIterator


Examples of com.taobao.metamorphosis.consumer.MessageIterator

        buf.putInt(5);// msg length
        buf.putInt(CheckSum.crc32("hello".getBytes())); // checksum

        buf.position(MessageUtils.HEADER_LEN);
        buf.put("world".getBytes());
        this.it = new MessageIterator("test", buf.array());
        assertTrue(this.it.hasNext());
        this.it.next();

    }
View Full Code Here

Examples of com.taobao.metamorphosis.consumer.MessageIterator

        buf.putLong(9999); // id
        buf.putInt(0); // flag

        buf.position(MessageUtils.HEADER_LEN);
        buf.put("hello".getBytes());
        this.it = new MessageIterator("test", buf.array());
        assertTrue(this.it.hasNext());
        final Message msg = this.it.next();
        assertNotNull(msg);
        assertEquals(9999L, msg.getId());
        assertEquals("test", msg.getTopic());
View Full Code Here

Examples of com.taobao.metamorphosis.consumer.MessageIterator

        buf.putLong(9999); // id
        buf.putInt(1); // flag
        buf.position(MessageUtils.HEADER_LEN);
        buf.put(dataBuf);

        this.it = new MessageIterator("test", buf.array());
        assertTrue(this.it.hasNext());
        final Message msg = this.it.next();
        assertNotNull(msg);
        assertEquals(9999L, msg.getId());
        assertEquals("test", msg.getTopic());
View Full Code Here

Examples of com.taobao.metamorphosis.consumer.MessageIterator

                // ��ȡ���������ز����ʱ������maxSize
                if (data.length < fetchRequest.getMaxSize() / 2) {
                    fetchRequest.decreaseMaxSize();
                }
                success = true;
                return new MessageIterator(fetchRequest.getTopic(), data);
            }
            else {
                final BooleanCommand booleanCmd = (BooleanCommand) response;
                switch (booleanCmd.getCode()) {
                case HttpStatus.NotFound:
View Full Code Here

Examples of com.taobao.metamorphosis.consumer.MessageIterator

     * </pre>
     */
    public ReveiceResult get(String topic, Partition partition) {
        long offset = this.getOffset(partition);
        ReveiceResult result = new ReveiceResult(topic, partition, offset, this.serverUrl);
        MessageIterator it = null;
        try {
            int i = 0;
            while ((it = this.consumer.get(topic, partition, offset, 1024 * 1024)) != null) {
                // ��ֹ��һ�δ�0-offset����̫�������.
                if (i++ >= 3) {
                    break;
                }
                while (it.hasNext()) {
                    final Message msg = it.next();
                    result.addMessage(msg);
                    // System.out.println("Receive message " + new
                    // String(msg.getData()));
                }
                offset += it.getOffset();
                this.setOffset(partition, offset);
            }
        }
        catch (InvalidMessageException e) {
            result.setException(e);
View Full Code Here

Examples of com.taobao.metamorphosis.consumer.MessageIterator

        // ��ǰ�����ļ�
        while (startOffset < maxOffset && (msgSet = (FileMessageSet) store.slice(startOffset, MAX_SIZE)) != null) {
            final int sizeInBytes = (int) msgSet.getSizeInBytes();
            final ByteBuffer buffer = ByteBuffer.allocate(sizeInBytes);
            msgSet.read(buffer);
            final MessageIterator it = new MessageIterator(topic, buffer.array());
            final List<DecodeMessage> msgList = new ArrayList<DecodeMessage>();
            // ������Ϣ
            long msgOffset = 0;
            while (it.hasNext()) {
                try {
                    final Message msg = it.next();
                    msgList.add(new DecodeMessage(msg.getId(), startOffset + it.getOffset()));
                    msgOffset = it.getOffset();
                }
                catch (final InvalidMessageException e) {
                    // �����ϲ����������������Ԥ����һ���Ǵ�ӡ��־
                    log.error("Message was corrupted,partition=" + store.getDescription() + ",offset=" + msgOffset);
                }
            }
            // recover��һ����Ϣ
            this.recoverOffset(offsetInfos, segRecoverOffsetInfos, msgList);
            // ��ǰ�ƶ�startOffset
            startOffset = startOffset + it.getOffset();
        }

        // �Ƴ���segment�ܹ���ƫ��offset
        for (final OffsetInfo info : segRecoverOffsetInfos) {
            offsetInfos.remove(info.oldMsgId);
View Full Code Here

Examples of com.taobao.metamorphosis.consumer.MessageIterator

        }


        void processRequest(final FetchRequest request) {
            try {
                final MessageIterator iterator = SimpleFetchManager.this.consumer.fetch(request, -1, null);
                final MessageListener listener =
                        SimpleFetchManager.this.consumer.getMessageListener(request.getTopic());
                final ConsumerMessageFilter filter =
                        SimpleFetchManager.this.consumer.getMessageFilter(request.getTopic());
                this.notifyListener(request, iterator, listener, filter, SimpleFetchManager.this.consumer
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.