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

com.github.dennisit.vplus.data.metric.spring.JMetricContextFactory Maven / Gradle / Ivy

/*--------------------------------------------------------------------------
 *  Copyright (c) 2010-2020, Elon.su All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the elon developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: Elon.su, you can also mail [email protected]
 *--------------------------------------------------------------------------
*/
package com.github.dennisit.vplus.data.metric.spring;

import com.github.dennisit.vplus.data.metric.JMetricCollector;
import com.github.dennisit.vplus.data.metric.JMetricContext;
import com.github.dennisit.vplus.data.metric.JMetricPipeline;
import com.github.dennisit.vplus.data.metric.collector.DefaultCollector;
import com.github.dennisit.vplus.data.metric.config.JMetricConfig;
import com.github.dennisit.vplus.data.metric.pipeline.LoggerPipeline;
import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.lang.Nullable;

import java.util.List;


/**
 * Created by Elon.su on 17/11/3.
 */
public class JMetricContextFactory implements FactoryBean {

    /**
     * 采集器
     */
    private List collectors;

    /**
     * 管道流
     */
    private List pipelines;

    /**
     * 配置设定
     */
    private JMetricConfig jMetricConfig;


    @Nullable
    @Override
    public JMetricContext getObject() throws Exception {
        if(null == jMetricConfig){
            // 默认 实例化后直接启动上报任务, 没分钟上报一次
            jMetricConfig = JMetricConfig.DEFAULT();
        }
        if(CollectionUtils.isEmpty(collectors)){
            // 默认 启动应用采集器调用耗时采集器
            collectors = Lists.newArrayList(new DefaultCollector());
        }
        if(CollectionUtils.isEmpty(pipelines)){
            // 默认 日志管道流推送输出
            pipelines = Lists.newArrayList(new LoggerPipeline());
        }
        return new JMetricContext(jMetricConfig, collectors, pipelines);
    }


    @Nullable
    @Override
    public Class getObjectType() {
        return JMetricContext.class;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }

    public void setCollectors(List collectors) {
        this.collectors = collectors;
    }

    public void setPipelines(List pipelines) {
        this.pipelines = pipelines;
    }

    public void setjMetricConfig(JMetricConfig jMetricConfig) {
        this.jMetricConfig = jMetricConfig;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy