KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > ext > benchsocket > BenchClientSocket


1 package org.objectweb.proactive.ext.benchsocket;
2
3 import java.io.IOException JavaDoc;
4 import java.io.InputStream JavaDoc;
5 import java.io.OutputStream JavaDoc;
6
7 import java.net.InetAddress JavaDoc;
8 import java.net.Socket JavaDoc;
9 import java.net.SocketAddress JavaDoc;
10 import java.net.SocketException JavaDoc;
11
12 import java.nio.channels.SocketChannel JavaDoc;
13
14
15 /**
16  *
17  * @author fabrice
18  *
19  * A wrapper to a real socket
20  * to measure the size of data sent
21  */

22 public class BenchClientSocket extends Socket JavaDoc {
23     private static int counter;
24     private Socket JavaDoc realSocket;
25     private BenchOutputStream output;
26     private BenchInputStream input;
27     private int number;
28
29     public BenchClientSocket() throws IOException JavaDoc {
30         this.realSocket = new Socket JavaDoc();
31         // this.output = this.createOutputStream();
32
// this.input = this.createInputStream();
33
this.createStreams();
34     }
35
36     public BenchClientSocket(Socket JavaDoc s) throws IOException JavaDoc {
37         this.realSocket =s;
38         // this.output = this.createOutputStream();
39
// this.input = this.createInputStream();
40
this.createStreams();
41     }
42     
43     public BenchClientSocket(String JavaDoc host, int port) throws IOException JavaDoc {
44         this.realSocket = new Socket JavaDoc(host, port);
45         // this.output = this.createOutputStream();
46
// this.input = this.createInputStream();
47
this.createStreams();
48     }
49
50     protected BenchOutputStream createOutputStream() throws IOException JavaDoc {
51         synchronized (BenchClientSocket.class) {
52             this.number = BenchClientSocket.counter;
53             BenchClientSocket.counter++;
54         }
55         return new BenchOutputStream(realSocket.getOutputStream(), this.number);
56     }
57
58     protected BenchInputStream createInputStream() throws IOException JavaDoc {
59         synchronized (BenchClientSocket.class) {
60             this.number = BenchClientSocket.counter;
61             BenchClientSocket.counter++;
62         }
63         return new BenchInputStream(realSocket.getInputStream(), this.number);
64     }
65
66     public void createStreams() throws IOException JavaDoc {
67         synchronized (BenchClientSocket.class) {
68             this.number = BenchClientSocket.counter;
69             BenchClientSocket.counter++;
70         }
71         this.output = new BenchOutputStream(realSocket.getOutputStream(),
72                 this.number);
73         ;
74         this.input = new BenchInputStream(realSocket.getInputStream(),
75                 this.number);
76     }
77
78     /* (non-Javadoc)
79      * @see java.net.Socket#bind(java.net.SocketAddress)
80      */

81     public void bind(SocketAddress JavaDoc bindpoint) throws IOException JavaDoc {
82         // Auto-generated method stub
83
this.realSocket.bind(bindpoint);
84     }
85
86     /* (non-Javadoc)
87      * @see java.net.Socket#close()
88      */

89     public synchronized void close() throws IOException JavaDoc {
90         // Auto-generated method stub
91
this.realSocket.close();
92     }
93
94     /* (non-Javadoc)
95      * @see java.net.Socket#connect(java.net.SocketAddress, int)
96      */

97     public void connect(SocketAddress JavaDoc endpoint, int timeout)
98         throws IOException JavaDoc {
99         this.realSocket.connect(endpoint, timeout);
100     }
101
102     /* (non-Javadoc)
103      * @see java.net.Socket#connect(java.net.SocketAddress)
104      */

105     public void connect(SocketAddress JavaDoc endpoint) throws IOException JavaDoc {
106         this.realSocket.connect(endpoint);
107     }
108
109     /* (non-Javadoc)
110      * @see java.net.Socket#getChannel()
111      */

112     public SocketChannel JavaDoc getChannel() {
113         return this.realSocket.getChannel();
114     }
115
116     /* (non-Javadoc)
117      * @see java.net.Socket#getInetAddress()
118      */

119     public InetAddress JavaDoc getInetAddress() {
120         return this.realSocket.getInetAddress();
121     }
122
123     /* (non-Javadoc)
124      * @see java.net.Socket#getInputStream()
125      */

126     public InputStream JavaDoc getInputStream() throws IOException JavaDoc {
127         // System.out.println("getInputtStream()");
128
// return this.realSocket.getInputStream();
129
return this.input;
130     }
131
132     /* (non-Javadoc)
133      * @see java.net.Socket#getKeepAlive()
134      */

135     public boolean getKeepAlive() throws SocketException JavaDoc {
136         return this.realSocket.getKeepAlive();
137     }
138
139     /* (non-Javadoc)
140      * @see java.net.Socket#getLocalAddress()
141      */

142     public InetAddress JavaDoc getLocalAddress() {
143         return this.realSocket.getLocalAddress();
144     }
145
146     /* (non-Javadoc)
147      * @see java.net.Socket#getLocalPort()
148      */

149     public int getLocalPort() {
150         return this.realSocket.getLocalPort();
151     }
152
153     /* (non-Javadoc)
154      * @see java.net.Socket#getLocalSocketAddress()
155      */

156     public SocketAddress JavaDoc getLocalSocketAddress() {
157         return this.realSocket.getLocalSocketAddress();
158     }
159
160     /* (non-Javadoc)
161      * @see java.net.Socket#getOOBInline()
162      */

163     public boolean getOOBInline() throws SocketException JavaDoc {
164         return this.realSocket.getOOBInline();
165     }
166
167     /* (non-Javadoc)
168      * @see java.net.Socket#getOutputStream()
169      */

170     public OutputStream JavaDoc getOutputStream() throws IOException JavaDoc {
171         // return this.realSocket.getOutputStream();
172
// System.out.println("getOutputStream()");
173
return this.output;
174     }
175
176     /* (non-Javadoc)
177      * @see java.net.Socket#getPort()
178      */

179     public int getPort() {
180         return this.realSocket.getPort();
181     }
182
183     /* (non-Javadoc)
184      * @see java.net.Socket#getReceiveBufferSize()
185      */

186     public synchronized int getReceiveBufferSize() throws SocketException JavaDoc {
187         return this.realSocket.getReceiveBufferSize();
188     }
189
190     /* (non-Javadoc)
191      * @see java.net.Socket#getRemoteSocketAddress()
192      */

193     public SocketAddress JavaDoc getRemoteSocketAddress() {
194         return this.realSocket.getRemoteSocketAddress();
195     }
196
197     /* (non-Javadoc)
198      * @see java.net.Socket#getReuseAddress()
199      */

200     public boolean getReuseAddress() throws SocketException JavaDoc {
201         return this.realSocket.getReuseAddress();
202     }
203
204     /* (non-Javadoc)
205      * @see java.net.Socket#getSendBufferSize()
206      */

207     public synchronized int getSendBufferSize() throws SocketException JavaDoc {
208         return this.realSocket.getSendBufferSize();
209     }
210
211     /* (non-Javadoc)
212      * @see java.net.Socket#getSoLinger()
213      */

214     public int getSoLinger() throws SocketException JavaDoc {
215         return this.realSocket.getSoLinger();
216     }
217
218     /* (non-Javadoc)
219      * @see java.net.Socket#getSoTimeout()
220      */

221     public synchronized int getSoTimeout() throws SocketException JavaDoc {
222         return this.realSocket.getSoTimeout();
223     }
224
225     /* (non-Javadoc)
226      * @see java.net.Socket#getTcpNoDelay()
227      */

228     public boolean getTcpNoDelay() throws SocketException JavaDoc {
229         return this.realSocket.getTcpNoDelay();
230     }
231
232     /* (non-Javadoc)
233      * @see java.net.Socket#getTrafficClass()
234      */

235     public int getTrafficClass() throws SocketException JavaDoc {
236         return this.realSocket.getTrafficClass();
237     }
238
239     /* (non-Javadoc)
240      * @see java.net.Socket#isBound()
241      */

242     public boolean isBound() {
243         return this.realSocket.isBound();
244     }
245
246     /* (non-Javadoc)
247      * @see java.net.Socket#isClosed()
248      */

249     public boolean isClosed() {
250         return this.realSocket.isClosed();
251     }
252
253     /* (non-Javadoc)
254      * @see java.net.Socket#isConnected()
255      */

256     public boolean isConnected() {
257         return this.realSocket.isConnected();
258     }
259
260     /* (non-Javadoc)
261      * @see java.net.Socket#isInputShutdown()
262      */

263     public boolean isInputShutdown() {
264         return this.realSocket.isInputShutdown();
265     }
266
267     /* (non-Javadoc)
268      * @see java.net.Socket#isOutputShutdown()
269      */

270     public boolean isOutputShutdown() {
271         return this.realSocket.isOutputShutdown();
272     }
273
274     /* (non-Javadoc)
275      * @see java.net.Socket#sendUrgentData(int)
276      */

277     public void sendUrgentData(int data) throws IOException JavaDoc {
278         this.realSocket.sendUrgentData(data);
279     }
280
281     /* (non-Javadoc)
282      * @see java.net.Socket#setKeepAlive(boolean)
283      */

284     public void setKeepAlive(boolean on) throws SocketException JavaDoc {
285         this.realSocket.setKeepAlive(on);
286     }
287
288     /* (non-Javadoc)
289      * @see java.net.Socket#setOOBInline(boolean)
290      */

291     public void setOOBInline(boolean on) throws SocketException JavaDoc {
292         this.realSocket.setOOBInline(on);
293     }
294
295     /* (non-Javadoc)
296      * @see java.net.Socket#setReceiveBufferSize(int)
297      */

298     public synchronized void setReceiveBufferSize(int size)
299         throws SocketException JavaDoc {
300         this.realSocket.setReceiveBufferSize(size);
301     }
302
303     /* (non-Javadoc)
304      * @see java.net.Socket#setReuseAddress(boolean)
305      */

306     public void setReuseAddress(boolean on) throws SocketException JavaDoc {
307         this.realSocket.setReuseAddress(on);
308     }
309
310     /* (non-Javadoc)
311      * @see java.net.Socket#setSendBufferSize(int)
312      */

313     public synchronized void setSendBufferSize(int size)
314         throws SocketException JavaDoc {
315         this.realSocket.setSendBufferSize(size);
316     }
317
318     /* (non-Javadoc)
319      * @see java.net.Socket#setSoLinger(boolean, int)
320      */

321     public void setSoLinger(boolean on, int linger) throws SocketException JavaDoc {
322         this.realSocket.setSoLinger(on, linger);
323     }
324
325     /* (non-Javadoc)
326      * @see java.net.Socket#setSoTimeout(int)
327      */

328     public synchronized void setSoTimeout(int timeout)
329         throws SocketException JavaDoc {
330         this.realSocket.setSoTimeout(timeout);
331     }
332
333     /* (non-Javadoc)
334      * @see java.net.Socket#setTcpNoDelay(boolean)
335      */

336     public void setTcpNoDelay(boolean on) throws SocketException JavaDoc {
337         this.realSocket.setTcpNoDelay(on);
338     }
339
340     /* (non-Javadoc)
341      * @see java.net.Socket#setTrafficClass(int)
342      */

343     public void setTrafficClass(int tc) throws SocketException JavaDoc {
344         this.realSocket.setTrafficClass(tc);
345     }
346
347     /* (non-Javadoc)
348      * @see java.net.Socket#shutdownInput()
349      */

350     public void shutdownInput() throws IOException JavaDoc {
351         this.realSocket.shutdownInput();
352     }
353
354     /* (non-Javadoc)
355      * @see java.net.Socket#shutdownOutput()
356      */

357     public void shutdownOutput() throws IOException JavaDoc {
358         this.realSocket.shutdownOutput();
359     }
360 }
361
Popular Tags