1 52 53 package com.go.trove.net; 54 55 import java.net.*; 56 57 72 public class LazySocketFactory implements SocketFactory { 73 private final SocketFactory mFactory; 74 75 public LazySocketFactory(SocketFactory factory) { 76 mFactory = factory; 77 } 78 79 public InetAddressAndPort getInetAddressAndPort() { 80 return mFactory.getInetAddressAndPort(); 81 } 82 83 public InetAddressAndPort getInetAddressAndPort(Object session) { 84 return mFactory.getInetAddressAndPort(session); 85 } 86 87 public long getDefaultTimeout() { 88 return mFactory.getDefaultTimeout(); 89 } 90 91 public CheckedSocket createSocket() 92 throws ConnectException, SocketException 93 { 94 return mFactory.createSocket(); 95 } 96 97 public CheckedSocket createSocket(Object session) 98 throws ConnectException, SocketException 99 { 100 return mFactory.createSocket(session); 101 } 102 103 public CheckedSocket createSocket(long timeout) 104 throws ConnectException, SocketException 105 { 106 return mFactory.createSocket(timeout); 107 } 108 109 public CheckedSocket createSocket(Object session, long timeout) 110 throws ConnectException, SocketException 111 { 112 return mFactory.createSocket(session, timeout); 113 } 114 115 118 public CheckedSocket getSocket() throws ConnectException, SocketException { 119 return CheckedSocket.check(new LazySocket(mFactory)); 120 } 121 122 125 public CheckedSocket getSocket(Object session) 126 throws ConnectException, SocketException 127 { 128 return CheckedSocket.check(new LazySocket(mFactory, session)); 129 } 130 131 134 public CheckedSocket getSocket(long timeout) 135 throws ConnectException, SocketException 136 { 137 return CheckedSocket.check(new LazySocket(mFactory, timeout)); 138 } 139 140 143 public CheckedSocket getSocket(Object session, long timeout) 144 throws ConnectException, SocketException 145 { 146 return CheckedSocket.check(new LazySocket(mFactory, session, timeout)); 147 } 148 149 public void recycleSocket(CheckedSocket cs) 150 throws SocketException, IllegalArgumentException 151 { 152 if (cs == null) { 153 return; 154 } 155 156 158 Socket s = cs.mSocket; 159 if (s instanceof LazySocket) { 160 cs = ((LazySocket)s).recycle(); 161 if (cs == null) { 162 return; 163 } 164 } 165 166 mFactory.recycleSocket(cs); 167 } 168 169 public void clear() { 170 mFactory.clear(); 171 } 172 173 public int getAvailableCount(){ 174 return mFactory.getAvailableCount(); 175 } 176 } 177 | Popular Tags |