From 1a2b07f01ba4616fd9e894dddf474b56d020158c Mon Sep 17 00:00:00 2001
From: zhubaomin <zhubaomin>
Date: 星期一, 07 四月 2025 15:18:51 +0800
Subject: [PATCH] 整理版本

---
 pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/core/CoreUnit.java |  121 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 121 insertions(+), 0 deletions(-)

diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/core/CoreUnit.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/core/CoreUnit.java
new file mode 100644
index 0000000..6b3ce51
--- /dev/null
+++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/core/CoreUnit.java
@@ -0,0 +1,121 @@
+package com.dy.common.mw.core;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.dy.common.queue.Queue;
+import com.dy.common.mw.UnitAdapterInterface;
+import com.dy.common.mw.UnitInterface;
+import com.dy.common.mw.UnitCallbackInterface;
+
+
+public class CoreUnit implements UnitInterface {
+	
+	private static final CoreUnit instance = new CoreUnit() ;
+	private static boolean started = false ;
+	
+	//鎭掍箙浠诲姟锛屼竴鏃﹀姞鍏ワ紝姘镐箙瀛樺湪
+	private static final List<CoreTask> constantTasks = new ArrayList<>() ;
+	//浠诲姟闃熷垪锛屼竴娆℃�т换鍔★紝浠诲姟鎵ц鏃朵粠闃熷垪涓竻闄�
+	protected static Queue taskQueue = new Queue("coreTaskQueue") ;
+	
+	public CoreUnitAdapter adapter ;
+	
+	private CoreUnit(){}
+
+	public static CoreUnit getInstance(){
+		return instance ;
+	}
+	
+	@Override
+	public void setAdapter(UnitAdapterInterface adapter) throws Exception {
+		if(adapter == null){
+			throw new Exception("鏍稿績妯″潡閫傞厤鍣ㄥ璞′笉鑳戒负绌猴紒") ;
+		}
+		this.adapter = (CoreUnitAdapter)adapter ; 
+		CoreUnitConfigVo vo = this.adapter.getConfig() ;
+		if(vo == null){
+			throw new Exception("鏍稿績妯″潡閰嶇疆瀵硅薄涓嶈兘涓虹┖锛�") ;
+		}
+		if(vo.coreInterval == null){
+			throw new Exception("鏍稿績妯″潡閰嶇疆瀵硅薄闂撮殧灞炴�у�间笉鑳戒负绌猴紒") ;
+		}
+		if(vo.coreInterval <= 0){
+			throw new Exception("鏍稿績妯″潡閰嶇疆瀵硅薄灞炴�oreInterval鍊间笉鑳藉皬浜�0锛�") ;
+		}
+		if(vo.coreInterval > 1000){
+			throw new Exception("鏍稿績妯″潡閰嶇疆瀵硅薄灞炴�oreInterval鍊间笉鑳藉ぇ浜�1000锛�") ;
+		}
+		if(vo.queueWarnSize == null || vo.queueMaxSize == null){
+			throw new Exception("鏍稿績妯″潡閰嶇疆瀵硅薄闃熷垪鑺傜偣闄愬埗鏁伴噺灞炴�у�间笉鑳戒负绌猴紒") ;
+		}
+		if(vo.queueWarnSize < 500){
+			throw new Exception("鏍稿績妯″潡閰嶇疆瀵硅薄闃熷垪鑺傜偣璀﹀憡闄愬埗鏁伴噺灞炴�у�间笉鑳藉皬浜�500锛�") ;
+		}
+		if(vo.queueMaxSize < 5000){
+			throw new Exception("鏍稿績妯″潡閰嶇疆瀵硅薄闃熷垪鑺傜偣鎷掔粷闄愬埗鏁伴噺灞炴�у�间笉鑳藉皬浜�5000锛�") ;
+		}
+		if(vo.queueWarnSize > vo.queueMaxSize){
+			throw new Exception("鏍稿績妯″潡閰嶇疆瀵硅薄闃熷垪鑺傜偣璀﹀憡闄愬埗鏁伴噺灞炴�у�间笉鑳藉ぇ浜庢嫆缁濋檺鍒舵暟閲忥紒") ;
+		}
+		taskQueue.setLimit(vo.queueWarnSize, vo.queueMaxSize);
+	}
+
+	@Override
+	public void start(UnitCallbackInterface callback) throws Exception {
+		if(!started){
+			started = true ;
+			/*
+			CoreThread ct = CoreThread.getInstance() ;
+			ct.setSleep(this.adapter.getConfig().sleepBigBusy, this.adapter.getConfig().sleepSmallBusy);
+			ct.start();
+			*/
+			CoreTimer ct = CoreTimer.getInstance() ;
+			ct.setSleep(this.adapter.getConfig().coreInterval);
+			ct.start();
+
+			CoreConstantManage ccm = CoreConstantManage.getInstance() ;
+			ccm.setSleep(this.adapter.getConfig().coreInterval);
+			ccm.start();
+			
+			if(adapter.getConfig().showStartInfo){
+				System.out.println("鏍稿績妯″潡鎴愬姛鍚姩锛�"
+						+ "涓荤嚎绋嬫墽琛岄棿闅旓細" + adapter.getConfig().coreInterval + "姣");
+			}
+			callback.call(null);
+		}
+	}
+
+	@Override
+	public void stop(UnitCallbackInterface callback) {
+	}
+	
+
+	/**
+	 * 鍔犲叆鏍稿績浠诲姟
+	 * @param task 鏍稿績浠诲姟
+	 * @throws Exception 寮傚父
+	 */
+	@SuppressWarnings("unused")
+	public void pushCoreTask(CoreTask task) throws Exception{
+		taskQueue.pushTail(task);
+	}
+	
+	/**
+	 * 鍔犲叆鎭掍箙浠诲姟
+	 * @param task  鎭掍箙浠诲姟
+	 */
+	@SuppressWarnings("unused")
+	public static void addConstantTask(CoreTask task){
+		constantTasks.add(task) ;
+	}
+	
+	/**
+	 * 寰楀埌鎵�鏈夋亽涔呬换鍔�
+	 * @return 鎵�鏈夋亽涔呬换鍔�
+	 */
+	public static List<CoreTask> getAllConstantTasks(){
+		return constantTasks ;
+	}
+
+}

--
Gitblit v1.8.0