00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package org.objectweb.proactive.ext.benchsocket;
00032
00033 import java.io.IOException;
00034 import java.io.InputStream;
00035 import java.io.OutputStream;
00036 import java.net.InetAddress;
00037 import java.net.Socket;
00038 import java.net.SocketAddress;
00039 import java.net.SocketException;
00040 import java.nio.channels.SocketChannel;
00041
00042
00043 public class BenchClientSocket extends Socket {
00044 private static int counter;
00045 private Socket realSocket;
00046 private BenchOutputStream output;
00047 private BenchInputStream input;
00048 private int number;
00049 private BenchFactoryInterface parent;
00050
00051 public BenchClientSocket() throws IOException {
00052 synchronized (BenchClientSocket.class) {
00053 BenchClientSocket.counter++;
00054 this.number = BenchClientSocket.counter;
00055 this.realSocket = new Socket();
00056 this.createStreams();
00057 }
00058 }
00059
00060 public BenchClientSocket(Socket s, BenchFactoryInterface parent)
00061 throws IOException {
00062 synchronized (BenchClientSocket.class) {
00063 BenchClientSocket.counter++;
00064 this.number = BenchClientSocket.counter;
00065 this.realSocket = s;
00066 this.parent = parent;
00067 this.createStreams();
00068 }
00069 }
00070
00071 public BenchClientSocket(String host, int port, BenchFactoryInterface parent)
00072 throws IOException {
00073 synchronized (BenchClientSocket.class) {
00074 BenchClientSocket.counter++;
00075 this.number = BenchClientSocket.counter;
00076 this.realSocket = new Socket(host, port);
00077 this.parent = parent;
00078 this.createStreams();
00079 }
00080 }
00081
00082 public BenchClientSocket(InetAddress address, int port,
00083 BenchFactoryInterface parent) throws IOException {
00084 synchronized (BenchClientSocket.class) {
00085 BenchClientSocket.counter++;
00086 this.number = BenchClientSocket.counter;
00087 this.realSocket = new Socket(address, port);
00088 this.parent = parent;
00089 this.createStreams();
00090 }
00091 }
00092
00093 public void createStreams() throws IOException {
00094 synchronized (BenchClientSocket.class) {
00095 this.number = BenchClientSocket.counter;
00096 }
00097
00098 this.output = new BenchOutputStream(realSocket.getOutputStream(),
00099 this.number, this);
00100 this.parent.addStream(this.output);
00101
00102 this.input = new BenchInputStream(realSocket.getInputStream(),
00103 this.number, this);
00104 this.parent.addStream(this.input);
00105 }
00106
00107 public String toString() {
00108 return this.realSocket.toString();
00109 }
00110
00111 public void bind(SocketAddress bindpoint) throws IOException {
00112 this.realSocket.bind(bindpoint);
00113 }
00114
00115 public synchronized void close() throws IOException {
00116 if (this.input != null) {
00117 this.input.close();
00118 this.input = null;
00119 }
00120 if (this.output != null) {
00121 this.output.close();
00122 this.output = null;
00123 }
00124 if (this.realSocket != null) {
00125 this.realSocket.close();
00126 this.realSocket = null;
00127 }
00128 }
00129
00130
00131
00132
00133 public void connect(SocketAddress endpoint, int timeout)
00134 throws IOException {
00135 this.realSocket.connect(endpoint, timeout);
00136 }
00137
00138
00139
00140
00141 public void connect(SocketAddress endpoint) throws IOException {
00142 this.realSocket.connect(endpoint);
00143 }
00144
00145
00146
00147
00148 public SocketChannel getChannel() {
00149 return this.realSocket.getChannel();
00150 }
00151
00152
00153
00154
00155 public InetAddress getInetAddress() {
00156 return this.realSocket.getInetAddress();
00157 }
00158
00159
00160
00161
00162 public InputStream getInputStream() throws IOException {
00163
00164
00165 return this.input;
00166 }
00167
00168
00169
00170
00171 public boolean getKeepAlive() throws SocketException {
00172 return this.realSocket.getKeepAlive();
00173 }
00174
00175
00176
00177
00178 public InetAddress getLocalAddress() {
00179 return this.realSocket.getLocalAddress();
00180 }
00181
00182
00183
00184
00185 public int getLocalPort() {
00186 return this.realSocket.getLocalPort();
00187 }
00188
00189
00190
00191
00192 public SocketAddress getLocalSocketAddress() {
00193 return this.realSocket.getLocalSocketAddress();
00194 }
00195
00196
00197
00198
00199 public boolean getOOBInline() throws SocketException {
00200 return this.realSocket.getOOBInline();
00201 }
00202
00203
00204
00205
00206 public OutputStream getOutputStream() throws IOException {
00207
00208
00209 return this.output;
00210 }
00211
00212
00213
00214
00215 public int getPort() {
00216 return this.realSocket.getPort();
00217 }
00218
00219
00220
00221
00222 public synchronized int getReceiveBufferSize() throws SocketException {
00223 return this.realSocket.getReceiveBufferSize();
00224 }
00225
00226
00227
00228
00229 public SocketAddress getRemoteSocketAddress() {
00230 return this.realSocket.getRemoteSocketAddress();
00231 }
00232
00233
00234
00235
00236 public boolean getReuseAddress() throws SocketException {
00237 return this.realSocket.getReuseAddress();
00238 }
00239
00240
00241
00242
00243 public synchronized int getSendBufferSize() throws SocketException {
00244 return this.realSocket.getSendBufferSize();
00245 }
00246
00247
00248
00249
00250 public int getSoLinger() throws SocketException {
00251 return this.realSocket.getSoLinger();
00252 }
00253
00254
00255
00256
00257 public synchronized int getSoTimeout() throws SocketException {
00258 return this.realSocket.getSoTimeout();
00259 }
00260
00261
00262
00263
00264 public boolean getTcpNoDelay() throws SocketException {
00265 return this.realSocket.getTcpNoDelay();
00266 }
00267
00268
00269
00270
00271 public int getTrafficClass() throws SocketException {
00272 return this.realSocket.getTrafficClass();
00273 }
00274
00275
00276
00277
00278 public boolean isBound() {
00279 return this.realSocket.isBound();
00280 }
00281
00282
00283
00284
00285 public boolean isClosed() {
00286 return this.realSocket.isClosed();
00287 }
00288
00289
00290
00291
00292 public boolean isConnected() {
00293 return this.realSocket.isConnected();
00294 }
00295
00296
00297
00298
00299 public boolean isInputShutdown() {
00300 return this.realSocket.isInputShutdown();
00301 }
00302
00303
00304
00305
00306 public boolean isOutputShutdown() {
00307 return this.realSocket.isOutputShutdown();
00308 }
00309
00310
00311
00312
00313 public void sendUrgentData(int data) throws IOException {
00314 this.realSocket.sendUrgentData(data);
00315 }
00316
00317
00318
00319
00320 public void setKeepAlive(boolean on) throws SocketException {
00321 this.realSocket.setKeepAlive(on);
00322 }
00323
00324
00325
00326
00327 public void setOOBInline(boolean on) throws SocketException {
00328 this.realSocket.setOOBInline(on);
00329 }
00330
00331
00332
00333
00334 public synchronized void setReceiveBufferSize(int size)
00335 throws SocketException {
00336 this.realSocket.setReceiveBufferSize(size);
00337 }
00338
00339
00340
00341
00342 public void setReuseAddress(boolean on) throws SocketException {
00343 this.realSocket.setReuseAddress(on);
00344 }
00345
00346
00347
00348
00349 public synchronized void setSendBufferSize(int size)
00350 throws SocketException {
00351 this.realSocket.setSendBufferSize(size);
00352 }
00353
00354
00355
00356
00357 public void setSoLinger(boolean on, int linger) throws SocketException {
00358 this.realSocket.setSoLinger(on, linger);
00359 }
00360
00361
00362
00363
00364 public synchronized void setSoTimeout(int timeout)
00365 throws SocketException {
00366 this.realSocket.setSoTimeout(timeout);
00367 }
00368
00369
00370
00371
00372 public void setTcpNoDelay(boolean on) throws SocketException {
00373 this.realSocket.setTcpNoDelay(on);
00374 }
00375
00376
00377
00378
00379 public void setTrafficClass(int tc) throws SocketException {
00380 this.realSocket.setTrafficClass(tc);
00381 }
00382
00383
00384
00385
00386 public void shutdownInput() throws IOException {
00387 this.realSocket.shutdownInput();
00388 }
00389
00390
00391
00392
00393 public void shutdownOutput() throws IOException {
00394 this.realSocket.shutdownOutput();
00395 }
00396 }