ThisApplication.java 3.4 KB
Newer Older
R
roo00 已提交
1 2
package com.x.message.assemble.communicate;

R
roo00 已提交
3 4
import org.apache.commons.lang3.BooleanUtils;

R
roo00 已提交
5
import com.x.base.core.project.Context;
Z
zhourui 已提交
6
import com.x.base.core.project.cache.CacheManager;
R
roo00 已提交
7
import com.x.base.core.project.config.Config;
R
roo00 已提交
8
import com.x.base.core.project.logger.LoggerFactory;
Z
zhourui 已提交
9
import com.x.base.core.project.message.MessageConnector;
R
roo00 已提交
10
import com.x.message.assemble.communicate.schedule.Clean;
hlwwx's avatar
hlwwx 已提交
11
import com.x.message.assemble.communicate.schedule.TriggerMq;
R
roo00 已提交
12 13 14

public class ThisApplication {

Z
zhourui 已提交
15 16 17 18
	private ThisApplication() {
		// nothing
	}

R
roo00 已提交
19 20
	protected static Context context;

Z
zhourui 已提交
21
	public static final WsConsumeQueue wsConsumeQueue = new WsConsumeQueue();
R
roo00 已提交
22

Z
zhourui 已提交
23
	public static final PmsConsumeQueue pmsConsumeQueue = new PmsConsumeQueue();
R
roo00 已提交
24

Z
zhourui 已提交
25
	public static final CalendarConsumeQueue calendarConsumeQueue = new CalendarConsumeQueue();
R
roo00 已提交
26

Z
zhourui 已提交
27
	public static final QiyeweixinConsumeQueue qiyeweixinConsumeQueue = new QiyeweixinConsumeQueue();
R
roo00 已提交
28

Z
zhourui 已提交
29
	public static final ZhengwuDingdingConsumeQueue zhengwuDingdingConsumeQueue = new ZhengwuDingdingConsumeQueue();
R
roo00 已提交
30

Z
zhourui 已提交
31
	public static final DingdingConsumeQueue dingdingConsumeQueue = new DingdingConsumeQueue();
R
roo00 已提交
32

Z
zhourui 已提交
33
	public static final WeLinkConsumeQueue weLinkConsumeQueue = new WeLinkConsumeQueue();
F
fancy 已提交
34

Z
zhourui 已提交
35
	public static final PmsInnerConsumeQueue pmsInnerConsumeQueue = new PmsInnerConsumeQueue();
Z
zhourui 已提交
36

Z
zhourui 已提交
37
	public static final MQConsumeQueue mqConsumeQueue = new MQConsumeQueue();
R
update  
roo00 已提交
38

R
roo00 已提交
39 40 41 42 43 44
	public static Context context() {
		return context;
	}

	public static void init() {
		try {
Z
zhourui 已提交
45
			CacheManager.init(context.clazz().getSimpleName());
R
roo00 已提交
46
			LoggerFactory.setLevel(Config.logLevel().x_message_assemble_communicate());
Z
zhourui 已提交
47 48 49

			MessageConnector.start(context());
			startQueue();
R
update  
roo00 已提交
50 51 52
			if (BooleanUtils.isTrue(Config.communicate().clean().getEnable())) {
				context().schedule(Clean.class, Config.communicate().clean().getCron());
			}
hlwwx's avatar
hlwwx 已提交
53
			if (BooleanUtils.isTrue(Config.communicate().cronMq().getEnable())) {
Z
zhourui 已提交
54
				context().schedule(TriggerMq.class, Config.communicate().cronMq().getCron());
hlwwx's avatar
hlwwx 已提交
55
			}
R
roo00 已提交
56 57 58 59 60
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

Z
zhourui 已提交
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
	private static void startQueue() throws Exception {
		if (BooleanUtils.isTrue(Config.communicate().wsEnable())) {
			context().startQueue(wsConsumeQueue);
		}
		if (BooleanUtils.isTrue(Config.communicate().pmsEnable())) {
			context().startQueue(pmsConsumeQueue);
		}
		if (BooleanUtils.isTrue(Config.communicate().calendarEnable())) {
			context().startQueue(calendarConsumeQueue);
		}

		if (BooleanUtils.isTrue(Config.qiyeweixin().getEnable())
				&& BooleanUtils.isTrue(Config.qiyeweixin().getMessageEnable())) {
			context().startQueue(qiyeweixinConsumeQueue);
		}
		if (BooleanUtils.isTrue(Config.zhengwuDingding().getEnable())
				&& BooleanUtils.isTrue(Config.zhengwuDingding().getMessageEnable())) {
			context().startQueue(zhengwuDingdingConsumeQueue);
		}
		if (Config.dingding().getEnable() && Config.dingding().getMessageEnable()) {
			context().startQueue(dingdingConsumeQueue);
		}
		if (BooleanUtils.isTrue(Config.pushConfig().getEnable())) {
			context().startQueue(pmsInnerConsumeQueue);
		}
		if (Config.weLink().getEnable() && Config.weLink().getMessageEnable()) {
			context().startQueue(weLinkConsumeQueue);
		}

		if (BooleanUtils.isTrue(Config.mq().getEnable())) {
			context().startQueue(mqConsumeQueue);
		}
	}

R
roo00 已提交
95 96
	public static void destroy() {
		try {
Z
zhourui 已提交
97
			CacheManager.shutdown();
NoSubject's avatar
NoSubject 已提交
98
			MessageConnector.stop();
R
roo00 已提交
99 100 101 102 103
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}