NotifyMsgQueueMgr.java 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package com.shkpr.service.alambizplugin.globalmgr;
  2. import com.global.base.log.LogLevelFlag;
  3. import com.global.base.log.LogPrintMgr;
  4. import com.global.base.taskqueue.TaskQueueData;
  5. import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
  6. import com.shkpr.service.alambizplugin.constants.TaskQueueDataTypeEx;
  7. import com.shkpr.service.alambizplugin.queues.NotifyMsgQueueHandlerPool;
  8. import javax.annotation.PostConstruct;
  9. import javax.annotation.PreDestroy;
  10. public class NotifyMsgQueueMgr {
  11. private String mStrClassName;
  12. private static volatile NotifyMsgQueueMgr msInstance = null;
  13. private NotifyMsgQueueHandlerPool mNotifyMsgQueuePool = null;
  14. private NotifyMsgQueueMgr() {mStrClassName = this.getClass().getSimpleName();
  15. }
  16. public static NotifyMsgQueueMgr getInstance() {
  17. if (msInstance == null){
  18. synchronized (NotifyMsgQueueMgr.class){
  19. if (msInstance == null){
  20. msInstance = new NotifyMsgQueueMgr();
  21. }
  22. }
  23. }
  24. return msInstance;
  25. }
  26. private void init(){
  27. mNotifyMsgQueuePool = new NotifyMsgQueueHandlerPool(1);
  28. mNotifyMsgQueuePool.init();
  29. LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, LogFlagBusiType.BUSI_INIT.toStrValue(), mStrClassName
  30. ,String.format("init()..."));
  31. }
  32. @PostConstruct
  33. public void afterPropertiesSet() throws Exception{
  34. init();
  35. }
  36. @PreDestroy
  37. public void destroy() throws Exception{
  38. if (mNotifyMsgQueuePool != null)
  39. mNotifyMsgQueuePool.stopAllQueueHandler(true);
  40. }
  41. public <T> boolean postTaskData(int type, T data){
  42. if (data != null
  43. && type > TaskQueueDataTypeEx.NOTIFY_MSG_BEGIN
  44. && type < TaskQueueDataTypeEx.NOTIFY_MSG_END
  45. && mNotifyMsgQueuePool != null)
  46. return mNotifyMsgQueuePool.postTaskData(type, data);
  47. return false;
  48. }
  49. public boolean postTaskData(TaskQueueData taskData){
  50. if (taskData != null
  51. && taskData.getType() > TaskQueueDataTypeEx.NOTIFY_MSG_BEGIN
  52. && taskData.getType() < TaskQueueDataTypeEx.NOTIFY_MSG_END
  53. && mNotifyMsgQueuePool != null)
  54. return mNotifyMsgQueuePool.postTaskData(taskData);
  55. return false;
  56. }
  57. public void stopAllTaskQueue(){
  58. if (mNotifyMsgQueuePool != null)
  59. mNotifyMsgQueuePool.stopAllQueueHandler(true);
  60. }
  61. public void timePerSecondNow(){
  62. if (mNotifyMsgQueuePool != null){
  63. mNotifyMsgQueuePool.timePerSecondNow();
  64. }
  65. }
  66. }