Package com.taobao.metamorphosis.consumer

Examples of com.taobao.metamorphosis.consumer.ConsumerMessageFilter



    @Test
    public void testGetFilter() {
        this.consumerFilterManager.setFilterClassLoader(Thread.currentThread().getContextClassLoader());
        ConsumerMessageFilter filter = this.consumerFilterManager.findFilter("test", "test-group2");
        assertNotNull(filter);
        assertSame(filter, this.consumerFilterManager.findFilter("test", "test-group2"));
        assertTrue(filter.accept(null, null));
        assertTrue(filter.accept(null, null));
    }
View Full Code Here


            }

        });
        this.consumerFilterManager = this.mocksControl.createMock(ConsumerFilterManager.class);
        EasyMock.expect(this.consumerFilterManager.findFilter(this.topic, this.group)).andReturn(
            new ConsumerMessageFilter() {

                @Override
                public boolean accept(String group, Message message) {
                    return false;
                }
View Full Code Here

        if (task == null) {
            task = new FutureTask<ConsumerMessageFilter>(new Callable<ConsumerMessageFilter>() {

                @Override
                public ConsumerMessageFilter call() throws Exception {
                    ConsumerMessageFilter intanceFilter = ConsumerFilterManager.this.intanceFilter(className);
                    if (intanceFilter != null) {
                        log.warn("Created filter '" + className + "' for group:" + group + " and topic:" + topic);
                    }
                    return intanceFilter;
                }
View Full Code Here

            @Override
            public Executor getExecutor() {
                return null;
            }
        });
        EasyMock.expect(this.consumer.getMessageFilter(topic)).andReturn(new ConsumerMessageFilter() {

            @Override
            public boolean accept(String group, Message message) {
                return true;
            }
View Full Code Here

            public Executor getExecutor() {
                return null;
            }
        });
        // Don't accept all messages.
        EasyMock.expect(this.consumer.getMessageFilter(topic)).andReturn(new ConsumerMessageFilter() {

            @Override
            public boolean accept(String group, Message message) {
                // always return false.
                return false;
View Full Code Here

            public Executor getExecutor() {
                return null;
            }
        });
        // Don't accept all messages.
        EasyMock.expect(this.consumer.getMessageFilter(topic)).andReturn(new ConsumerMessageFilter() {

            @Override
            public boolean accept(String group, Message message) {
                throw new RuntimeException();
            }
View Full Code Here

        }
        try {
            final MessageSet set =
                    store.slice(request.getOffset(),
                        Math.min(this.metaConfig.getMaxTransferSize(), request.getMaxSize()));
            ConsumerMessageFilter filter = this.consumerFilterManager.findFilter(topic, group);
            if (set != null) {
                if (zeroCopy && filter == null) {
                    set.write(request, ctx);
                    return null;
                }
                else {
                    // refer to the code of line 440 in MessageStore
                    // create two copies of byte array including the byteBuffer
                    // and new bytes
                    // this may not a good use case of Buffer
                    final ByteBuffer byteBuffer =
                            ByteBuffer.allocate(Math.min(this.metaConfig.getMaxTransferSize(), request.getMaxSize()));
                    set.read(byteBuffer);
                    byte[] bytes = this.getBytesFromBuffer(byteBuffer);
                    // If filter is not null,we filter the messages by it.
                    if (filter != null) {
                        MessageIterator it = new MessageIterator(topic, bytes);
                        // reuse the buffer.
                        byteBuffer.clear();
                        while (it.hasNext()) {
                            Message msg = it.next();
                            try {
                                if (filter.accept(group, msg)) {
                                    ByteBuffer msgBuf = it.getCurrentMsgBuf();
                                    // Append current message buffer to result
                                    // buffer.
                                    byteBuffer.put(msgBuf);
                                }
                            }
                            catch (Exception e) {
                                log.error("Filter message for consumer failed,topic=" + topic + ",group=" + group
                                    + ",filterClass=" + filter.getClass().getCanonicalName(), e);
                            }
                        }
                        // re-new the byte array.
                        bytes = this.getBytesFromBuffer(byteBuffer);
                        // All these messages are not acceptable,move forward
View Full Code Here

        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
                    .getConsumerConfig().getGroup());
            }
            catch (final MetaClientException e) {
View Full Code Here

TOP

Related Classes of com.taobao.metamorphosis.consumer.ConsumerMessageFilter

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.