You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by jf...@apache.org on 2009/10/09 18:00:20 UTC
svn commit: r823603 - in /tomcat/trunk/java/org/apache/catalina/ha/backend:
CollectedInfo.java HeartbeatListener.java MultiCastSender.java TcpSender.java
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
Re: svn commit: r823603 - in /tomcat/trunk/java/org/apache/catalina/ha/backend:
CollectedInfo.java HeartbeatListener.java MultiCastSender.java TcpSender.java
Posted by jean-frederic clere <jf...@gmail.com>.
On 10/12/2009 03:27 PM, Filip Hanik - Dev Lists wrote:
> On 10/12/2009 01:06 AM, jean-frederic clere wrote:
>> On 10/10/2009 12:24 AM, Filip Hanik - Dev Lists wrote:
>>> 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
>>
>> Well it is not exactly solving the same problem, here we need a
>> protocol between the node of a cluster to the front-end. I though
>> tribes was just to be used between the nodes of a cluster, did I miss
>> something?
> Tribes is generic, just a communication component. Can be used for
> anything. And if there are changes needed we can make them.
> What you are developing right now, looking at the code, you may be
> reinventing a lot of code that already exists.
> What is Tomcat specific is the org.apache.catalina.ha package that sits
> on top of Tribes.
>> Additionally the httpd part doesn't work only with Tomcat but could
>> also front-end other httpd making the use of tribes a bit complex....
> what is the httpd part right now, is it in trunk?
> however, since all you need is communicate data back and forth, you
> could make it work with any comm layer underneath, instead of writing
> one from scratch.
Well the first step was just extending existing stuff in httpd. The
existing protocol is quite open so I don't think we will need another one.
If you have tribes in C I would use it immediately.
Cheers
Jean-Frederic
>
> best
> Filip
>
>>
>>
>> Cheers
>>
>> Jean-Frederic
>>
>> ---------------------------------------------------------------------
>> 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
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r823603 - in /tomcat/trunk/java/org/apache/catalina/ha/backend:
CollectedInfo.java HeartbeatListener.java MultiCastSender.java TcpSender.java
Posted by Filip Hanik - Dev Lists <de...@hanik.com>.
On 10/12/2009 07:27 AM, Filip Hanik - Dev Lists wrote:
> On 10/12/2009 01:06 AM, jean-frederic clere wrote:
>> On 10/10/2009 12:24 AM, Filip Hanik - Dev Lists wrote:
>>> 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
>>
>> Well it is not exactly solving the same problem, here we need a
>> protocol between the node of a cluster to the front-end. I though
>> tribes was just to be used between the nodes of a cluster, did I miss
>> something?
> Tribes is generic, just a communication component. Can be used for
> anything. And if there are changes needed we can make them.
> What you are developing right now, looking at the code, you may be
> reinventing a lot of code that already exists.
> What is Tomcat specific is the org.apache.catalina.ha package that
> sits on top of Tribes.
>> Additionally the httpd part doesn't work only with Tomcat but could
>> also front-end other httpd making the use of tribes a bit complex....
> what is the httpd part right now, is it in trunk?
> however, since all you need is communicate data back and forth, you
> could make it work with any comm layer underneath, instead of writing
> one from scratch.
additionally, the beauty with trunk is that its open for dev, you can
continue with your component that does TCP and multicasting, you can
even take code out of tribes since it does that exact thing, or we can
adjust tribes to be more generic (unless it already is)
best
Filip
>
> best
> Filip
>
>>
>>
>> Cheers
>>
>> Jean-Frederic
>>
>> ---------------------------------------------------------------------
>> 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
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r823603 - in /tomcat/trunk/java/org/apache/catalina/ha/backend:
CollectedInfo.java HeartbeatListener.java MultiCastSender.java TcpSender.java
Posted by Filip Hanik - Dev Lists <de...@hanik.com>.
On 10/12/2009 01:06 AM, jean-frederic clere wrote:
> On 10/10/2009 12:24 AM, Filip Hanik - Dev Lists wrote:
>> 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
>
> Well it is not exactly solving the same problem, here we need a
> protocol between the node of a cluster to the front-end. I though
> tribes was just to be used between the nodes of a cluster, did I miss
> something?
Tribes is generic, just a communication component. Can be used for
anything. And if there are changes needed we can make them.
What you are developing right now, looking at the code, you may be
reinventing a lot of code that already exists.
What is Tomcat specific is the org.apache.catalina.ha package that sits
on top of Tribes.
> Additionally the httpd part doesn't work only with Tomcat but could
> also front-end other httpd making the use of tribes a bit complex....
what is the httpd part right now, is it in trunk?
however, since all you need is communicate data back and forth, you
could make it work with any comm layer underneath, instead of writing
one from scratch.
best
Filip
>
>
> Cheers
>
> Jean-Frederic
>
> ---------------------------------------------------------------------
> 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
Re: svn commit: r823603 - in /tomcat/trunk/java/org/apache/catalina/ha/backend:
CollectedInfo.java HeartbeatListener.java MultiCastSender.java TcpSender.java
Posted by jean-frederic clere <jf...@gmail.com>.
On 10/10/2009 12:24 AM, Filip Hanik - Dev Lists wrote:
> 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
Well it is not exactly solving the same problem, here we need a protocol
between the node of a cluster to the front-end. I though tribes was just
to be used between the nodes of a cluster, did I miss something?
Additionally the httpd part doesn't work only with Tomcat but could also
front-end other httpd making the use of tribes a bit complex....
Cheers
Jean-Frederic
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r823603 - in /tomcat/trunk/java/org/apache/catalina/ha/backend:
CollectedInfo.java HeartbeatListener.java MultiCastSender.java TcpSender.java
Posted by Filip Hanik - Dev Lists <de...@hanik.com>.
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