1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
32
33
34
35 private LinkedList queue = new LinkedList();
36
37 private static Logger logger = Logger.getLogger(JOscarMessageQueue.class);
38
39
40
41 public JOscarMessageQueue()
42 {
43
44 }
45
46
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 }