persistqueue.java

来自「采用JAVA开发」· Java 代码 · 共 74 行

JAVA
74
字号
package com.gctech.sms.sp.cms.core;
import com.gctech.sms.sp.cms.msg.*;
import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;

public class PersistQueue
{
  LinkedQueue queue = null;
  String fileLocation = "defaultPersist.db";
  public PersistQueue(boolean isPersist)
  {
    queue = new LinkedQueue();
  }

  /**
   * 持久化队列,并制定保存队列的文件名字
   * @param fileLocation
   */
  public PersistQueue(String fileLocation)
  {

  }

  public boolean isEmpty()
  {
    return queue.isEmpty();
  }

  public void putMessage(Message msg) throws InterruptedException
  {
    try
    {
      queue.put(msg);
    }
    catch(InterruptedException ie)
    {
      throw ie;
    }

  }


  public Message takeMessage() throws PlatformException
  {
    try
    {
      return (Message)queue.take();
    }
    catch(InterruptedException ie)
    {
      throw new PlatformException(ie.getMessage());
    }

  }

  public Message takeMessage(long time) throws InterruptedException
  {
    try
    {
      return (Message)queue.poll(time);
    }
    catch(InterruptedException ie)
    {
      throw  ie;
    }

  }



  public static void main(String[] args) {
//    PersistQueue persistQueue1 = new PersistQueue();
  }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?