All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.rocketmq.test.clientinterface.MQCollector Maven / Gradle / Ivy

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.apache.rocketmq.test.clientinterface;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.rocketmq.test.util.RandomUtil;
import org.apache.rocketmq.test.util.data.collect.DataCollector;
import org.apache.rocketmq.test.util.data.collect.DataCollectorManager;

public abstract class MQCollector {
    protected DataCollector msgBodys = null;
    protected DataCollector originMsgs = null;
    protected DataCollector errorMsgs = null;
    protected Map originMsgIndex = null;
    protected Collection msgBodysCopy = null;

    protected DataCollector msgRTs = null;

    public MQCollector() {
        msgBodys = DataCollectorManager.getInstance()
            .fetchListDataCollector(RandomUtil.getStringByUUID());
        originMsgs = DataCollectorManager.getInstance()
            .fetchListDataCollector(RandomUtil.getStringByUUID());
        errorMsgs = DataCollectorManager.getInstance()
            .fetchListDataCollector(RandomUtil.getStringByUUID());
        originMsgIndex = new ConcurrentHashMap();
        msgRTs = DataCollectorManager.getInstance()
            .fetchListDataCollector(RandomUtil.getStringByUUID());
    }

    public MQCollector(String originMsgCollector, String msgBodyCollector) {
        originMsgs = DataCollectorManager.getInstance().fetchDataCollector(originMsgCollector);
        msgBodys = DataCollectorManager.getInstance().fetchDataCollector(msgBodyCollector);
    }

    public Collection getAllMsgBody() {
        return msgBodys.getAllData();
    }

    public Collection getAllOriginMsg() {
        return originMsgs.getAllData();
    }

    public Object getFirstMsg() {
        return ((List) originMsgs.getAllData()).get(0);
    }

    public Collection getAllUndupMsgBody() {
        return msgBodys.getAllDataWithoutDuplicate();
    }

    public Collection getAllUndupOriginMsg() {
        return originMsgs.getAllData();
    }

    public Collection getSendErrorMsg() {
        return errorMsgs.getAllData();
    }

    public Collection getMsgRTs() {
        return msgRTs.getAllData();
    }

    public Map getOriginMsgIndex() {
        return originMsgIndex;
    }

    public Collection getMsgBodysCopy() {
        msgBodysCopy = new ArrayList();
        msgBodysCopy.addAll(msgBodys.getAllData());
        return msgBodysCopy;
    }

    public void clearMsg() {
        if (msgBodys != null) {
            msgBodys.resetData();
        }
        if (originMsgs != null) {
            originMsgs.resetData();
        }
        if (originMsgs != null) {
            errorMsgs.resetData();
        }
        if (originMsgIndex != null) {
            originMsgIndex.clear();
        }
        if (msgRTs != null) {
            msgRTs.resetData();
        }
    }

    public void lockCollectors() {
        msgBodys.lockIncrement();
        originMsgs.lockIncrement();
        errorMsgs.lockIncrement();
        msgRTs.lockIncrement();

    }
}