1 /*
2 * Copyright (c) 1998-2002 The Jgroup Team.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 *
17 */
18
19 package jgroup.relacs.events;
20
21 import java.io.IOException;
22 import java.io.ObjectInput;
23 import java.io.ObjectOutput;
24
25 import jgroup.core.MemberId;
26 import jgroup.relacs.types.GroupIndex;
27 import jgroup.relacs.types.MemberIdImpl;
28 import jgroup.relacs.types.MessageId;
29
30 /**
31 * The <code>DeliveryAck</code> class represents a local message
32 * exchanged between members and the daemon; it is used by the member
33 * to notify the daemon that a message has been successfully delivered.
34 *
35 * @author Alberto Montresor
36 * @since Jgroup 1.2
37 */
38 public final class DeliveryAck
39 extends Event
40 {
41
42 ////////////////////////////////////////////////////////////////////////////////////////////
43 // Fields
44 ////////////////////////////////////////////////////////////////////////////////////////////
45
46 private static final long serialVersionUID = -6414737364782334061L;
47
48 /** Host position of the member in the current view */
49 private int hostIndex;
50
51 /** Local member position of the member in the current view */
52 private int memberIndex;
53
54 /** */
55 private int viewIndex;
56
57 /** Message identifier */
58 private int mid;
59
60 /** Identifier of the sender of the original message */
61 private MemberId sender;
62
63 /** Result value associated to the message acknowledgement */
64 private Object result;
65
66 /** Sender of this ack message */
67 private MemberId ackSender;
68
69
70 ////////////////////////////////////////////////////////////////////////////////////////////
71 // Constructors
72 ////////////////////////////////////////////////////////////////////////////////////////////
73
74 /**
75 * Default constructor for externalization.
76 */
77 public DeliveryAck()
78 {
79 }
80
81
82 /**
83 * Creates a <code>DeliveryAck</code> with the specified data.
84 *
85 * @param gid group identifier
86 * @param hostIndex host position in the current view
87 * @param memberIndex member position in the current view
88 * @param viewIndex
89 * @param mid message identifier
90 * @param sender sender identifier
91 * @param result result associated to the message acknowledgement
92 */
93 public DeliveryAck(int gid, int hostIndex, int memberIndex, int viewIndex,
94 int mid, MemberId sender, Object result, MemberId ackSender)
95 {
96 super(DELIVERY_ACK, gid);
97 this.hostIndex = hostIndex;
98 this.memberIndex = memberIndex;
99 this.viewIndex = viewIndex;
100 this.mid = mid;
101 this.sender = sender;
102 this.result = result;
103 this.ackSender = ackSender;
104 }
105
106 ////////////////////////////////////////////////////////////////////////////////////////////
107 // Getter / setter methods
108 ////////////////////////////////////////////////////////////////////////////////////////////
109
110 /**
111 * Returns the position index of the local host in the array of the
112 * hosts contained in the current view.
113 */
114 public int getHostIndex()
115 {
116 return hostIndex;
117 }
118
119 /**
120 * Returns the position index of this member in the array of
121 * the local members contained in the current view.
122 */
123 public int getMemberIndex()
124 {
125 return memberIndex;
126 }
127
128 /**
129 * Returns the position index of this member in the array of
130 * the members contained in the current view.
131 */
132 public int getViewIndex()
133 {
134 return viewIndex;
135 }
136
137 /**
138 * Returns the message identifier.
139 */
140 public int getMessageId()
141 {
142 return mid;
143 }
144
145 /**
146 * Returns the sender identifier of the original message sender.
147 */
148 public MemberId getSender()
149 {
150 return sender;
151 }
152
153 /**
154 * Returns the result object associated to the message acknowledgement.
155 */
156 public Object getResult()
157 {
158 return result;
159 }
160
161 /**
162 * Returns the sender of this ack message.
163 */
164 public MemberId getAckSender()
165 {
166 return ackSender;
167 }
168
169
170 ////////////////////////////////////////////////////////////////////////////////////////////
171 // Methods from Externalizable
172 ////////////////////////////////////////////////////////////////////////////////////////////
173
174 /**
175 * Restores the content of this object from the marshalled data contained
176 * in the specified input stream.
177 *
178 * @param in the stream to be read
179 */
180 public void readExternal(ObjectInput in)
181 throws IOException, ClassNotFoundException
182 {
183 super.readExternal(in);
184 hostIndex = GroupIndex.unmarshal(in);
185 memberIndex = GroupIndex.unmarshal(in);
186 viewIndex = GroupIndex.unmarshal(in);
187 mid = MessageId.unmarshal(in);
188 sender = new MemberIdImpl();
189 sender.readExternal(in);
190 result = in.readObject();
191 ackSender = new MemberIdImpl();
192 ackSender.readExternal(in);
193 }
194
195 /**
196 * Marshals the content of this object to the specified output stream.
197 *
198 * @param out the stream to be written
199 */
200 public void writeExternal(ObjectOutput out)
201 throws IOException
202 {
203 super.writeExternal(out);
204 GroupIndex.marshal(out, hostIndex);
205 GroupIndex.marshal(out, memberIndex);
206 GroupIndex.marshal(out, viewIndex);
207 MessageId.marshal(out, mid);
208 sender.writeExternal(out);
209 out.writeObject(result);
210 ackSender.writeExternal(out);
211 }
212
213
214 ////////////////////////////////////////////////////////////////////////////////////////////
215 // Methods from Object
216 ////////////////////////////////////////////////////////////////////////////////////////////
217
218 /**
219 * Returns a string representation of the object.
220 */
221 public String toString()
222 {
223 StringBuilder buf = new StringBuilder();
224 buf.append(super.toString());
225 buf.append("[DeliveryAck: hostIndex=");
226 buf.append(hostIndex);
227 buf.append(", memberIndex=");
228 buf.append(memberIndex);
229 buf.append(", viewIndex=");
230 buf.append(viewIndex);
231 buf.append(", mid=");
232 buf.append(mid);
233 buf.append(", sender=");
234 buf.append(sender);
235 buf.append(", ackSender=");
236 buf.append(ackSender);
237 buf.append("]");
238 return buf.toString();
239 }
240
241 } // END DeliveryAck