| 1 | |
package ca.uhn.hl7v2.util; |
| 2 | |
|
| 3 | |
import java.io.IOException; |
| 4 | |
import java.net.ServerSocket; |
| 5 | |
import java.net.Socket; |
| 6 | |
import java.net.SocketException; |
| 7 | |
|
| 8 | 5605 | public class StandardSocketFactory implements SocketFactory { |
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
public static final int DEFAULT_ACCEPTED_SOCKET_TIMEOUT = 500; |
| 14 | |
|
| 15 | 5605 | private int myAcceptedSocketTimeout = DEFAULT_ACCEPTED_SOCKET_TIMEOUT; |
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
public int getAcceptedSocketTimeout() { |
| 21 | 0 | return myAcceptedSocketTimeout; |
| 22 | |
} |
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
public void setAcceptedSocketTimeout(int theAcceptedSocketTimeout) { |
| 28 | 0 | if (theAcceptedSocketTimeout < 0) { |
| 29 | 0 | throw new IllegalArgumentException("Timeout can't be negative"); |
| 30 | |
} |
| 31 | 0 | myAcceptedSocketTimeout = theAcceptedSocketTimeout; |
| 32 | 0 | } |
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
public Socket createSocket() throws IOException { |
| 38 | 350 | Socket retVal = javax.net.SocketFactory.getDefault().createSocket(); |
| 39 | 350 | retVal.setKeepAlive(true); |
| 40 | 350 | retVal.setTcpNoDelay(true); |
| 41 | 350 | return retVal; |
| 42 | |
} |
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
public Socket createTlsSocket() throws IOException { |
| 48 | 0 | Socket retVal = javax.net.ssl.SSLSocketFactory.getDefault().createSocket(); |
| 49 | 0 | retVal.setKeepAlive(true); |
| 50 | 0 | retVal.setTcpNoDelay(true); |
| 51 | 0 | return retVal; |
| 52 | |
} |
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
public ServerSocket createServerSocket() throws IOException { |
| 58 | 160 | return javax.net.ServerSocketFactory.getDefault().createServerSocket(); |
| 59 | |
} |
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
public ServerSocket createTlsServerSocket() throws IOException { |
| 65 | 0 | return javax.net.ssl.SSLServerSocketFactory.getDefault().createServerSocket(); |
| 66 | |
} |
| 67 | |
|
| 68 | |
public void configureNewAcceptedSocket(Socket theSocket) throws SocketException { |
| 69 | 305 | theSocket.setSoTimeout(myAcceptedSocketTimeout); |
| 70 | 305 | } |
| 71 | |
|
| 72 | |
} |