| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- package com.shkpr.service.alambizplugin.globalmgr;
- import com.global.base.log.LogLevelFlag;
- import com.global.base.log.LogPrintMgr;
- import com.global.base.taskqueue.TaskQueueData;
- import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
- import com.shkpr.service.alambizplugin.constants.TaskQueueDataTypeEx;
- import com.shkpr.service.alambizplugin.globalcache.GlobalData;
- import com.shkpr.service.alambizplugin.queues.DelayCommTaskQueueHandlerPool;
- import javax.annotation.PostConstruct;
- import javax.annotation.PreDestroy;
- public class DelayTaskQueueMgr {
- private String mStrClassName;
- private static volatile DelayTaskQueueMgr msInstance = null;
- private DelayCommTaskQueueHandlerPool mCommTaskQueuePool = null;
- private DelayTaskQueueMgr() {mStrClassName = this.getClass().getSimpleName();
- }
- public static DelayTaskQueueMgr getInstance(){
- if (msInstance == null){
- synchronized (DelayTaskQueueMgr.class){
- if (msInstance == null){
- msInstance = new DelayTaskQueueMgr();
- }
- }
- }
- return msInstance;
- }
- private void init(){
- int nPooSize = GlobalData.getInstance().getCpuCores()/2;
- mCommTaskQueuePool = new DelayCommTaskQueueHandlerPool(nPooSize<=0?1:nPooSize);
- mCommTaskQueuePool.init();
- LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, LogFlagBusiType.BUSI_INIT.toStrValue(), mStrClassName
- ,String.format("init()..."));
- }
- @PostConstruct
- public void afterPropertiesSet() throws Exception{
- init();
- }
- @PreDestroy
- public void destroy() throws Exception{
- if (mCommTaskQueuePool != null)
- mCommTaskQueuePool.stopAllQueueHandler(true);
- }
- public <T> boolean postTaskData(int type, T data, long expiredMs){
- if (data != null
- && type > TaskQueueDataTypeEx.DELAY_TASK_BEGIN
- && type < TaskQueueDataTypeEx.DELAY_TASK_END
- && mCommTaskQueuePool != null)
- return mCommTaskQueuePool.postTaskData(type, data, expiredMs);
- return false;
- }
- public boolean postTaskData(TaskQueueData taskData, long expiredMs){
- if (taskData != null
- && taskData.getType() > TaskQueueDataTypeEx.DELAY_TASK_BEGIN
- && taskData.getType() < TaskQueueDataTypeEx.DELAY_TASK_END
- && mCommTaskQueuePool != null)
- return mCommTaskQueuePool.postTaskData(taskData, expiredMs);
- return false;
- }
- public void stopAllTaskQueue(){
- if (mCommTaskQueuePool != null)
- mCommTaskQueuePool.stopAllQueueHandler(true);
- }
- public void timePerSecondNow(){
- if (mCommTaskQueuePool != null){
- mCommTaskQueuePool.timePerSecondNow();
- }
- }
- }
|