KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > dyade > aaa > agent > Notification


1 /*
2  * Copyright (C) 2001 - 2006 ScalAgent Distributed Technologies
3  * Copyright (C) 1996 - 2000 BULL
4  * Copyright (C) 1996 - 2000 INRIA
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA.
20  */

21 package fr.dyade.aaa.agent;
22
23 import java.io.*;
24
25 /**
26  * Class Notification is the root of the notifications hierarchy. Every
27  * notification's class has Notification as a superclass.
28  */

29 public class Notification implements Serializable, Cloneable JavaDoc {
30   static final long serialVersionUID = 3007264908616389613L;
31
32   /**
33    * True if the notification is persistent, false otherwise. By default, this
34    * field is set to true during object creation and disk loading. This field
35    * is carry by network protocol.
36    */

37   protected transient boolean persistent = true;
38
39   /**
40    * True if the notification is detachable, false otherwise. A detachable
41    * notification is saved in a different object that its containing
42    * message.
43    */

44   protected transient boolean detachable = false;
45
46   /**
47    * True if the notification is detached, false otherwise. A detached
48    * notification is not destroyed in the same way that its containing
49    * message.
50    */

51   protected transient boolean detached = false;
52
53   /**
54    * The expiration date for this notification.
55    *
56    * This field is handled by the network protocol in order to fit
57    * the time synchronisation problem.
58    */

59   long expiration = -1L;
60
61   /**
62    * Sets the expiration date for this notification.
63    *
64    * A value of -1L (default) indicates that the notification does
65    * not expire.
66    *
67    * @param expiration the expiration date for this notification.
68    */

69   public void setExpiration(long expiration) {
70     this.expiration = expiration;
71   }
72
73   /**
74    * Gets the notification's expiration value.
75    *
76    * This field is handled by the network protocol in order to fit
77    * the time synchronisation problem.
78    *
79    * If the expiration date is set to -1L (default), it indicates that
80    * the notification does not expire.
81    *
82    * When a notification's expiration time is reached, the MOM should
83    * discard it without any form of notification of message expiration.
84    * Agents should not receive messages that have expired; however, the
85    * MOM does not guarantee that this will not happen.
86    *
87    * @return The notification's expiration value.
88    */

89   public long getExpiration() {
90     return expiration;
91   }
92
93   /**
94    * If the notification is stored independently that its containing message
95    * messageId contains the persistent name of this notification.
96    */

97   transient String JavaDoc messageId = null;
98
99   public String JavaDoc getMessageId() {
100     return messageId;
101   }
102
103   /** Context of the notification. */
104   private Object JavaDoc context;
105
106   /**
107    * Sets the context of the notification.
108    *
109    * @param context the context of the notification.
110    */

111   public final void setContext(Object JavaDoc context) {
112     this.context = context;
113   }
114
115   /**
116    * Returns the context of the notification.
117    *
118    * @return the context of the notification.
119    */

120   public final Object JavaDoc getContext() {
121     return context;
122   }
123
124   /**
125    * Returns a clone of this notification.
126    *
127    * @return a clone of this notification.
128    */

129   public synchronized Object JavaDoc clone() {
130     try {
131       Notification dup = (Notification) super.clone();
132       dup.detached = false;
133       dup.messageId = null;
134       return dup;
135     } catch (CloneNotSupportedException JavaDoc e) {
136       // this shouldn't happen, since we are Cloneable
137
throw new InternalError JavaDoc();
138     }
139   }
140
141   /**
142    * Return true if notification is persistent.
143    *
144    * @return persistent of this notification.
145    */

146   public boolean isPersistent() {
147     return persistent;
148   }
149
150   /**
151    * Provides a string image for this object.
152    *
153    * @return a string representation for this object.
154    */

155   public final String JavaDoc toString() {
156     StringBuffer JavaDoc output = new StringBuffer JavaDoc();
157     return toString(output).toString();
158   }
159
160   /**
161    * Appends a string image for this object to the StringBuffer parameter.
162    *
163    * @param output
164    * buffer to fill in
165    * @return
166     <code>output</code> buffer is returned
167    */

168   public StringBuffer JavaDoc toString(StringBuffer JavaDoc output) {
169     output.append('(');
170     output.append(super.toString());
171     output.append(",messageId=").append(messageId);
172     output.append(",persistent=").append(persistent);
173     output.append(",detachable=").append(detachable);
174     output.append(",detached=").append(detached);
175     output.append(",context=").append(context);
176     output.append(",expiration=").append(expiration);
177     output.append(')');
178
179     return output;
180   }
181
182 }
183
Popular Tags