Author: asmuts Date: Fri May 22 20:39:25 2009 New Revision: 777699 URL: http://svn.apache.org/viewvc?rev=777699&view=rev Log: Made "openTimeOut" and "socketTimeOut" configurable on the TCP Lateral.
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPSender.java jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/TCPLateralCacheAttributes.java jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/behavior/ITCPLateralCacheAttributes.java jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/utils/SocketOpener.java jakarta/jcs/trunk/src/test-conf/TestTCPLateralCache.ccf jakarta/jcs/trunk/xdocs/LateralTCPProperties.xml jakarta/jcs/trunk/xdocs/changes.xml Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPSender.java URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPSender.java?rev=777699&r1=777698&r2=777699&view=diff ============================================================================== --- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPSender.java (original) +++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPSender.java Fri May 22 20:39:25 2009 @@ -75,15 +75,6 @@ /** How often we need to reset the stream. */ private final static int RESET_FREQUENCY = 70; - /** - * Only block for 1 second before timing out on a read. TODO: make configurable. The default 1 - * is way too long. - */ - private final static int timeOut = 1000; - - /** Only block for 5 seconds before timing out on startup. */ - private final static int openTimeOut = 5000; - /** Use to synchronize multiple threads that may be trying to get. */ private Object getLock = new int[0]; @@ -140,14 +131,14 @@ } // have time out socket open do this for us - socket = SocketOpener.openSocket( host, port, openTimeOut ); + socket = SocketOpener.openSocket( host, port, tcpLateralCacheAttributes.getOpenTimeOut() ); if ( socket == null ) { throw new IOException( "Socket is null, cannot connect to " + host + ":" + port ); } - socket.setSoTimeout( LateralTCPSender.timeOut ); + socket.setSoTimeout( tcpLateralCacheAttributes.getSocketTimeOut() ); synchronized ( this ) { oos = new ObjectOutputStream( socket.getOutputStream() ); Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/TCPLateralCacheAttributes.java URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/TCPLateralCacheAttributes.java?rev=777699&r1=777698&r2=777699&view=diff ============================================================================== --- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/TCPLateralCacheAttributes.java (original) +++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/TCPLateralCacheAttributes.java Fri May 22 20:39:25 2009 @@ -55,6 +55,12 @@ /** default */ private static final boolean DEFAULT_FILTER_REMOVE_BY_HASH_CODE = true; + /** default - Only block for 1 second before timing out on a read.*/ + private static final int DEFAULT_SOCKET_TIME_OUT = 1000; + + /** default - Only block for 2 seconds before timing out on startup.*/ + private static final int DEFAULT_OPEN_TIMEOUT = 2000; + /** TCP -------------------------------------------- */ private String tcpServers = ""; @@ -84,7 +90,13 @@ /** don't remove it the hashcode is the same */ private boolean filterRemoveByHashCode = DEFAULT_FILTER_REMOVE_BY_HASH_CODE; - + + /** Only block for socketTimeOut seconds before timing out on a read. */ + private int socketTimeOut = DEFAULT_SOCKET_TIME_OUT; + + /** Only block for openTimeOut seconds before timing out on startup. */ + private int openTimeOut = DEFAULT_OPEN_TIMEOUT; + /** * Sets the tcpServer attribute of the ILateralCacheAttributes object * <p> @@ -317,6 +329,38 @@ } /** + * @param socketTimeOut the socketTimeOut to set + */ + public void setSocketTimeOut( int socketTimeOut ) + { + this.socketTimeOut = socketTimeOut; + } + + /** + * @return the socketTimeOut + */ + public int getSocketTimeOut() + { + return socketTimeOut; + } + + /** + * @param openTimeOut the openTimeOut to set + */ + public void setOpenTimeOut( int openTimeOut ) + { + this.openTimeOut = openTimeOut; + } + + /** + * @return the openTimeOut + */ + public int getOpenTimeOut() + { + return openTimeOut; + } + + /** * Used to key the instance TODO create another method for this and use toString for debugging * only. * <p> @@ -326,5 +370,4 @@ { return this.getTcpServer() + ":" + this.getTcpListenerPort(); } - } Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/behavior/ITCPLateralCacheAttributes.java URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/behavior/ITCPLateralCacheAttributes.java?rev=777699&r1=777698&r2=777699&view=diff ============================================================================== --- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/behavior/ITCPLateralCacheAttributes.java (original) +++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/behavior/ITCPLateralCacheAttributes.java Fri May 22 20:39:25 2009 @@ -195,4 +195,24 @@ * @param filter */ public void setFilterRemoveByHashCode( boolean filter ); + + /** + * @param socketTimeOut the socketTimeOut to set + */ + public void setSocketTimeOut( int socketTimeOut ); + + /** + * @return the socketTimeOut + */ + public int getSocketTimeOut(); + + /** + * @param openTimeOut the openTimeOut to set + */ + public void setOpenTimeOut( int openTimeOut ); + + /** + * @return the openTimeOut + */ + public int getOpenTimeOut(); } Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/utils/SocketOpener.java URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/utils/SocketOpener.java?rev=777699&r1=777698&r2=777699&view=diff ============================================================================== --- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/utils/SocketOpener.java (original) +++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/utils/SocketOpener.java Fri May 22 20:39:25 2009 @@ -20,13 +20,12 @@ */ import java.io.IOException; +import java.net.InetSocketAddress; import java.net.Socket; /** - * This should no longer be needed. - * <p> - * Socket opener that will timeout on the initial connect rather than block - * forever. Technique from core java II. + * Since 1.4, we can specify the timeout in the connect block, we no longer need the extra thread to + * join against the Socket creation. */ public class SocketOpener implements Runnable @@ -37,13 +36,15 @@ /** The port. */ private int port; + /** the open timeOut */ + private int timeOut; + /** The socket */ private Socket socket; /** - * Opens a socket with a connection timeout value. Joins against a background - * thread that does the opening. - * + * Opens a socket with a connection timeout value. + * <p> * @param host * @param port * @param timeOut @@ -51,39 +52,43 @@ */ public static Socket openSocket( String host, int port, int timeOut ) { - SocketOpener opener = new SocketOpener( host, port ); - Thread t = new Thread( opener ); - t.start(); - try - { - t.join( timeOut ); - } - catch ( InterruptedException ire ) - { - // swallow - } + // TODO get rid of the extra object + SocketOpener opener = new SocketOpener( host, port, timeOut ); + opener.connect(); return opener.getSocket(); } /** * Constructor for the SocketOpener object - * * @param host * @param port + * @param timeout connect timeout */ - public SocketOpener( String host, int port ) + public SocketOpener( String host, int port, int timeout ) { this.socket = null; this.host = host; this.port = port; + this.timeOut = timeout; } /** Main processing method for the SocketOpener object */ public void run() { + connect(); + } + + /** + * Creates an InetSocketAddress. Creates an unconnected Socket. Connects the Socket to the + * address. + */ + private void connect() + { try { - socket = new Socket( host, port ); + InetSocketAddress address = new InetSocketAddress( host, port ); + socket = new Socket(); + socket.connect( address, timeOut ); } catch ( IOException ioe ) { @@ -92,7 +97,6 @@ } /** - * * @return The opened socket */ public Socket getSocket() Modified: jakarta/jcs/trunk/src/test-conf/TestTCPLateralCache.ccf URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test-conf/TestTCPLateralCache.ccf?rev=777699&r1=777698&r2=777699&view=diff ============================================================================== --- jakarta/jcs/trunk/src/test-conf/TestTCPLateralCache.ccf (original) +++ jakarta/jcs/trunk/src/test-conf/TestTCPLateralCache.ccf Fri May 22 20:39:25 2009 @@ -39,6 +39,8 @@ jcs.auxiliary.LTCP.attributes.TcpServers=localhost:1111 jcs.auxiliary.LTCP.attributes.TcpListenerPort=1110 jcs.auxiliary.LTCP.attributes.AllowGet=false +jcs.auxiliary.LTCP.attributes.SocketTimeOut=1001 +jcs.auxiliary.LTCP.attributes.OpenTimeOut=2002 # ############################################################# # ################# THREAD POOL CONFIGURATION ################### Modified: jakarta/jcs/trunk/xdocs/LateralTCPProperties.xml URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/xdocs/LateralTCPProperties.xml?rev=777699&r1=777698&r2=777699&view=diff ============================================================================== --- jakarta/jcs/trunk/xdocs/LateralTCPProperties.xml (original) +++ jakarta/jcs/trunk/xdocs/LateralTCPProperties.xml Fri May 22 20:39:25 2009 @@ -101,6 +101,22 @@ <td>false</td> </tr> <tr> + <td>SocketTimeOut</td> + <td> + This allows you to set the socket (read) timeout. + </td> + <td>N</td> + <td>1000</td> + </tr> + <tr> + <td>OpenTimeOut</td> + <td> + This allows you to set the socket open timeout. + </td> + <td>N</td> + <td>2000</td> + </tr> + <tr> <td>UdpDiscoveryAddr</td> <td> The address the UDP discovery process should broadcast messages to. @@ -141,6 +157,8 @@ jcs.auxiliary.LTCP.attributes.AllowGet=false jcs.auxiliary.LTCP.attributes.IssueRemoveOnPut=false jcs.auxiliary.LTCP.attributes.FilterRemoveByHashCode=false +jcs.auxiliary.LTCP.attributes.SocketTimeoOt=1001 +jcs.auxiliary.LTCP.attributes.OpenTimeOut=2002 ]]></source> </subsection> Modified: jakarta/jcs/trunk/xdocs/changes.xml URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/xdocs/changes.xml?rev=777699&r1=777698&r2=777699&view=diff ============================================================================== --- jakarta/jcs/trunk/xdocs/changes.xml (original) +++ jakarta/jcs/trunk/xdocs/changes.xml Fri May 22 20:39:25 2009 @@ -21,6 +21,8 @@ <body> <release version="1.4-dev" date="in SVN"> </release> + <release version="1.3.3.0" date="2009-05-22" description="tempbuild"> + <action dev="asmuts" type="update">Made "openTimeOut" and "socketTimeOut" configurable on the TCP Lateral.</action> <release version="1.3.2.9" date="2009-02-02" description="tempbuild"> <action dev="asmuts" type="fix">Fixed bug in Remote Http Client URL creation for query strings.</action> --------------------------------------------------------------------- To unsubscribe, e-mail: jcs-dev-unsubscr...@jakarta.apache.org For additional commands, e-mail: jcs-dev-h...@jakarta.apache.org