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

com.alibaba.dts.client.executor.grid.flowcontrol.FlowControlParameterWatcher Maven / Gradle / Ivy

package com.alibaba.dts.client.executor.grid.flowcontrol;

import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

import com.alibaba.dts.client.executor.job.context.ClientContextImpl;
import com.alibaba.dts.common.exception.AccessException;
import com.alibaba.dts.common.logger.SchedulerXLoggerFactory;
import com.alibaba.dts.common.logger.innerlog.Logger;
import com.alibaba.dts.common.util.NamedThreadFactory;

/**
 * @author Ronan Zhan
 * @date 2016/12/27.
 */
public class FlowControlParameterWatcher {

    private static final Logger logger = SchedulerXLoggerFactory.getLogger(FlowControlParameterWatcher.class);

    public static volatile AtomicLong dbTasksCount = new AtomicLong(0);
    public static AtomicInteger dbTasksMemoryRate = new AtomicInteger(0);

    private ClientContextImpl clientContext;

    private ScheduledThreadPoolExecutor watchThreadPool = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("SchedulerX-Flow-Control-Parameter-Watch-Thread-"));

    public FlowControlParameterWatcher(ClientContextImpl clientContext) {
        this.clientContext = clientContext;
    }

    public void watchH2Count() {
        watchThreadPool.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                try {
                    dbTasksCount.set(clientContext.getStore().getTaskSnapshotDao().queryTotalCount());
                } catch (AccessException e) {
                    logger.error("watchH2Count error", e);
                }
            }
        }, 10, 5, TimeUnit.SECONDS);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy