org/objectweb/proactive/ext/benchsocket/BenchIbisSocketFactory.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.ServerSocket;
00038 import java.net.Socket;
00039 import java.util.ArrayList;
00040 import java.util.Iterator;
00041 
00042 import ibis.util.IbisSocketFactory;
00043 
00044 
00045 public class BenchIbisSocketFactory extends IbisSocketFactory
00046     implements BenchFactoryInterface {
00047     protected static ArrayList<BenchStream> streamList = new ArrayList<BenchStream>();
00048 
00049     public void addStream(BenchStream s) {
00050         synchronized (streamList) {
00051             streamList.add(s);
00052         }
00053     }
00054 
00055     public static void dumpStreamIntermediateResults() {
00056         synchronized (streamList) {
00057             Iterator<BenchStream> it = streamList.iterator();
00058             while (it.hasNext()) {
00059                 it.next().dumpIntermediateResults();
00060             }
00061         }
00062     }
00063 
00064     public Socket accept(ServerSocket a) throws IOException {
00065         Socket s = a.accept();
00066         return s;
00067     }
00068 
00069     public void close(InputStream in, OutputStream out, Socket s) {
00070         try {
00071             if (in != null) {
00072                 in.close();
00073             }
00074             if (out != null) {
00075                 out.flush();
00076                 out.close();
00077             }
00078             if (s != null) {
00079                 s.close();
00080             }
00081         } catch (Exception e) {
00082             e.printStackTrace();
00083         }
00084     }
00085 
00086     public int allocLocalPort() {
00087         return 0;
00088     }
00089 
00090     public ServerSocket createServerSocket(int port, int backlog,
00091         InetAddress addr) throws IOException {
00092         return new BenchServerSocket(port, addr, this);
00093     }
00094 
00095     public Socket createSocket(InetAddress rAddr, int rPort)
00096         throws IOException {
00097         return new BenchClientSocket(rAddr, rPort, this);
00098     }
00099 
00100     public Socket createSocket(InetAddress dest, int port, InetAddress localIP,
00101         long timeoutMillis) throws IOException {
00102         return new BenchClientSocket(dest, port, this);
00103     }
00104 
00105     public ServerSocket createServerSocket(int port, InetAddress localAddress,
00106         boolean retry) throws IOException {
00107         return new BenchServerSocket(port, localAddress, this);
00108     }
00109 }

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