tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Filip Hanik - Dev Lists <devli...@hanik.com>
Subject Re: svn commit: r823603 - in /tomcat/trunk/java/org/apache/catalina/ha/backend: CollectedInfo.java HeartbeatListener.java MultiCastSender.java TcpSender.java
Date Fri, 09 Oct 2009 22:24:28 GMT
you're gonna run into all the same issues we already worked through with 
tribes. I'm not sure why you don't just use tribes rather than 
reinventing everything from scratch

Filip

On 10/09/2009 10:00 AM, jfclere@apache.org wrote:
> Author: jfclere
> Date: Fri Oct  9 16:00:20 2009
> New Revision: 823603
>
> URL: http://svn.apache.org/viewvc?rev=823603&view=rev
> Log:
> Add a local bind otherwise for box with multi IP httpd may use the wrong port.
>
> Modified:
>      tomcat/trunk/java/org/apache/catalina/ha/backend/CollectedInfo.java
>      tomcat/trunk/java/org/apache/catalina/ha/backend/HeartbeatListener.java
>      tomcat/trunk/java/org/apache/catalina/ha/backend/MultiCastSender.java
>      tomcat/trunk/java/org/apache/catalina/ha/backend/TcpSender.java
>
> Modified: tomcat/trunk/java/org/apache/catalina/ha/backend/CollectedInfo.java
> URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ha/backend/CollectedInfo.java?rev=823603&r1=823602&r2=823603&view=diff
> ==============================================================================
> --- tomcat/trunk/java/org/apache/catalina/ha/backend/CollectedInfo.java (original)
> +++ tomcat/trunk/java/org/apache/catalina/ha/backend/CollectedInfo.java Fri Oct  9 16:00:20
2009
> @@ -44,11 +44,15 @@
>       int ready;
>       int busy;
>
> +    int port = 0;
> +    String host = null;
> +
>       public CollectedInfo(String host, int port) throws Exception {
>           init(host, port);
>       }
>       public void init(String host, int port) throws Exception {
> -        String sport = Integer.toString(port);
> +        int iport = 0;
> +        String shost = null;
>           mBeanServer = Registry.getRegistry(null, null).getMBeanServer();
>           String onStr = "*:type=ThreadPool,*";
>           ObjectName objectName = new ObjectName(onStr);
> @@ -58,24 +62,29 @@
>               ObjectInstance oi = iterator.next();
>               objName = oi.getObjectName();
>               String name = objName.getKeyProperty("name");
> +
>               /* Name are:
>                * http-8080
>                * jk-10.33.144.3-8009
>                * jk-jfcpc%2F10.33.144.3-8009
>                */
> +            String [] elenames = name.split("-");
> +            String sport = elenames[elenames.length-1];
> +            iport = Integer.parseInt(sport);
> +            String [] shosts = elenames[1].split("%2F");
> +            shost = shosts[0];
> +
>               if (port==0&&  host==null)
>                     break; /* Take the first one */
> -            String [] elenames = name.split("-");
> -            if (elenames[elenames.length-1].compareTo(sport) != 0)
> -                continue; /* port doesn't match */
> -            if (host==null)
> +            if (host==null&&  iport==port)
>                   break; /* Only port done */
> -            String [] shosts = elenames[1].split("%2F");
> -            if (shosts[0].compareTo(host) == 0)
> +            if (shost.compareTo(host) == 0)
>                   break; /* Done port and host are the expected ones */
>           }
>           if (objName == null)
> -            throw(new Exception("Can't find connector for " + host + ":" + sport));
> +            throw(new Exception("Can't find connector for " + host + ":" + port));
> +        this.port = iport;
> +        this.host = shost;
>
>       }
>
>
> Modified: tomcat/trunk/java/org/apache/catalina/ha/backend/HeartbeatListener.java
> URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ha/backend/HeartbeatListener.java?rev=823603&r1=823602&r2=823603&view=diff
> ==============================================================================
> --- tomcat/trunk/java/org/apache/catalina/ha/backend/HeartbeatListener.java (original)
> +++ tomcat/trunk/java/org/apache/catalina/ha/backend/HeartbeatListener.java Fri Oct 
9 16:00:20 2009
> @@ -85,26 +85,31 @@
>                       sender = new MultiCastSender();
>                   else
>                       sender = new TcpSender();
> -
> -                try {
> -                    sender.init(this);
> -                } catch (Exception ex) {
> -                    log.error("Unable to initialize Sender: " + ex);
> -                    sender = null;
> -                    return;
> -                }
>               }
>
>               /* Read busy and ready */
>               if (coll == null) {
>                   try {
>                       coll = new CollectedInfo(host, port);
> +                    this.port = coll.port;
> +                    this.host = coll.host;
>                   } catch (Exception ex) {
>                       log.error("Unable to initialize info collection: " + ex);
>                       coll = null;
>                       return;
>                   }
>               }
> +
> +            /* Start or restart sender */
> +            try {
> +                sender.init(this);
> +            } catch (Exception ex) {
> +                log.error("Unable to initialize Sender: " + ex);
> +                sender = null;
> +                return;
> +            }
> +
> +            /* refresh the connector information and send it */
>               try {
>                   coll.refresh();
>               } catch (Exception ex) {
>
> Modified: tomcat/trunk/java/org/apache/catalina/ha/backend/MultiCastSender.java
> URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ha/backend/MultiCastSender.java?rev=823603&r1=823602&r2=823603&view=diff
> ==============================================================================
> --- tomcat/trunk/java/org/apache/catalina/ha/backend/MultiCastSender.java (original)
> +++ tomcat/trunk/java/org/apache/catalina/ha/backend/MultiCastSender.java Fri Oct  9
16:00:20 2009
> @@ -23,6 +23,7 @@
>
>   import java.net.MulticastSocket;
>   import java.net.InetAddress;
> +import java.net.InetSocketAddress;
>   import java.net.DatagramPacket;
>   import java.io.UnsupportedEncodingException;
>
> @@ -48,7 +49,13 @@
>           if (s == null) {
>               try {
>                   group = InetAddress.getByName(config.getGroup());
> -                s = new MulticastSocket(config.getMultiport());
> +                if (config.host != null) {
> +                    InetAddress addr =  InetAddress.getByName(config.host);
> +                    InetSocketAddress addrs = new InetSocketAddress(addr, config.getMultiport());
> +                    s = new MulticastSocket(addrs);
> +                } else
> +                    s = new MulticastSocket(config.getMultiport());
> +
>                   s.setTimeToLive(config.getTtl());
>                   s.joinGroup(group);
>               } catch (Exception ex) {
>
> Modified: tomcat/trunk/java/org/apache/catalina/ha/backend/TcpSender.java
> URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ha/backend/TcpSender.java?rev=823603&r1=823602&r2=823603&view=diff
> ==============================================================================
> --- tomcat/trunk/java/org/apache/catalina/ha/backend/TcpSender.java (original)
> +++ tomcat/trunk/java/org/apache/catalina/ha/backend/TcpSender.java Fri Oct  9 16:00:20
2009
> @@ -27,6 +27,7 @@
>   import java.io.InputStreamReader;
>   import java.io.OutputStreamWriter;
>   import java.net.InetAddress;
> +import java.net.InetSocketAddress;
>   import java.net.Socket;
>   import java.util.StringTokenizer;
>
> @@ -90,7 +91,16 @@
>           for (int i = 0; i<  connections.length; i++) {
>               if (connections[i] == null) {
>                   try {
> -                    connections[i] = new Socket(proxies[i].address, proxies[i].port);
> +                    if (config.host != null) {
> +                        connections[i] = new Socket();
> +                        InetAddress addr =  InetAddress.getByName(config.host);
> +                        InetSocketAddress addrs = new InetSocketAddress(addr, 0);
> +                        connections[i].setReuseAddress(true);
> +                        connections[i].bind(addrs);
> +                        addrs = new InetSocketAddress(proxies[i].address, proxies[i].port);
> +                        connections[i].connect(addrs);
> +                    } else
> +                        connections[i] = new Socket(proxies[i].address, proxies[i].port);
>                       connectionReaders[i] = new BufferedReader(new InputStreamReader(connections[i].getInputStream()));
>                       connectionWriters[i] = new BufferedWriter(new OutputStreamWriter(connections[i].getOutputStream()));
>                   } catch (Exception ex) {
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: dev-help@tomcat.apache.org
>
>
>    


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message