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 uk.ac.rdg.resc.jstyx.StyxUtils;
32
33 /***
34 * Message sent to negotiate the protocol version and maximum message size of a
35 * Styx Connection
36 *
37 * @author Jon Blower
38 * $Revision: 507 $
39 * $Date: 2005-12-01 08:21:56 +0000 (Thu, 01 Dec 2005) $
40 * $Log$
41 * Revision 1.5 2005/12/01 08:21:56 jonblower
42 * Fixed javadoc comments
43 *
44 * Revision 1.4 2005/03/15 09:01:48 jonblower
45 * Message type now stored as short, not int
46 *
47 * Revision 1.3 2005/03/11 14:02:16 jonblower
48 * Merged MINA-Test_20059309 into main line of development
49 *
50 * Revision 1.2.2.1 2005/03/10 11:50:59 jonblower
51 * Changed to fit with MINA framework
52 *
53 * Revision 1.1 2005/03/09 16:58:42 jonblower
54 * Changes to MINA-related classes
55 *
56 * Revision 1.2 2005/02/24 07:44:44 jonblower
57 * Added getFriendlyString()
58 *
59 * Revision 1.1.1.1 2005/02/16 18:58:29 jonblower
60 * Initial import
61 *
62 */
63 public class TversionMessage extends StyxMessage
64 {
65
66 private long maxMessageSize;
67
68 private String version;
69
70 /***
71 * Creates a new TversionMessage. This constructor will be called by the
72 * StyxMessage.createStyxMessage() method
73 * @param length The total length of the message (including all header info)
74 * @param type The type of the message (a number between 100 and 127)
75 * @param tag The tag that identifies this message
76 */
77 public TversionMessage(int length, short type, int tag)
78 {
79 super(length, type, tag);
80 this.name = "Tversion";
81 }
82
83 /***
84 * Default constructor, sets version to "9P2000" and maximum message size
85 * to 8216 (so that 8192 bytes can be read or written with a Tread/Twrite)
86 */
87 public TversionMessage()
88 {
89 this(19, (short)100, StyxUtils.NOTAG);
90 this.maxMessageSize = 8216;
91 this.setVersion("9P2000");
92 }
93
94 /***
95 * Creates a new TversionMessage, with the supplied maximum message size.
96 * Sets the version to "9P2000"
97 * @param maxMessageSize The requested maximum size of a message that will
98 * be sent on this connection by either party
99 */
100 public TversionMessage(long maxMessageSize)
101 {
102 this();
103 this.maxMessageSize = maxMessageSize;
104 }
105
106 /***
107 * Creates a new TversionMessage, with the supplied maximum message size
108 * and version string. Note that the version string should always be "9P2000";
109 * this constructor is used mainly for debugging.
110 * @param maxMessageSize The requested maximum size of a message that will
111 * be sent on this connection by either party
112 * @param protocolVersion The version string (Should always be "9P2000")
113 */
114 public TversionMessage(long maxMessageSize, String protocolVersion)
115 {
116 this();
117 this.maxMessageSize = maxMessageSize;
118 this.setVersion(protocolVersion);
119 }
120
121 protected final void decodeBody(StyxBuffer styxBuf)
122 {
123
124 this.maxMessageSize = styxBuf.getUInt();
125
126 this.version = styxBuf.getString();
127 }
128
129 protected final void encodeBody(StyxBuffer styxBuf)
130 {
131
132 styxBuf.putUInt(this.maxMessageSize).putString(this.version);
133 }
134
135 /***
136 * @return The requested maximum size of a message that will
137 * be sent on this connection by either party
138 */
139 public long getMaxMessageSize()
140 {
141 return this.maxMessageSize;
142 }
143
144 /***
145 * @param maxMessageSize The requested maximum size of a message that will
146 * be sent on this connection by either party
147 */
148 public void setMaxMessageSize(long maxMessageSize)
149 {
150 this.maxMessageSize = maxMessageSize;
151 }
152
153 /***
154 * @return The version string (normally "9P2000")
155 */
156 public String getVersion()
157 {
158 return this.version;
159 }
160
161 /***
162 * @param version The version string (normally "9P2000")
163 */
164 public void setVersion(String version)
165 {
166 this.version = version;
167 int versionLen = StyxUtils.strToUTF8(version).length;
168 this.length = StyxUtils.HEADER_LENGTH + 4 + 2 + versionLen;
169 }
170
171 protected String getElements()
172 {
173 return ", " + this.maxMessageSize + ", " + this.version;
174 }
175
176 public String toFriendlyString()
177 {
178 return "Max msg size: " + this.maxMessageSize + " bytes, version = "
179 + this.version;
180 }
181
182 }