messagequeue.java

来自「Java SIP」· Java 代码 · 共 72 行

JAVA
72
字号
/* * This file is part of the Java SIP library, an open source SIP library. Please see * http://collaboration.mitre.org/sip for more information *  * Copyright (c) 2001 The MITRE Corporation  *  * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Library General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at your * option) 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 Library General Public * License for more details. *  * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB.  If not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. * *//** * class to maintain incoming messages * * Based on QueueObject, DDJ 10/98 by Mike Criscolo * */package org.mitre.jsip;import java.util.Vector;public class MessageQueue {    // Vector is inherently thread-safe    protected Vector queue;    protected int itemcount;    protected String queueName;    public MessageQueue(String name)    {	queue = new Vector();	queueName = name;	itemcount = 0;    }    /**     * Retrieve a message from the queue     */    public synchronized SipMessage getQueueMessage()    {	SipMessage item = (SipMessage) queue.firstElement();	queue.removeElement( item );	itemcount--;	return item;    }    public synchronized void AddQueueItem(SipMessage message)    {	itemcount++;	queue.addElement(message);	if (SipClient.DEBUG) System.out.println("new item! count is " + itemcount);    }    public synchronized boolean hasMessage() {	// maybe put a notify in here and have it called by AddQueueItem ???	return ( itemcount > 0 ) ? true : false;    }}

⌨️ 快捷键说明

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