ackedqueue.java

来自「一个类似于openJMS分布在ObjectWeb之下的JMS消息中间件。」· Java 代码 · 共 97 行

JAVA
97
字号
/* * JORAM: Java(TM) Open Reliable Asynchronous Messaging * Copyright (C) 2004 - ScalAgent Distributed Technologies * Copyright (C) 2004 - France Telecom R&D * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or any later version. *  * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Lesser General Public License for more details. *  * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 * USA. * * Initial developer(s): ScalAgent Distributed Technologies */package org.objectweb.joram.mom.proxies;import org.objectweb.util.monolog.api.BasicLevel;import org.objectweb.joram.mom.MomTracing;import java.util.*;public class AckedQueue implements java.io.Serializable {  private Vector list;  private int current;  public AckedQueue() {    list = new Vector();    current = 0;  }  public void push(ProxyMessage msg) {    if (MomTracing.dbgProxy.isLoggable(BasicLevel.DEBUG))      MomTracing.dbgProxy.log(        BasicLevel.DEBUG, "AckedQueue.push(" + msg + ')');    synchronized (list) {      list.addElement(msg);      list.notify();    }  }  public ProxyMessage get() throws InterruptedException {    if (MomTracing.dbgProxy.isLoggable(BasicLevel.DEBUG))      MomTracing.dbgProxy.log(        BasicLevel.DEBUG, "AckedQueue.get()");    synchronized (list) {       while ((list.size() - current) == 0) {	list.wait();      }            ProxyMessage msg =         (ProxyMessage)list.elementAt(current);      current++;      return msg;    }  }  public void ack(long ackId) {    if (MomTracing.dbgProxy.isLoggable(BasicLevel.DEBUG))      MomTracing.dbgProxy.log(        BasicLevel.DEBUG, "AckedQueue.ack(" + ackId + ')');    synchronized (list) {      while (list.size() > 0) {        ProxyMessage m = 	  (ProxyMessage)list.elementAt(0);	if (ackId < m.getId()) {          	  return;	} else {	  // acked          if (MomTracing.dbgProxy.isLoggable(BasicLevel.DEBUG))            MomTracing.dbgProxy.log(              BasicLevel.DEBUG, "AckedQueue acked " + m.getId());	  list.removeElementAt(0);          if (current > 0) {            current--;          }	}      }    }  }  public void reset() {    if (MomTracing.dbgProxy.isLoggable(BasicLevel.DEBUG))      MomTracing.dbgProxy.log(        BasicLevel.DEBUG, "AckedQueue.reset()");    current = 0;  }}

⌨️ 快捷键说明

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