fhanik 2004/05/14 08:00:29 Modified: modules/cluster/src/share/org/apache/catalina/cluster/mcast McastService.java McastServiceImpl.java Log: Supporting TTL and so time out settings for multicast sockets Revision Changes Path 1.10 +36 -1 jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/mcast/McastService.java Index: McastService.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/mcast/McastService.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- McastService.java 27 Feb 2004 14:58:56 -0000 1.9 +++ McastService.java 14 May 2004 15:00:29 -0000 1.10 @@ -53,6 +53,8 @@ * The local member */ protected McastMember localMember ; + private int mcastSoTimeout; + private int mcastTTL; /** * Create a membership service. @@ -169,11 +171,30 @@ if ( properties.getProperty("mcastBindAddress")!= null ) { bind = java.net.InetAddress.getByName(properties.getProperty("mcastBindAddress")); } + int ttl = -1; + int soTimeout = -1; + if ( properties.getProperty("mcastTTL") != null ) { + try { + ttl = Integer.parseInt(properties.getProperty("mcastTTL")); + } catch ( Exception x ) { + log.error("Unable to parse mcastTTL="+properties.getProperty("mcastTTL"),x); + } + } + if ( properties.getProperty("mcastSoTimeout") != null ) { + try { + soTimeout = Integer.parseInt(properties.getProperty("mcastSoTimeout")); + } catch ( Exception x ) { + log.error("Unable to parse mcastSoTimeout="+properties.getProperty("mcastSoTimeout"),x); + } + } + impl = new McastServiceImpl((McastMember)localMember,Long.parseLong(properties.getProperty("msgFrequency")), Long.parseLong(properties.getProperty("memberDropTime")), Integer.parseInt(properties.getProperty("mcastPort")), bind, java.net.InetAddress.getByName(properties.getProperty("mcastAddress")), + ttl, + soTimeout, this); impl.start(level); @@ -249,5 +270,19 @@ service.setProperties(p); service.start(); Thread.currentThread().sleep(60*1000*60); + } + public int getMcastSoTimeout() { + return mcastSoTimeout; + } + public void setMcastSoTimeout(int mcastSoTimeout) { + this.mcastSoTimeout = mcastSoTimeout; + properties.setProperty("mcastSoTimeout", String.valueOf(mcastSoTimeout)); + } + public int getMcastTTL() { + return mcastTTL; + } + public void setMcastTTL(int mcastTTL) { + this.mcastTTL = mcastTTL; + properties.setProperty("mcastTTL", String.valueOf(mcastTTL)); } } 1.11 +30 -8 jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/mcast/McastServiceImpl.java Index: McastServiceImpl.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/mcast/McastServiceImpl.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- McastServiceImpl.java 30 Apr 2004 15:28:02 -0000 1.10 +++ McastServiceImpl.java 14 May 2004 15:00:29 -0000 1.11 @@ -94,6 +94,10 @@ * When was the service started */ protected long serviceStartTime = System.currentTimeMillis(); + + protected int mcastTTL = -1; + protected int mcastSoTimeout = -1; + protected InetAddress mcastBindAddress = null; /** * Create a new mcast service impl @@ -113,18 +117,17 @@ int port, InetAddress bind, InetAddress mcastAddress, + int ttl, + int soTimeout, MembershipListener service) throws IOException { - if ( bind != null) socket = new MulticastSocket(new java.net.InetSocketAddress(bind,port)); - else socket = new MulticastSocket(port); - if ( bind != null ) { - log.info("Setting multihome multicast interface to:"+bind); - socket.setInterface(bind); - log.info("Done setting interface for multicast."); - }//end if this.member = member; address = mcastAddress; this.port = port; + this.mcastSoTimeout = soTimeout; + this.mcastTTL = ttl; + this.mcastBindAddress = bind; + setupSocket(); sendPacket = new DatagramPacket(new byte[1000],1000); sendPacket.setAddress(address); sendPacket.setPort(port); @@ -135,6 +138,25 @@ timeToExpiration = expireTime; this.service = service; this.sendFrequency = sendFrequency; + } + + protected void setupSocket() throws IOException { + if (mcastBindAddress != null) socket = new MulticastSocket(new java.net. + InetSocketAddress(mcastBindAddress, port)); + else socket = new MulticastSocket(port); + if (mcastBindAddress != null) { + log.info("Setting multihome multicast interface to:" + + mcastBindAddress); + socket.setInterface(mcastBindAddress); + } //end if + if ( mcastSoTimeout >= 0 ) { + log.info("Setting cluster mcast soTimeout to "+mcastSoTimeout); + socket.setSoTimeout(mcastSoTimeout); + } + if ( mcastTTL >= 0 ) { + log.info("Setting cluster mcast TTL to " + mcastTTL); + socket.setTimeToLive(mcastTTL); + } } /**
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]