1 46 package org.mr.core.net; 47 48 import java.io.IOException ; 49 import java.net.SocketAddress ; 50 import java.net.InetAddress ; 51 import java.nio.channels.SocketChannel ; 52 53 import javax.net.ssl.SSLSocket; 54 55 import org.mr.MantaAgent; 56 import org.mr.indexing.WBManager; 57 import org.apache.commons.logging.Log; 58 import org.apache.commons.logging.LogFactory; 59 60 70 public class TransportProvider { 71 private static Log log = LogFactory.getLog("TransportProvider"); 72 73 public TransportProvider() { 74 } 76 86 public static TransportImpl createImpl(TransportType type, 87 SocketAddress local, 88 SocketAddress remote, 89 String remoteAgent, 90 Transport owner) 91 throws IOException 92 { 93 if(log.isInfoEnabled()){ 94 log.info("Creating " + type + " impl " + 95 (local != null ? local.toString() : "0.0.0.0:0") + 96 "--" +remote.toString()+"."); 97 } 98 99 if (type.equals(TransportType.TCP)) { 100 return new TCPTransportImpl(local, remote); 101 } else if(type.equals(TransportType.HTTP)) { 102 return new HTTPTransportImpl(local, remote); 103 } else if (type.equals(TransportType.SSL)) { 104 return new SSLTransportImpl(local, remote, owner); 105 } else if (type.equals(TransportType.MWB)) { 106 WBManager wblink = MantaAgent.getInstance(). 107 getSingletonRepository().getWBManager(); 108 if (wblink != null) { 109 return wblink.getIRSTransportImpl(local, remote); 110 } 111 } 112 113 return null; 115 } 116 117 124 public static TransportImpl createImpl(TransportType type, 125 SocketChannel channel) 126 throws IOException 127 { 128 if(log.isInfoEnabled()){ 129 log.info("Creating " + type + " impl from channel " +channel.socket().getLocalSocketAddress().toString() +"--" + channel.socket().getRemoteSocketAddress().toString()+"."); 130 } 131 132 if (type.equals(TransportType.TCP)) { 133 return new TCPTransportImpl(channel); 134 } else if(type.equals(TransportType.HTTP)) { 135 return new HTTPTransportImpl(channel); 136 } else if (type.equals(TransportType.MWB)) { 137 return new MWBTransportImpl(channel); 138 } else { 139 return null; 141 } 142 } 143 144 150 public static TransportImpl createImpl(TransportType type, SSLSocket socket) 151 throws IOException 152 { 153 if (type == TransportType.SSL) { 154 return new SSLTransportImpl(socket); 155 } 156 157 return null; 158 } 159 160 public static LocalTransport createLocalTransport(TransportType type, 161 InetAddress addr, 162 int portMin, 163 int portMax, 164 NetworkListener listener, 165 NetworkSelector selector) 166 throws IOException 167 { 168 if (type.equals(TransportType.SSL)) { 169 return new LocalSSLTransport(addr, portMin, portMax, listener); 170 } else if (type.equals(TransportType.HTTP) || 171 type.equals(TransportType.TCP) || 172 type.equals(TransportType.MWB)) { 173 return new LocalTCPTransport(type, addr, portMin, portMax, 174 selector); 175 } else { 176 throw new IllegalArgumentException ("Unsupported transport type: " + 177 type.toString()); 178 } 179 } 180 } | Popular Tags |