KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mx > remoting > NotificationQueue


1 /***************************************
2  * *
3  * JBoss: The OpenSource J2EE WebOS *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  ***************************************/

9 package org.jboss.mx.remoting;
10
11 import java.io.Serializable JavaDoc;
12 import java.util.ArrayList JavaDoc;
13 import java.util.Iterator JavaDoc;
14 import java.util.List JavaDoc;
15
16 /**
17  * NotificationQueue is an object that holds one or more NotificationEntry objects. This
18  * object is created and passed from the server to the client during invocation so that the
19  * client and re-deliver Notifications to client-side NotificationListeners.
20  *
21  * @author <a HREF="mailto:jhaynie@vocalocity.net">Jeff Haynie</a>
22  * @version $Revision: 30392 $
23  */

24 public class NotificationQueue implements Serializable JavaDoc
25 {
26    static final long serialVersionUID = -1185639057427341662L;
27
28    private final String JavaDoc sessionId;
29    private final List JavaDoc notifications = new ArrayList JavaDoc();
30
31    /**
32     * create an empty queue
33     *
34     * @param sessionId
35     */

36    public NotificationQueue(String JavaDoc sessionId)
37    {
38       this.sessionId = sessionId;
39    }
40
41    public String JavaDoc toString()
42    {
43       return "NotificationQueue [sessionId:" + sessionId + ",notifications:" + notifications + "]";
44    }
45
46    /**
47     * clear the queue
48     */

49    public void clear()
50    {
51       notifications.clear();
52    }
53
54    /**
55     * add an entry to the queue
56     *
57     * @param notification
58     */

59    void add(NotificationEntry notification)
60    {
61       synchronized(notifications)
62       {
63          notifications.add(notification);
64       }
65    }
66
67    /**
68     * return the session ID associated with the queue
69     *
70     * @return
71     */

72    public String JavaDoc getSessionID()
73    {
74       return sessionId;
75    }
76
77    /**
78     * return true if there are no entries, false if there are 1..n entries
79     *
80     * @return
81     */

82    public boolean isEmpty()
83    {
84       synchronized(notifications)
85       {
86          return notifications.isEmpty();
87       }
88    }
89
90    /**
91     * return an Iterator of NotificationEntry objects
92     *
93     * @return
94     */

95    public Iterator JavaDoc iterator()
96    {
97       synchronized(notifications)
98       {
99          return notifications.iterator();
100       }
101    }
102 }
103
Popular Tags