1 package org.objectweb.proactive.ext.benchsocket; 2 3 import java.io.IOException ; 4 import java.io.InputStream ; 5 import java.io.OutputStream ; 6 7 import java.net.InetAddress ; 8 import java.net.Socket ; 9 import java.net.SocketAddress ; 10 import java.net.SocketException ; 11 12 import java.nio.channels.SocketChannel ; 13 14 15 22 public class BenchClientSocket extends Socket { 23 private static int counter; 24 private Socket realSocket; 25 private BenchOutputStream output; 26 private BenchInputStream input; 27 private int number; 28 29 public BenchClientSocket() throws IOException { 30 this.realSocket = new Socket (); 31 this.createStreams(); 34 } 35 36 public BenchClientSocket(Socket s) throws IOException { 37 this.realSocket =s; 38 this.createStreams(); 41 } 42 43 public BenchClientSocket(String host, int port) throws IOException { 44 this.realSocket = new Socket (host, port); 45 this.createStreams(); 48 } 49 50 protected BenchOutputStream createOutputStream() throws IOException { 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 { 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 { 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 81 public void bind(SocketAddress bindpoint) throws IOException { 82 this.realSocket.bind(bindpoint); 84 } 85 86 89 public synchronized void close() throws IOException { 90 this.realSocket.close(); 92 } 93 94 97 public void connect(SocketAddress endpoint, int timeout) 98 throws IOException { 99 this.realSocket.connect(endpoint, timeout); 100 } 101 102 105 public void connect(SocketAddress endpoint) throws IOException { 106 this.realSocket.connect(endpoint); 107 } 108 109 112 public SocketChannel getChannel() { 113 return this.realSocket.getChannel(); 114 } 115 116 119 public InetAddress getInetAddress() { 120 return this.realSocket.getInetAddress(); 121 } 122 123 126 public InputStream getInputStream() throws IOException { 127 return this.input; 130 } 131 132 135 public boolean getKeepAlive() throws SocketException { 136 return this.realSocket.getKeepAlive(); 137 } 138 139 142 public InetAddress getLocalAddress() { 143 return this.realSocket.getLocalAddress(); 144 } 145 146 149 public int getLocalPort() { 150 return this.realSocket.getLocalPort(); 151 } 152 153 156 public SocketAddress getLocalSocketAddress() { 157 return this.realSocket.getLocalSocketAddress(); 158 } 159 160 163 public boolean getOOBInline() throws SocketException { 164 return this.realSocket.getOOBInline(); 165 } 166 167 170 public OutputStream getOutputStream() throws IOException { 171 return this.output; 174 } 175 176 179 public int getPort() { 180 return this.realSocket.getPort(); 181 } 182 183 186 public synchronized int getReceiveBufferSize() throws SocketException { 187 return this.realSocket.getReceiveBufferSize(); 188 } 189 190 193 public SocketAddress getRemoteSocketAddress() { 194 return this.realSocket.getRemoteSocketAddress(); 195 } 196 197 200 public boolean getReuseAddress() throws SocketException { 201 return this.realSocket.getReuseAddress(); 202 } 203 204 207 public synchronized int getSendBufferSize() throws SocketException { 208 return this.realSocket.getSendBufferSize(); 209 } 210 211 214 public int getSoLinger() throws SocketException { 215 return this.realSocket.getSoLinger(); 216 } 217 218 221 public synchronized int getSoTimeout() throws SocketException { 222 return this.realSocket.getSoTimeout(); 223 } 224 225 228 public boolean getTcpNoDelay() throws SocketException { 229 return this.realSocket.getTcpNoDelay(); 230 } 231 232 235 public int getTrafficClass() throws SocketException { 236 return this.realSocket.getTrafficClass(); 237 } 238 239 242 public boolean isBound() { 243 return this.realSocket.isBound(); 244 } 245 246 249 public boolean isClosed() { 250 return this.realSocket.isClosed(); 251 } 252 253 256 public boolean isConnected() { 257 return this.realSocket.isConnected(); 258 } 259 260 263 public boolean isInputShutdown() { 264 return this.realSocket.isInputShutdown(); 265 } 266 267 270 public boolean isOutputShutdown() { 271 return this.realSocket.isOutputShutdown(); 272 } 273 274 277 public void sendUrgentData(int data) throws IOException { 278 this.realSocket.sendUrgentData(data); 279 } 280 281 284 public void setKeepAlive(boolean on) throws SocketException { 285 this.realSocket.setKeepAlive(on); 286 } 287 288 291 public void setOOBInline(boolean on) throws SocketException { 292 this.realSocket.setOOBInline(on); 293 } 294 295 298 public synchronized void setReceiveBufferSize(int size) 299 throws SocketException { 300 this.realSocket.setReceiveBufferSize(size); 301 } 302 303 306 public void setReuseAddress(boolean on) throws SocketException { 307 this.realSocket.setReuseAddress(on); 308 } 309 310 313 public synchronized void setSendBufferSize(int size) 314 throws SocketException { 315 this.realSocket.setSendBufferSize(size); 316 } 317 318 321 public void setSoLinger(boolean on, int linger) throws SocketException { 322 this.realSocket.setSoLinger(on, linger); 323 } 324 325 328 public synchronized void setSoTimeout(int timeout) 329 throws SocketException { 330 this.realSocket.setSoTimeout(timeout); 331 } 332 333 336 public void setTcpNoDelay(boolean on) throws SocketException { 337 this.realSocket.setTcpNoDelay(on); 338 } 339 340 343 public void setTrafficClass(int tc) throws SocketException { 344 this.realSocket.setTrafficClass(tc); 345 } 346 347 350 public void shutdownInput() throws IOException { 351 this.realSocket.shutdownInput(); 352 } 353 354 357 public void shutdownOutput() throws IOException { 358 this.realSocket.shutdownOutput(); 359 } 360 } 361 | Popular Tags |