com.github.javaclub.toolbox.utils.AlarmUtils Maven / Gradle / Ivy
/*
* @(#)AlarmUtils.java 2022-6-18
*
* Copyright (c) 2022. All Rights Reserved.
*
*/
package com.github.javaclub.toolbox.utils;
import java.util.Date;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.javaclub.toolbox.ToolBox.Environments;
import com.github.javaclub.toolbox.ToolBox.Objects;
import com.github.javaclub.toolbox.ToolBox.Strings;
import com.github.javaclub.toolbox.conf.ConfUtils;
import com.github.javaclub.toolbox.thread.ExecutorServiceInstance;
/**
* AlarmUtils
*
* @author Gerald Chen
* @version $Id: AlarmUtils.java 2022-6-18 18:00:42 Exp $
*/
public class AlarmUtils {
private static final Logger log = LoggerFactory.getLogger(AlarmUtils.class);
private static AtomicBoolean initFlag = new AtomicBoolean(false);
private AlarmUtils() {
}
public static void sendDingTalk(String title, Date time, Map params) {
String invokeClass = null;
if (Environments.support(ConfUtils.MONITOR_DINGTALK_CLASS)) {
invokeClass = ConfUtils.MONITOR_DINGTALK_CLASS;
} else if (Environments.support(ConfUtils.CONFIGCNTER_DINGTALK_CLASS)) {
invokeClass = ConfUtils.CONFIGCNTER_DINGTALK_CLASS;
}
if (Strings.isBlank(invokeClass)) {
log.warn("No DingTalk Message sender Utils in classpath.");
return;
}
if (initFlag.compareAndSet(false, true)) {
if (log.isInfoEnabled()) {
log.info("Using [{}] sendDingTalk", invokeClass);
}
}
final String target = invokeClass;
ExecutorServiceInstance.get().execute(() -> {
Objects.invoke(target, "sendMarkdown",
new Class[] { String.class, Date.class, Map.class},
new Object[] { title, time, params}
);
});
}
}