KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > mcast > Response


1 package org.sapia.ubik.mcast;
2
3
4 /**
5  * Models a synchronous response to a remote event.
6  *
7  * @see org.sapia.ubik.mcast.EventChannel#send(ServerAddress, String, Object)
8  * @see org.sapia.ubik.mcast.EventChannel#send(String, Object)
9  * @see Response
10  *
11  * @author Yanick Duchesne
12  * <dl>
13  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
14  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
15  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
16  * </dl>
17  */

18 public class Response implements java.io.Serializable JavaDoc {
19   /**
20    * Corresponds to the OK status, signifying that the response
21    * was returned normally.
22    */

23   public static final int STATUS_OK = 0;
24
25   /**
26    * Indicates that the remote node corresponding to this instance
27    * is probably down.
28    */

29   public static final int STATUS_SUSPECT = 1;
30   private long _eventId;
31   private Object JavaDoc _data;
32   private boolean _none;
33   private int _status = STATUS_OK;
34
35   /**
36    * Constructor for Response.
37    */

38   Response(long eventId, Object JavaDoc data) {
39     _eventId = eventId;
40     _data = data;
41   }
42
43   /**
44    * Returns <code>true</code> if this instance contains a <code>Throwable</code>.
45    */

46   public boolean isError() {
47     return (_data != null) && _data instanceof Throwable JavaDoc;
48   }
49
50   /**
51    * Returns the <code>Throwable</code> held within this response.
52    *
53    * @return a <code>Throwable</code>
54    *
55    * @see #isError()
56    */

57   public Throwable JavaDoc getThrowable() {
58     if (_data != null) {
59       return (Throwable JavaDoc) _data;
60     }
61
62     return null;
63   }
64
65   /**
66    * Returns the data held by this instance.
67    *
68    * @return an <code>Object</code>, or null if this response
69    * has no data.
70    */

71   public Object JavaDoc getData() {
72     return _data;
73   }
74
75   /**
76    * Returns this instance's status.
77    *
78    * @see #STATUS_OK
79    * @see #STATUS_SUSPECT
80    */

81   public int getStatus() {
82     return _status;
83   }
84
85   Response setNone() {
86     _none = true;
87
88     return this;
89   }
90
91   boolean isNone() {
92     return _none;
93   }
94
95   Response setStatusSuspect() {
96     _status = STATUS_SUSPECT;
97
98     return this;
99   }
100
101   public String JavaDoc toString() {
102     return "[ eventId=" + _eventId + ", data=" + _data + "] ";
103   }
104 }
105
Popular Tags