| 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.AsyncCommTaskQueueHandlerPool;
- import javax.annotation.PostConstruct;
- import javax.annotation.PreDestroy;
- public class AsyncTaskQueueMgr {
- private String mStrClassName;
- private static volatile AsyncTaskQueueMgr msInstance = null;
- private AsyncCommTaskQueueHandlerPool mAsyncTaskQueuePool = null;
- private AsyncTaskQueueMgr() {mStrClassName = this.getClass().getSimpleName();
- }
- public static AsyncTaskQueueMgr getInstance() {
- if (msInstance == null){
- synchronized (AsyncTaskQueueMgr.class){
- if (msInstance == null){
- msInstance = new AsyncTaskQueueMgr();
- }
- }
- }
- return msInstance;
- }
- private void init(){
- int nPooSize = GlobalData.getInstance().getCpuCores()/2;
- mAsyncTaskQueuePool = new AsyncCommTaskQueueHandlerPool(nPooSize<=0?1:nPooSize);
- mAsyncTaskQueuePool.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 (mAsyncTaskQueuePool != null)
- mAsyncTaskQueuePool.stopAllQueueHandler(true);
- }
- public <T> boolean postTaskData(int type, T data){
- if (data != null
- && type > TaskQueueDataTypeEx.ASYNC_TASK_BEGIN
- && type < TaskQueueDataTypeEx.ASYNC_TASK_END
- && mAsyncTaskQueuePool != null)
- return mAsyncTaskQueuePool.postTaskData(type, data);
- return false;
- }
- public boolean postTaskData(TaskQueueData taskData){
- if (taskData != null
- && taskData.getType() > TaskQueueDataTypeEx.ASYNC_TASK_BEGIN
- && taskData.getType() < TaskQueueDataTypeEx.ASYNC_TASK_END
- && mAsyncTaskQueuePool != null)
- return mAsyncTaskQueuePool.postTaskData(taskData);
- return false;
- }
- public void stopAllTaskQueue(){
- if (mAsyncTaskQueuePool != null)
- mAsyncTaskQueuePool.stopAllQueueHandler(true);
- }
- public void timePerSecondNow(){
- if (mAsyncTaskQueuePool != null){
- mAsyncTaskQueuePool.timePerSecondNow();
- }
- }
- }
|