add ListPersistentRequests and WatchGlobal command
[jSite2.git] / src / net / pterodactylus / util / fcp / NodeHello.java
1 /**
2  * © 2008 INA Service GmbH
3  */
4 package net.pterodactylus.util.fcp;
5
6
7 /**
8  * Some convenience methods for parsing a “NodeHello” message from the node.
9  * 
10  * @author <a href="mailto:dr@ina-germany.de">David Roden</a>
11  * @version $Id$
12  */
13 public class NodeHello extends BaseMessage {
14
15         /**
16          * Createa a new “NodeHello” message that wraps the received message.
17          * 
18          * @param receivedMessage
19          *            The received FCP message
20          */
21         public NodeHello(FcpMessage receivedMessage) {
22                 super(receivedMessage);
23         }
24
25         /**
26          * Returns the build of the node. This may not be a number but also a string
27          * like “@custom@” in case you built the node yourself.
28          * 
29          * @return The build of the node
30          */
31         public String getBuild() {
32                 return getField("Build");
33         }
34
35         /**
36          * Returns the build number of the node. This may not be a number but also a
37          * string like “@custom@” in case you built the node yourself.
38          * 
39          * @return The build number of the node, or <code>-1</code> if the build
40          *         number could not be determined
41          */
42         public int getBuildNumber() {
43                 String build = getBuild();
44                 try {
45                         return Integer.valueOf(build);
46                 } catch (NumberFormatException nfe1) {
47                         /* ignore. */
48                 }
49                 return -1;
50         }
51
52         /**
53          * Returns the number of compression codecs.
54          * 
55          * @return The number of compression codecs
56          */
57         public String getCompressionCodecs() {
58                 return getField("CompressionCodecs");
59         }
60
61         /**
62          * Returns the number of compression codecs.
63          * 
64          * @return The number of compression codecs, or <code>-1</code> if the
65          *         number of compression codecs could not be determined
66          */
67         public int getCompressionCodecsNumber() {
68                 String compressionCodecs = getCompressionCodecs();
69                 try {
70                         return Integer.valueOf(compressionCodecs);
71                 } catch (NumberFormatException nfe1) {
72                         /* ignore. */
73                 }
74                 return -1;
75         }
76
77         /**
78          * Returns the unique connection identifier.
79          * 
80          * @return The connection identifier
81          */
82         public String getConnectionIdentifier() {
83                 return getField("ConnectionIdentifier");
84         }
85
86         /**
87          * Returns the build of the external library file.
88          * 
89          * @return The build of the external library file
90          */
91         public String getExtBuild() {
92                 return getField("ExtBuild");
93         }
94
95         /**
96          * Returns the build number of the external library file.
97          * 
98          * @return The build number of the external library file, or <code>-1</code>
99          *         if the build number could not be determined
100          */
101         public int getExtBuildNumber() {
102                 String extBuild = getExtBuild();
103                 try {
104                         return Integer.valueOf(extBuild);
105                 } catch (NumberFormatException nfe1) {
106                         /* ignore. */
107                 }
108                 return -1;
109         }
110
111         /**
112          * Returns the revision of the external library file.
113          * 
114          * @return The revision of the external library file
115          */
116         public String getExtRevision() {
117                 return getField("ExtRevision");
118         }
119
120         /**
121          * Returns the revision number of the external library file.
122          * 
123          * @return The revision number of the external library file, or
124          *         <code>-1</code> if the revision number could not be determined
125          */
126         public int getExtRevisionNumber() {
127                 String extRevision = getExtRevision();
128                 try {
129                         return Integer.valueOf(extRevision);
130                 } catch (NumberFormatException nfe1) {
131                         /* ignore. */
132                 }
133                 return -1;
134         }
135
136         /**
137          * Returns the FCP version the node speaks.
138          * 
139          * @return The FCP version the node speaks
140          */
141         public String getFCPVersion() {
142                 return getField("FCPVersion");
143         }
144
145         /**
146          * Returns the make of the node, e.g. “Fred” (freenet reference
147          * implementation).
148          * 
149          * @return The make of the node
150          */
151         public String getNode() {
152                 return getField("Node");
153         }
154
155         /**
156          * Returns the language of the node as 2-letter code, e.g. “en” or “de”.
157          * 
158          * @return The language of the node
159          */
160         public String getNodeLanguage() {
161                 return getField("NodeLanguage");
162         }
163
164         /**
165          * Returns the revision of the node.
166          * 
167          * @return The revision of the node
168          */
169         public String getRevision() {
170                 return getField("Revision");
171         }
172
173         /**
174          * Returns the revision number of the node.
175          * 
176          * @return The revision number of the node, or <code>-1</code> if the
177          *         revision number coult not be determined
178          */
179         public int getRevisionNumber() {
180                 String revision = getRevision();
181                 try {
182                         return Integer.valueOf(revision);
183                 } catch (NumberFormatException nfe1) {
184                         /* ignore. */
185                 }
186                 return -1;
187         }
188
189         /**
190          * Returns whether the node is currently is testnet mode.
191          * 
192          * @return <code>true</code> if the node is currently in testnet mode,
193          *         <code>false</code> otherwise
194          */
195         public boolean getTestnet() {
196                 return Boolean.valueOf(getField("Testnet"));
197         }
198
199         /**
200          * Returns the version of the node.
201          * 
202          * @return The version of the node
203          */
204         public String getVersion() {
205                 return getField("Version");
206         }
207
208 }