1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package uk.ac.rdg.resc.jstyx.messages;
30
31 import org.apache.mina.protocol.ProtocolViolationException;
32
33 import uk.ac.rdg.resc.jstyx.types.ULong;
34
35 /***
36 * Message sent to read data from a file
37 *
38 * @author Jon Blower
39 * $Revision: 176 $
40 * $Date: 2005-03-24 09:48:32 +0000 (Thu, 24 Mar 2005) $
41 * $Log$
42 * Revision 1.5 2005/03/24 09:48:31 jonblower
43 * Changed 'count' from long to int throughout for reading and writing
44 *
45 * Revision 1.4 2005/03/15 09:01:48 jonblower
46 * Message type now stored as short, not int
47 *
48 * Revision 1.3 2005/03/11 14:02:16 jonblower
49 * Merged MINA-Test_20059309 into main line of development
50 *
51 * Revision 1.2.2.1 2005/03/10 11:50:59 jonblower
52 * Changed to fit with MINA framework
53 *
54 * Revision 1.2 2005/02/24 07:44:44 jonblower
55 * Added getFriendlyString()
56 *
57 * Revision 1.1.1.1 2005/02/16 18:58:29 jonblower
58 * Initial import
59 *
60 */
61 public class TreadMessage extends StyxMessage
62 {
63
64 private long fid;
65 private ULong offset;
66 private int count;
67
68 /***
69 * Creates a new TreadMessage. This constructor will be called by the
70 * MessageRecognizer.
71 * @param length The total length of the message (including all header info)
72 * @param type The type of the message (a number between 100 and 127)
73 * @param tag The tag that identifies this message
74 */
75 public TreadMessage(int length, short type, int tag)
76 {
77 super(length, type, tag);
78 this.name = "Tread";
79 }
80
81 public TreadMessage(long fid, ULong offset, int count)
82 {
83 this(23, (short)116, 0);
84 this.fid = fid;
85 this.offset = offset;
86 if (count < 0)
87 {
88 throw new IllegalArgumentException("count < 0");
89 }
90 this.count = count;
91 }
92
93 protected final void decodeBody(StyxBuffer buf)
94 throws ProtocolViolationException
95 {
96 this.fid = buf.getUInt();
97 this.offset = buf.getULong();
98 long lngCount = buf.getUInt();
99 if (lngCount < 0 || lngCount > Integer.MAX_VALUE)
100 {
101 throw new ProtocolViolationException("Got illegal count of " + lngCount);
102 }
103
104 this.count = (int)lngCount;
105 }
106
107 protected final void encodeBody(StyxBuffer buf)
108 {
109 buf.putUInt(this.fid).putULong(this.offset).putUInt(this.count);
110 }
111
112 public long getFid()
113 {
114 return fid;
115 }
116
117 public void setFid(long fid)
118 {
119 this.fid = fid;
120 }
121
122 public ULong getOffset()
123 {
124 return offset;
125 }
126
127 public void setOffset(ULong offset)
128 {
129 this.offset = offset;
130 }
131
132 public int getCount()
133 {
134 return count;
135 }
136
137 public void setCount(int count)
138 {
139 this.count = count;
140 }
141
142 protected String getElements()
143 {
144 return ", " + this.fid + ", " + this.offset + ", " + this.count;
145 }
146
147 public String toFriendlyString()
148 {
149 return "fid: " + this.fid + ", offset: " + this.offset + ", count: "
150 + this.count;
151 }
152
153 }