@Override
    public void dispatch(DispatchRequest request) {
        if (!this.brokerConfig.isEnableCalcFilterBitMap()) {
            return;
        }

        try {

            Collection<ConsumerFilterData> filterDatas = consumerFilterManager.get(request.getTopic());

            if (filterDatas == null || filterDatas.isEmpty()) {
                return;
            }

            Iterator<ConsumerFilterData> iterator = filterDatas.iterator();
            BitsArray filterBitMap = BitsArray.create(
                this.consumerFilterManager.getBloomFilter().getM()
            );

            long startTime = System.currentTimeMillis();
            while (iterator.hasNext()) {
                ConsumerFilterData filterData = iterator.next();

                if (filterData.getCompiledExpression() == null) {
                    log.error("[BUG] Consumer in filter manager has no compiled expression! {}", filterData);
                    continue;
                }

                if (filterData.getBloomFilterData() == null) {
                    log.error("[BUG] Consumer in filter manager has no bloom data! {}", filterData);
                    continue;
                }

                Object ret = null;
                try {
                    MessageEvaluationContext context = new MessageEvaluationContext(request.getPropertiesMap());

                    ret = filterData.getCompiledExpression().evaluate(context);
                } catch (Throwable e) {
                    log.error("Calc filter bit map error!commitLogOffset={}, consumer={}, {}", request.getCommitLogOffset(), filterData, e);
                }

                log.debug("Result of Calc bit map:ret={}, data={}, props={}, offset={}", ret, filterData, request.getPropertiesMap(), request.getCommitLogOffset());

                // eval true
                if (ret != null && ret instanceof Boolean && (Boolean) ret) {
                    consumerFilterManager.getBloomFilter().hashTo(
                        filterData.getBloomFilterData(),
                        filterBitMap
                    );
                }
            }

            request.setBitMap(filterBitMap.bytes());

            long elapsedTime = UtilAll.computeElapsedTimeMilliseconds(startTime);
            // 1ms
            if (elapsedTime >= 1) {
                log.warn("Spend {} ms to calc bit map, consumerNum={}, topic={}", elapsedTime, filterDatas.size(), request.getTopic());
            }
        } catch (Throwable e) {
            log.error("Calc bit map error! topic={}, offset={}, queueId={}, {}", request.getTopic(), request.getCommitLogOffset(), request.getQueueId(), e);
        }
    }
@Test
    public void testDispatch_filterDataIllegal() {
        BrokerConfig brokerConfig = new BrokerConfig();
        brokerConfig.setEnableCalcFilterBitMap(true);

        ConsumerFilterManager filterManager = new ConsumerFilterManager();

        filterManager.register("topic0", "CID_0", "a is not null and a >= 5",
            ExpressionType.SQL92, System.currentTimeMillis());

        filterManager.register("topic0", "CID_1", "a is not null and a >= 15",
            ExpressionType.SQL92, System.currentTimeMillis());

        ConsumerFilterData nullExpression = filterManager.get("topic0", "CID_0");
        nullExpression.setExpression(null);
        nullExpression.setCompiledExpression(null);
        ConsumerFilterData nullBloomData = filterManager.get("topic0", "CID_1");
        nullBloomData.setBloomFilterData(null);

        CommitLogDispatcherCalcBitMap calcBitMap = new CommitLogDispatcherCalcBitMap(brokerConfig,
            filterManager);

        for (int i = 0; i < 1; i++) {
            Map<String, String> properties = new HashMap<>(4);
            properties.put("a", String.valueOf(i * 10 + 5));

            String topic = "topic" + i;

            DispatchRequest dispatchRequest = new DispatchRequest(
                topic,
                0,
                i * 100 + 123,
                100,
                (long) ("tags" + i).hashCode(),
                System.currentTimeMillis(),
                i,
                null,
                UUID.randomUUID().toString(),
                0,
                0,
                properties
            );

            calcBitMap.dispatch(dispatchRequest);

            assertThat(dispatchRequest.getBitMap()).isNotNull();

            BitsArray bitsArray = BitsArray.create(dispatchRequest.getBitMap(),
                filterManager.getBloomFilter().getM());

            for (int j = 0; j < bitsArray.bitLength(); j++) {
                assertThat(bitsArray.getBit(j)).isFalse();
            }
        }
    }