View Javadoc

1   /*
2    *  XNap
3    *
4    *  A pure java file sharing client.
5    *
6    *  See AUTHORS for copyright information.
7    *
8    *  This program is free software; you can redistribute it and/or modify
9    *  it under the terms of the GNU General Public License as published by
10   *  the Free Software Foundation; either version 2 of the License, or
11   *  (at your option) any later version.
12   *
13   *  This program is distributed in the hope that it will be useful,
14   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   *  GNU General Public License for more details.
17   *
18   *  You should have received a copy of the GNU General Public License
19   *  along with this program; if not, write to the Free Software
20   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21   *
22   */
23  package org.xnap.plugin.joscar.msg;
24  
25  import java.util.*;
26  
27  import org.apache.log4j.Logger;
28  
29  public class JOscarMessageQueue 
30  {
31  	//--- Constant(s) ---
32  
33  	//--- Data field(s) ---
34  
35  	private LinkedList queue = new LinkedList();
36  
37      private static Logger logger = Logger.getLogger(JOscarMessageQueue.class);
38  	
39  	//--- Constructor(s) ---
40  	
41      public JOscarMessageQueue()
42  	{
43  
44  	}
45  
46      //--- Method(s) ---
47  	
48  	public synchronized void clear()
49  	{
50  		queue.clear();
51  	}
52  	
53  	public synchronized void addMessage(String uin, String message)
54  	{
55  		queue.add(new DefaultJOscarMessage(uin, message));
56  		notify();
57  	}
58  
59  	public synchronized void addSMS(String uin, String message)
60  	{
61  		queue.add(new SMSJOscarMessage(uin, message));
62  		notify();
63  	}
64  
65  	public synchronized void addUser(String uin)
66  	{
67  		queue.add(new UserJOscarMessage(uin));
68  		notify();
69  	}
70  
71  	public synchronized void addMessage(JOscarMessage message)
72  	{
73  		queue.add(message);
74  		notify();
75  	}
76  
77  	/***
78  	 * Returns the next message to send to the icq server.
79  	 *
80  	 * @throws InterruptedException if the thread waiting for the next message
81  	 * was interrupted.
82  	 */
83  	public synchronized JOscarMessage getMessage() throws InterruptedException
84  	{
85  		while (queue.size() == 0) {
86  			wait();
87  		}
88  		return (JOscarMessage)queue.removeFirst();
89  	}
90  
91  }