org/objectweb/proactive/ext/benchsocket/BenchClientSocket.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
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     /* (non-Javadoc)
00131      * @see java.net.Socket#connect(java.net.SocketAddress, int)
00132      */
00133     public void connect(SocketAddress endpoint, int timeout)
00134         throws IOException {
00135         this.realSocket.connect(endpoint, timeout);
00136     }
00137 
00138     /* (non-Javadoc)
00139      * @see java.net.Socket#connect(java.net.SocketAddress)
00140      */
00141     public void connect(SocketAddress endpoint) throws IOException {
00142         this.realSocket.connect(endpoint);
00143     }
00144 
00145     /* (non-Javadoc)
00146      * @see java.net.Socket#getChannel()
00147      */
00148     public SocketChannel getChannel() {
00149         return this.realSocket.getChannel();
00150     }
00151 
00152     /* (non-Javadoc)
00153      * @see java.net.Socket#getInetAddress()
00154      */
00155     public InetAddress getInetAddress() {
00156         return this.realSocket.getInetAddress();
00157     }
00158 
00159     /* (non-Javadoc)
00160      * @see java.net.Socket#getInputStream()
00161      */
00162     public InputStream getInputStream() throws IOException {
00163         //      System.out.println("getInputtStream()");
00164         //  return this.realSocket.getInputStream();
00165         return this.input;
00166     }
00167 
00168     /* (non-Javadoc)
00169      * @see java.net.Socket#getKeepAlive()
00170      */
00171     public boolean getKeepAlive() throws SocketException {
00172         return this.realSocket.getKeepAlive();
00173     }
00174 
00175     /* (non-Javadoc)
00176      * @see java.net.Socket#getLocalAddress()
00177      */
00178     public InetAddress getLocalAddress() {
00179         return this.realSocket.getLocalAddress();
00180     }
00181 
00182     /* (non-Javadoc)
00183      * @see java.net.Socket#getLocalPort()
00184      */
00185     public int getLocalPort() {
00186         return this.realSocket.getLocalPort();
00187     }
00188 
00189     /* (non-Javadoc)
00190      * @see java.net.Socket#getLocalSocketAddress()
00191      */
00192     public SocketAddress getLocalSocketAddress() {
00193         return this.realSocket.getLocalSocketAddress();
00194     }
00195 
00196     /* (non-Javadoc)
00197      * @see java.net.Socket#getOOBInline()
00198      */
00199     public boolean getOOBInline() throws SocketException {
00200         return this.realSocket.getOOBInline();
00201     }
00202 
00203     /* (non-Javadoc)
00204      * @see java.net.Socket#getOutputStream()
00205      */
00206     public OutputStream getOutputStream() throws IOException {
00207         //  return this.realSocket.getOutputStream();
00208         //      System.out.println("getOutputStream()");
00209         return this.output;
00210     }
00211 
00212     /* (non-Javadoc)
00213      * @see java.net.Socket#getPort()
00214      */
00215     public int getPort() {
00216         return this.realSocket.getPort();
00217     }
00218 
00219     /* (non-Javadoc)
00220      * @see java.net.Socket#getReceiveBufferSize()
00221      */
00222     public synchronized int getReceiveBufferSize() throws SocketException {
00223         return this.realSocket.getReceiveBufferSize();
00224     }
00225 
00226     /* (non-Javadoc)
00227      * @see java.net.Socket#getRemoteSocketAddress()
00228      */
00229     public SocketAddress getRemoteSocketAddress() {
00230         return this.realSocket.getRemoteSocketAddress();
00231     }
00232 
00233     /* (non-Javadoc)
00234      * @see java.net.Socket#getReuseAddress()
00235      */
00236     public boolean getReuseAddress() throws SocketException {
00237         return this.realSocket.getReuseAddress();
00238     }
00239 
00240     /* (non-Javadoc)
00241      * @see java.net.Socket#getSendBufferSize()
00242      */
00243     public synchronized int getSendBufferSize() throws SocketException {
00244         return this.realSocket.getSendBufferSize();
00245     }
00246 
00247     /* (non-Javadoc)
00248      * @see java.net.Socket#getSoLinger()
00249      */
00250     public int getSoLinger() throws SocketException {
00251         return this.realSocket.getSoLinger();
00252     }
00253 
00254     /* (non-Javadoc)
00255      * @see java.net.Socket#getSoTimeout()
00256      */
00257     public synchronized int getSoTimeout() throws SocketException {
00258         return this.realSocket.getSoTimeout();
00259     }
00260 
00261     /* (non-Javadoc)
00262      * @see java.net.Socket#getTcpNoDelay()
00263      */
00264     public boolean getTcpNoDelay() throws SocketException {
00265         return this.realSocket.getTcpNoDelay();
00266     }
00267 
00268     /* (non-Javadoc)
00269      * @see java.net.Socket#getTrafficClass()
00270      */
00271     public int getTrafficClass() throws SocketException {
00272         return this.realSocket.getTrafficClass();
00273     }
00274 
00275     /* (non-Javadoc)
00276      * @see java.net.Socket#isBound()
00277      */
00278     public boolean isBound() {
00279         return this.realSocket.isBound();
00280     }
00281 
00282     /* (non-Javadoc)
00283      * @see java.net.Socket#isClosed()
00284      */
00285     public boolean isClosed() {
00286         return this.realSocket.isClosed();
00287     }
00288 
00289     /* (non-Javadoc)
00290      * @see java.net.Socket#isConnected()
00291      */
00292     public boolean isConnected() {
00293         return this.realSocket.isConnected();
00294     }
00295 
00296     /* (non-Javadoc)
00297      * @see java.net.Socket#isInputShutdown()
00298      */
00299     public boolean isInputShutdown() {
00300         return this.realSocket.isInputShutdown();
00301     }
00302 
00303     /* (non-Javadoc)
00304      * @see java.net.Socket#isOutputShutdown()
00305      */
00306     public boolean isOutputShutdown() {
00307         return this.realSocket.isOutputShutdown();
00308     }
00309 
00310     /* (non-Javadoc)
00311      * @see java.net.Socket#sendUrgentData(int)
00312      */
00313     public void sendUrgentData(int data) throws IOException {
00314         this.realSocket.sendUrgentData(data);
00315     }
00316 
00317     /* (non-Javadoc)
00318      * @see java.net.Socket#setKeepAlive(boolean)
00319      */
00320     public void setKeepAlive(boolean on) throws SocketException {
00321         this.realSocket.setKeepAlive(on);
00322     }
00323 
00324     /* (non-Javadoc)
00325      * @see java.net.Socket#setOOBInline(boolean)
00326      */
00327     public void setOOBInline(boolean on) throws SocketException {
00328         this.realSocket.setOOBInline(on);
00329     }
00330 
00331     /* (non-Javadoc)
00332      * @see java.net.Socket#setReceiveBufferSize(int)
00333      */
00334     public synchronized void setReceiveBufferSize(int size)
00335         throws SocketException {
00336         this.realSocket.setReceiveBufferSize(size);
00337     }
00338 
00339     /* (non-Javadoc)
00340      * @see java.net.Socket#setReuseAddress(boolean)
00341      */
00342     public void setReuseAddress(boolean on) throws SocketException {
00343         this.realSocket.setReuseAddress(on);
00344     }
00345 
00346     /* (non-Javadoc)
00347      * @see java.net.Socket#setSendBufferSize(int)
00348      */
00349     public synchronized void setSendBufferSize(int size)
00350         throws SocketException {
00351         this.realSocket.setSendBufferSize(size);
00352     }
00353 
00354     /* (non-Javadoc)
00355      * @see java.net.Socket#setSoLinger(boolean, int)
00356      */
00357     public void setSoLinger(boolean on, int linger) throws SocketException {
00358         this.realSocket.setSoLinger(on, linger);
00359     }
00360 
00361     /* (non-Javadoc)
00362      * @see java.net.Socket#setSoTimeout(int)
00363      */
00364     public synchronized void setSoTimeout(int timeout)
00365         throws SocketException {
00366         this.realSocket.setSoTimeout(timeout);
00367     }
00368 
00369     /* (non-Javadoc)
00370      * @see java.net.Socket#setTcpNoDelay(boolean)
00371      */
00372     public void setTcpNoDelay(boolean on) throws SocketException {
00373         this.realSocket.setTcpNoDelay(on);
00374     }
00375 
00376     /* (non-Javadoc)
00377      * @see java.net.Socket#setTrafficClass(int)
00378      */
00379     public void setTrafficClass(int tc) throws SocketException {
00380         this.realSocket.setTrafficClass(tc);
00381     }
00382 
00383     /* (non-Javadoc)
00384      * @see java.net.Socket#shutdownInput()
00385      */
00386     public void shutdownInput() throws IOException {
00387         this.realSocket.shutdownInput();
00388     }
00389 
00390     /* (non-Javadoc)
00391      * @see java.net.Socket#shutdownOutput()
00392      */
00393     public void shutdownOutput() throws IOException {
00394         this.realSocket.shutdownOutput();
00395     }
00396 }

Generated on Mon Jan 22 15:16:10 2007 for ProActive by  doxygen 1.5.1