1 52 53 package com.go.trove.net; 54 55 import java.net.*; 56 57 66 public class PlainSocketFactory implements SocketFactory { 67 private final InetAddress mAddr; 68 private final int mPort; 69 private final long mTimeout; 70 71 77 public PlainSocketFactory(InetAddress addr, int port, long timeout) { 78 mAddr = addr; 79 mPort = port; 80 mTimeout = timeout; 81 } 82 83 public InetAddressAndPort getInetAddressAndPort() { 84 return new InetAddressAndPort(mAddr, mPort); 85 } 86 87 public InetAddressAndPort getInetAddressAndPort(Object session) { 88 return getInetAddressAndPort(); 89 } 90 91 public long getDefaultTimeout() { 92 return mTimeout; 93 } 94 95 public CheckedSocket createSocket() 96 throws ConnectException, SocketException 97 { 98 return createSocket(mTimeout); 99 } 100 101 public CheckedSocket createSocket(Object session) 102 throws ConnectException, SocketException 103 { 104 return createSocket(mTimeout); 105 } 106 107 public CheckedSocket createSocket(long timeout) 108 throws ConnectException, SocketException 109 { 110 Socket socket = SocketConnector.connect(mAddr, mPort, timeout); 111 if (socket == null) { 112 throw new ConnectException("Connect timeout expired: " + timeout); 113 } 114 return CheckedSocket.check(socket); 115 } 116 117 public CheckedSocket createSocket(Object session, long timeout) 118 throws ConnectException, SocketException 119 { 120 return createSocket(timeout); 121 } 122 123 public CheckedSocket getSocket() throws ConnectException, SocketException { 124 return createSocket(mTimeout); 125 } 126 127 public CheckedSocket getSocket(Object session) 128 throws ConnectException, SocketException 129 { 130 return createSocket(mTimeout); 131 } 132 133 public CheckedSocket getSocket(long timeout) 134 throws ConnectException, SocketException 135 { 136 return createSocket(timeout); 137 } 138 139 public CheckedSocket getSocket(Object session, long timeout) 140 throws ConnectException, SocketException 141 { 142 return createSocket(timeout); 143 } 144 145 public void recycleSocket(CheckedSocket socket) 146 throws SocketException, IllegalArgumentException 147 { 148 if (socket != null) { 149 try { 150 socket.close(); 151 } 152 catch (java.io.IOException e) { 153 throw new SocketException(e.getMessage()); 154 } 155 } 156 } 157 158 public void clear() { 159 } 160 161 public int getAvailableCount() { 162 return 0; 163 } 164 } 165 | Popular Tags |