KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > tribe > adapters > MulticastRequestAdapterMessage


1 /**
2  * Tribe: Group communication library.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: tribe@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Emmanuel Cecchet.
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.tribe.adapters;
26
27 import java.io.Serializable JavaDoc;
28
29 import org.objectweb.tribe.common.Member;
30
31 /**
32  * This class defines a MulticastRequestAdapterMessage for carrying request and
33  * replies of multicastMessage().
34  *
35  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
36  * @version 1.0
37  */

38 class MulticastRequestAdapterMessage implements Serializable JavaDoc
39 {
40   static final int REQUEST = 0;
41   static final int REQUEST_ONLY = 1;
42   static final int REPLY = 2;
43   private Serializable JavaDoc msg;
44   private Member sender;
45   private int uid;
46   private int requestReply;
47
48   /**
49    * Creates a new <code>MulticastRequestAdapterMessage</code> object
50    *
51    * @param msg message to send
52    * @param sender message sender
53    * @param message unique identifier
54    * @param requestOrReply REQUEST, REQUEST_ONLY or REPLY
55    */

56   public MulticastRequestAdapterMessage(Serializable JavaDoc msg, Member sender,
57       int uid, int requestOrReply)
58   {
59     this.msg = msg;
60     this.sender = sender;
61     this.uid = uid;
62     this.requestReply = requestOrReply;
63   }
64
65   /**
66    * Returns the message value.
67    *
68    * @return Returns the message.
69    */

70   public Serializable JavaDoc getMessage()
71   {
72     return msg;
73   }
74
75   /**
76    * Sets the message value.
77    *
78    * @param msg The message to set.
79    */

80   public void setMessage(Serializable JavaDoc msg)
81   {
82     this.msg = msg;
83   }
84
85   /**
86    * Returns true if the message is a request.
87    *
88    * @return true if the message is a request.
89    */

90   public boolean isRequest()
91   {
92     return requestReply == REQUEST;
93   }
94
95   /**
96    * Sets this message to a request.
97    */

98   public void setRequest()
99   {
100     this.requestReply = REQUEST;
101   }
102
103   /**
104    * Returns true if the message is a request only.
105    *
106    * @return true if the message is a request only.
107    */

108   public boolean isRequestOnly()
109   {
110     return requestReply == REQUEST_ONLY;
111   }
112
113   /**
114    * Sets this message to a request only.
115    */

116   public void setRequestOnly()
117   {
118     this.requestReply = REQUEST_ONLY;
119   }
120
121   /**
122    * Returns true if the message is a reply.
123    *
124    * @return true if the message is a reply.
125    */

126   public boolean isReply()
127   {
128     return requestReply == REPLY;
129   }
130
131   /**
132    * Sets this message to a reply.
133    */

134   public void setReply()
135   {
136     this.requestReply = REPLY;
137   }
138
139   /**
140    * Returns the sender of the message.
141    *
142    * @return Returns the sender.
143    */

144   public Member getSender()
145   {
146     return sender;
147   }
148
149   /**
150    * Sets the sender of the message.
151    *
152    * @param sender The sender to set.
153    */

154   public void setSender(Member sender)
155   {
156     this.sender = sender;
157   }
158
159   /**
160    * Returns the uid value.
161    *
162    * @return Returns the uid.
163    */

164   public int getUid()
165   {
166     return uid;
167   }
168
169   /**
170    * @see java.lang.Object#toString()
171    */

172   public String JavaDoc toString()
173   {
174     String JavaDoc type;
175     switch (requestReply)
176     {
177       case REQUEST :
178         type = "Request ";
179         break;
180       case REQUEST_ONLY :
181         type = "Request only ";
182         break;
183       case REPLY :
184         type = "Reply ";
185         break;
186       default :
187         type = "Unknown ";
188         break;
189     }
190     return type + uid + " from " + sender + " (" + msg + ")";
191   }
192 }
Popular Tags