From 1a2b07f01ba4616fd9e894dddf474b56d020158c Mon Sep 17 00:00:00 2001 From: zhubaomin <zhubaomin> Date: 星期一, 07 四月 2025 15:18:51 +0800 Subject: [PATCH] 整理版本 --- pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/msCenter/MsCenterManager.java | 138 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 138 insertions(+), 0 deletions(-) diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/msCenter/MsCenterManager.java b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/msCenter/MsCenterManager.java new file mode 100644 index 0000000..659e45f --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/msCenter/MsCenterManager.java @@ -0,0 +1,138 @@ +package com.dy.rtuMw.server.msCenter; + +import com.alibaba.fastjson2.JSONObject; +import com.dy.common.queue.Queue; +import com.dy.common.springUtil.SpringContextUtil; +import com.dy.common.threadPool.ThreadPool; +import com.dy.common.threadPool.TreadPoolFactory; +import com.dy.common.util.Callback; +import com.dy.common.util.TimerTaskJob; +import com.dy.rtuMw.web.webRequest.WebRequestDeal; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.*; + +/** + * @Author: liurunyu + * @Date: 2025/2/12 14:12 + * @Description + */ +public class MsCenterManager extends TimerTaskJob implements Callback { + + private static final Logger log = LogManager.getLogger(MsCenterManager.class.getName()); + + private static final MsCenterManager INSTANCE = new MsCenterManager(); + //娑堟伅缂撳瓨闃熷垪锛岀嚎绋嬪畨鍏ㄧ殑 + private static final Queue msQueue = new Queue("MsCenterQueue") ; + + private static final Map<String, String> msReceivers = new HashMap<>() ; + + + private MsCenterManager(){ + } + + protected static MsCenterManager getInstance() { + return MsCenterManager.INSTANCE; + } + + /** + * 鍒濆鍖栭厤缃俊鎭� + */ + protected void initOption(MsCenterConfigVo configVo) { + } + /** + * 娉ㄥ唽娑堟伅鎺ユ敹鍣� + * @param webUrl 鎺ユ敹鑰厀eb http post url + */ + protected void registerMsReceiver(String webUrl){ + if(!msReceivers.containsKey(webUrl)){ + msReceivers.put(webUrl, webUrl) ; + } + } + + protected void pushMs(MsObj msNode){ + try { + msQueue.pushTail(msNode); + }catch (Exception e){ + log.error("娑堟伅涓績闃熷垪瀛樺叆娑堟伅鏃跺彂鐢熷紓甯�", e); + } + } + + @Override + public Object execute() throws Exception { + if(msQueue.size() > 0){ + JSONObject msNode1 = (JSONObject)msQueue.pop() ; + if(msNode1 != null){ + //澶ч儴鍒嗘椂闂磎sNode1鏄痭ull + List<JSONObject> list = new ArrayList<>() ; + list.add(msNode1) ; + JSONObject msNode ; + do{ + msNode = (JSONObject)msQueue.pop() ; + if(msNode != null){ + list.add(msNode) ; + } + }while (msNode != null); + this.notifyMs(list) ; + } + } + return null; + } + + + //////////////////////////////////////////////////// + // + // 娑堟伅閫氱煡閫氱煡宸ヤ綔绾跨▼鎵ц瀹屾垚鍚庡洖璋冪殑鏂规硶锛� + // 涔熷氨鏄笂闈xecute鏂规硶鎵ц瀹屾垚杩斿洖鎴栨姏鍑哄紓甯稿悗锛屾墽琛屼笅闈笁涓柟娉� + // + //////////////////////////////////////////////////// + @Override + public void call(Object obj) { + //绾跨▼宸ヤ綔鎵ц瀹屼簡锛宱bj = Boolean(true) + } + @Override + public void call(Object... objs) { + } + @Override + public void exception(Exception e) { + log.error("娑堟伅閫氱煡浼烘湇绾跨▼鍙戠敓寮傚父", e); + } + + + /** + * 鎶婃秷鎭�氱煡鍑哄幓 + * @param list + */ + private void notifyMs(List<JSONObject> list){ + try { + if(msReceivers.size() > 0){ + ThreadPool.Pool pool = TreadPoolFactory.getThreadPoolLong() ; + pool.putJob(new ThreadPool.Job() { + public void execute() { + Iterator<String> it = msReceivers.keySet().iterator() ; + while (it.hasNext()){ + doNotifyMs(it.next(), list) ; + } + } + @Override + public void destroy(){ + } + @Override + public boolean isDestroy(){ + return false ; + } + + }); + } + } catch (Exception e) { + log.error("鍦≧tuDataNode鍐呭彂鐢熷紓甯�", e); + } + } + + private void doNotifyMs(String receiverWebUrl, List<JSONObject> list){ + WebRequestDeal deal = SpringContextUtil.getBean(WebRequestDeal.class) ; + deal.deal(receiverWebUrl, list); + } + +} -- Gitblit v1.8.0