KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > fenyo > gnetwatch > IPQuerier


1
2 /*
3  * GNetWatch
4  * Copyright 2006, 2007 Alexandre Fenyo
5  * gnetwatch@fenyo.net
6  *
7  * This file is part of GNetWatch.
8  *
9  * GNetWatch is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * GNetWatch is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with GNetWatch; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22  */

23
24 package net.fenyo.gnetwatch;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 import java.net.*;
30 import java.io.*;
31
32 /**
33  * Instances of this class maintain IP options associated to IP targets.
34  * @author Alexandre Fenyo
35  * @version $Id: IPQuerier.java,v 1.9 2007/03/12 05:04:15 fenyo Exp $
36  */

37
38 public class IPQuerier {
39   private static Log log = LogFactory.getLog(IPQuerier.class);
40
41   private final InetAddress address;
42
43   private int tos = 0;
44   private int port_src = 10000;
45   private int port_dst = 10000;
46   private int pdu_max_size = 1400;
47
48   private boolean use_proxy = false;
49   private boolean reconnect = false;
50   private String JavaDoc proxy_host = "";
51   private int proxy_port = 3128;
52   private String JavaDoc URL = "";
53   private int nparallel = 1;
54
55   /**
56    * Constructor.
57    * @param address target address.
58    */

59   public IPQuerier(final InetAddress address) {
60     this.address = address;
61     if (Inet4Address.class.isInstance(address))
62       this.URL = "http://" + address.toString().substring(1) + ":80/";
63     if (Inet6Address.class.isInstance(address))
64       this.URL = "http://[" + address.toString().substring(1) + "]:80/";
65     parametersHaveChanged();
66   }
67
68   /**
69    * Must be called after some setters have been called.
70    * @param none.
71    * @return void.
72    */

73   public void update() {
74     parametersHaveChanged();
75   }
76
77   /**
78    * Must be called after some setters have been called.
79    * @param none.
80    * @return void.
81    */

82   // final since it is invoked from the constructor
83
private final void parametersHaveChanged() {}
84
85   /**
86    * Returns the TOS attribute.
87    * @param none.
88    * @return int TOS attribute.
89    */

90   public int getTOS() {
91     return tos;
92   }
93
94   /**
95    * Returns the address attribute.
96    * @param none.
97    * @return InetAddress address attribute.
98    */

99   public InetAddress getAddress() {
100     return address;
101   }
102
103   /**
104    * Returns the source port attribute.
105    * @param none.
106    * @return int source port attribute.
107    */

108   public int getPortSrc() {
109     return port_src;
110   }
111
112   /**
113    * Returns the destination port attribute.
114    * @param none.
115    * @return int destination port attribute.
116    */

117   public int getPortDst() {
118     return port_dst;
119   }
120
121   /**
122    * Returns the PDU maximum size attribute.
123    * @param none.
124    * @return int PDU maximum size attribute.
125    */

126   public int getPDUMaxSize() {
127     return pdu_max_size;
128   }
129
130   /**
131    * Checks that we must use the proxy.
132    * @param none.
133    * @return boolean true if we must use the proxy.
134    */

135   public boolean getUseProxy() {
136     return use_proxy;
137   }
138
139   /**
140    * Checks that we must make one connection per GET.
141    * @param none.
142    * @return boolean true if we must make one connection per GET.
143    */

144   public boolean getReconnect() {
145     return reconnect;
146   }
147
148   /**
149    * Returns the proxy host name.
150    * @param none.
151    * @return String proxy host name.
152    */

153   public String JavaDoc getProxyHost() {
154     return proxy_host;
155   }
156
157   /**
158    * Returns the TCP proxy port.
159    * @param none.
160    * @return String TCP proxy port.
161    */

162   public int getProxyPort() {
163     return proxy_port;
164   }
165
166   /**
167    * Returns the URL to connect to.
168    * @param none.
169    * @return String URL to connect to.
170    */

171   public String JavaDoc getURL() {
172     return URL;
173   }
174
175   /**
176    * Returns the number of simultaneous sessions.
177    * @param none.
178    * @return int number of simultaneous sessions..
179    */

180   public int getNParallel() {
181     return nparallel;
182   }
183
184   /**
185    * Set the TOS attribute.
186    * @param tos TOS attribute.
187    * @return void.
188    */

189   public void setTOS(final int tos) {
190     this.tos = tos;
191   }
192
193   /**
194    * Set the source port attribute.
195    * @param port_src source_port attribute.
196    * @return void.
197    */

198   public void setPortSrc(final int port_src) {
199     this.port_src = port_src;
200   }
201
202   /**
203    * Set the destination port attribute.
204    * @param port_dst destination_port attribute.
205    * @return void.
206    */

207   public void setPortDst(final int port_dst) {
208     this.port_dst = port_dst;
209   }
210
211   /**
212    * Set the PDU maximum size attribute.
213    * @param pdu_max_size PDU maximum size attribute.
214    * @return void.
215    */

216   public void setPDUMaxSize(final int pdu_max_size) {
217     this.pdu_max_size = pdu_max_size;
218   }
219
220   /**
221    * Sets it to true if we must use the proxy.
222    * @param use_proxy true if we must use the proxy.
223    * @return void.
224    */

225   public void setUseProxy(final boolean use_proxy) {
226     this.use_proxy = use_proxy;
227   }
228
229   /**
230    * Sets it to true if we must make a new connection for each GET.
231    * @param reconnect true if we must make a new connection for each GET.
232    * @return void.
233    */

234   public void setReconnect(final boolean reconnect) {
235     this.reconnect = reconnect;
236   }
237
238   /**
239    * Sets the proxy host name.
240    * @param proxy_host proxy host name.
241    * @return void.
242    */

243   public void setProxyHost(final String JavaDoc proxy_host) {
244     this.proxy_host = proxy_host;
245   }
246
247   /**
248    * Sets the TCP proxy port.
249    * @param proxy_port TCP proxy port.
250    * @return void.
251    */

252   public void setProxyPort(final int proxy_port) {
253     this.proxy_port = proxy_port;
254   }
255
256   /**
257    * Sets the URL to connect to.
258    * @param URL URL to connect to.
259    * @return void.
260    */

261   public void setURL(final String JavaDoc URL) {
262     this.URL = URL;
263   }
264
265   /**
266    * Sets the number of simultaneous sessions.
267    * @param nparallel number of simultaneous sessions.
268    * @return void.
269    */

270   public void setNParallel(final int nparallel) {
271     this.nparallel = nparallel;
272   }
273 }
274
Popular Tags