package com.jay.monitor.data.server.process;

import com.alipay.remoting.BizContext;
import com.alipay.remoting.rpc.protocol.SyncMultiInterestUserProcessor;
import com.jay.monitor.data.core.enums.MonitorDataConstants;
import com.jay.monitor.data.core.model.serializable.base.ApplicationData;
import com.jay.monitor.data.server.utils.DataUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 抽象用户执行线程
 *
 * @author ： liukx
 * @time ： 2020/8/27 - 10:41
 */
public abstract class AbstractUserProcess<T> extends SyncMultiInterestUserProcessor<T> {

    @Override
    public Object handleRequest(BizContext bizCtx, T request) throws Exception {

        if (request instanceof ApplicationData) {

            ApplicationData applicationData = (ApplicationData) request;
            String application = DataUtils.getStringValue(applicationData.getApplicationName(), bizCtx.getInvokeContext().get(MonitorDataConstants.INVOKE_CLIENT_NAME));
            String ip = DataUtils.getStringValue(applicationData.getIp(), bizCtx.getInvokeContext().get(MonitorDataConstants.INVOKE_CLIENT_IP));

            applicationData.setApplicationName(application);
            applicationData.setIp(ip);

        }

        return handleRequest0(bizCtx, request);
    }

    public abstract Object handleRequest0(BizContext bizCtx, T request) throws Exception;

    protected List<String> getNamesList(Class... clazz) {
        List<String> array = new ArrayList<>();
        for (Class aClass : clazz) {
            array.add(aClass.getName());
        }
        return array;
    }
    /**
     * 监控:
     * 1. 耗时
     *
     * 统计:
     * 1. 报告
     *
     * 告警:
     * 1. 钉钉
     */
}
