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.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 }