pero 2005/07/01 07:26:02 Modified: modules/cluster/src/share/org/apache/catalina/cluster/tcp ClusterReceiverBase.java LocalStrings.properties SocketReplicationListener.java Log: Fix wait that Recevier Port is bind Add i18n message support Revision Changes Path 1.7 +2 -2 jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/tcp/ClusterReceiverBase.java Index: ClusterReceiverBase.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/tcp/ClusterReceiverBase.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- ClusterReceiverBase.java 30 Jun 2005 13:03:34 -0000 1.6 +++ ClusterReceiverBase.java 1 Jul 2005 14:26:02 -0000 1.7 @@ -303,7 +303,7 @@ Thread t = new Thread(this, "ClusterReceiver"); t.setDaemon(true); t.start(); - } catch (Exception x) { + } catch (Exception x) { log.fatal("Unable to start cluster receiver", x); } registerReceiverMBean(); 1.12 +8 -0 jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/tcp/LocalStrings.properties Index: LocalStrings.properties =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/tcp/LocalStrings.properties,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- LocalStrings.properties 26 Jun 2005 21:21:50 -0000 1.11 +++ LocalStrings.properties 1 Jul 2005 14:26:02 -0000 1.12 @@ -49,3 +49,11 @@ SimpleTcpCluster.log.receive=RECEIVE {0,date}:{0,time} {1,number} {2}:{3,number,integer} {4} {5} SimpleTcpCluster.log.send=SEND {0,date}:{0,time} {1,number} {2}:{3,number,integer} {4} SimpleTcpCluster.log.send.all=SEND {0,date}:{0,time} {1,number} - {2} +SocketReplictionListener.allreadyExists=ServerSocket [{0}:{1}] allready started! +SocketReplictionListener.accept.failure=ServerSocket [{0}:{1}] - Exception to start thread or accept server socket +SocketReplictionListener.open=Open Socket at [{0}:{1}] +SocketReplictionListener.openclose.failure=ServerSocket [{0}:{1}] - Exception to open or close server socket +SocketReplictionListener.portbusy=Port busy at [{0}:{i}] - reason [{2}] +SocketReplictionListener.serverSocket.notExists=Fatal error: Receiver socket not bound address={0} port={1} maxport={2} +SocketReplictionListener.timeout=Receiver ServerSocket no started [{0}:{1}] - timeout +SocketReplictionListener.unlockSocket.failure=UnLocksocket failure at ServerSocket [{0:{1}] 1.4 +90 -13 jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/tcp/SocketReplicationListener.java Index: SocketReplicationListener.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/tcp/SocketReplicationListener.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- SocketReplicationListener.java 26 Jun 2005 21:21:50 -0000 1.3 +++ SocketReplicationListener.java 1 Jul 2005 14:26:02 -0000 1.4 @@ -22,33 +22,55 @@ import java.net.Socket; import org.apache.catalina.cluster.io.SocketObjectReader; +import org.apache.catalina.util.StringManager; /** * @author Peter Rossbach * @version $Revision$, $Date$ */ public class SocketReplicationListener extends ClusterReceiverBase { + + // ---------------------------------------------------- Statics + + public static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory + .getLog(SocketReplicationListener.class); + + /** + * The string manager for this package. + */ + protected static StringManager sm = StringManager + .getManager(Constants.Package); + /** * The descriptive information about this implementation. */ private static final String info = "SocketReplicationListener/1.2"; + // ---------------------------------------------------- Properties private ServerSocket serverSocket = null; private int tcpListenMaxPort ; + /** + * + * One second timeout to wait that socket started + */ + private int tcpListenTimeout = 1 ; + + // ---------------------------------------------------- Constructor + public SocketReplicationListener() { } + // ---------------------------------------------------- Properties + /** * Return descriptive information about this implementation and the * corresponding version number, in the format * <code><description>/<version></code>. */ public String getInfo() { - return (info); - } /** @@ -64,7 +86,48 @@ public void setTcpListenMaxPort(int maxListenPort) { this.tcpListenMaxPort = maxListenPort; } + + /** + * @return Returns the tcpListenTimeout. + */ + public int getTcpListenTimeout() { + return tcpListenTimeout; + } + /** + * @param tcpListenTimeout The tcpListenTimeout to set. + */ + public void setTcpListenTimeout(int tcpListenTimeout) { + this.tcpListenTimeout = tcpListenTimeout; + } + + // ---------------------------------------------------- public methods + + /** + * Wait the createServerSocket find the correct socket port when default config is used. + * @see org.apache.catalina.cluster.ClusterReceiver#start() + * @see #createServerSocket() + */ + public void start() { + super.start(); + long reqStart = System.currentTimeMillis(); + long reqNow = 0 ; + boolean isTimeout = true ; + do { + try { + Thread.sleep(50); + } catch (Exception sleep) { + } + reqNow = System.currentTimeMillis(); + isTimeout = ((reqNow - reqStart) > (1000 * getTcpListenTimeout())); + } while (doListen && (!isTimeout)); + if (isTimeout || (!doListen)) { + log.error(sm.getString("SocketReplictionListener.timeout", + getTcpListenAddress(),Integer.toString(getTcpListenPort()))); + } + } + // ---------------------------------------------------- protected methods + /** * Master/Slave Sender handling / bind Server Socket at addres and port * @@ -72,7 +135,8 @@ */ protected void listen() { if (doListen) { - log.warn("ServerSocket allready started"); + log.warn(sm.getString("SocketReplictionListener.allreadyExists", + getTcpListenAddress(),Integer.toString(getTcpListenPort()))); return; } @@ -92,16 +156,22 @@ t.start(); } } catch (IOException iex) { - log.warn("Exception to start thread", iex); + log.warn(sm.getString("SocketReplictionListener.accept.failure", + getTcpListenAddress(), + Integer.toString(getTcpListenPort())), iex); } } serverSocket.close(); } else { - log.fatal("Fatal error: Receiver socket not bound - address=" + getTcpListenAddress() - + " port=" + getTcpListenPort() + " maxport=" + getTcpListenMaxPort() ); + log.fatal(sm.getString("SocketReplictionListener.serverSocket.notExists", + getTcpListenAddress(), + Integer.toString(getTcpListenPort()), + Integer.toString(getTcpListenMaxPort()))); } } catch (IOException iex) { - log.warn("Exception at start or close server socket", iex); + log.warn(sm.getString("SocketReplictionListener.openclose.failure", + getTcpListenAddress(), + Integer.toString(getTcpListenPort())), iex); } finally { doListen = false; serverSocket = null; @@ -129,12 +199,17 @@ break; } catch( IOException ex ) { if(log.isDebugEnabled()) - log.debug("Port busy at [" + inet.getHostAddress() + "." + i + "] - reason: " + ex.toString()); + log.debug(sm.getString("SocketReplictionListener.portbusy", + inet.getHostAddress(), + Integer.toString(i), + ex.toString())); continue; } } if(sSocket != null && log.isInfoEnabled()) - log.info("Open Socket at [" + inet.getHostAddress() + "." + getTcpListenPort() + "]"); + log.info(sm.getString("SocketReplictionListener.open", + inet.getHostAddress(), + Integer.toString(getTcpListenPort()))); return sSocket ; } @@ -158,7 +233,9 @@ s.setSoLinger(true, 0); } catch (IOException iex) { - log.warn("UnLocksocket failure", iex); + log.warn(sm.getString("SocketReplictionListener.unlockSocket.failure", + getTcpListenAddress(), + Integer.toString(getTcpListenPort())), iex); } finally { try { if (s != null) @@ -169,8 +246,8 @@ } /** - * Close serverSockets FIXME the channelSocket to connect own socket to - * terminate accpet loop! + * Close serverSockets + * FIXME the channelSocket to connect own socket to terminate accpet loop! */ protected void stopListening() { unLockSocket();
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]