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/04/09 15:00:21 UTC
svn commit: r763635 - in /tomcat/trunk/java/org/apache/catalina/ha/backend:
HeartbeatListener.java MultiCastSender.java Sender.java
Author: jfclere
Date: Thu Apr 9 13:00:21 2009
New Revision: 763635
URL: http://svn.apache.org/viewvc?rev=763635&view=rev
Log:
Move the multi logic to MultiCastSender with
the idea to TCP sockets and a list of proxy too.
Added:
tomcat/trunk/java/org/apache/catalina/ha/backend/MultiCastSender.java
tomcat/trunk/java/org/apache/catalina/ha/backend/Sender.java
Modified:
tomcat/trunk/java/org/apache/catalina/ha/backend/HeartbeatListener.java
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=763635&r1=763634&r2=763635&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/ha/backend/HeartbeatListener.java (original)
+++ tomcat/trunk/java/org/apache/catalina/ha/backend/HeartbeatListener.java Thu Apr 9 13:00:21 2009
@@ -55,8 +55,6 @@
public void setPort(int port) { this.port = port; }
/* for multicasting stuff */
- MulticastSocket s = null;
- InetAddress group = null;
String ip = "224.0.1.105"; /* Multicast IP */
int multiport = 23364; /* Multicast Port */
int ttl = 16;
@@ -70,23 +68,17 @@
private CollectedInfo coll = null;
+ private Sender sender = null;
+
public void containerEvent(ContainerEvent event) {
}
public void lifecycleEvent(LifecycleEvent event) {
Object source = event.getLifecycle();
if (Lifecycle.PERIODIC_EVENT.equals(event.getType())) {
- if (s == null) {
- try {
- group = InetAddress.getByName(ip);
- s = new MulticastSocket(port);
- s.setTimeToLive(16);
- s.joinGroup(group);
- } catch (Exception ex) {
- log.error("Unable to use multicast: " + ex);
- s = null;
- return;
- }
+ if (sender == null) {
+ sender = new MultiCastSender();
+ sender.init(this);
}
/* Read busy and ready */
@@ -108,19 +100,10 @@
}
String output = new String();
output = "v=1&ready=" + coll.ready + "&busy=" + coll.busy;
- byte[] buf;
- try {
- buf = output.getBytes("US-ASCII");
- } catch (UnsupportedEncodingException ex) {
- buf = output.getBytes();
- }
- DatagramPacket data = new DatagramPacket(buf, buf.length, group, multiport);
try {
- s.send(data);
+ sender.send(output);
} catch (Exception ex) {
log.error("Unable to send colllected load information: " + ex);
- s.close();
- s = null;
}
}
}
Added: 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=763635&view=auto
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/ha/backend/MultiCastSender.java (added)
+++ tomcat/trunk/java/org/apache/catalina/ha/backend/MultiCastSender.java Thu Apr 9 13:00:21 2009
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.catalina.ha.backend;
+
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+
+import java.net.MulticastSocket;
+import java.net.InetAddress;
+import java.net.DatagramPacket;
+import java.io.UnsupportedEncodingException;
+
+/*
+ * Sender to proxies using multicast socket.
+ */
+public class MultiCastSender
+ implements Sender {
+
+ private static Log log = LogFactory.getLog(HeartbeatListener.class);
+
+ HeartbeatListener config = null;
+
+ /* for multicasting stuff */
+ MulticastSocket s = null;
+ InetAddress group = null;
+
+ public void init(HeartbeatListener config) {
+ this.config = config;
+ }
+
+ public int send(String mess) throws Exception {
+ if (s == null) {
+ try {
+ group = InetAddress.getByName(config.getGroup());
+ s = new MulticastSocket(config.getMultiport());
+ s.setTimeToLive(config.getTtl());
+ s.joinGroup(group);
+ } catch (Exception ex) {
+ log.error("Unable to use multicast: " + ex);
+ s = null;
+ return -1;
+ }
+ }
+
+ byte[] buf;
+ try {
+ buf = mess.getBytes("US-ASCII");
+ } catch (UnsupportedEncodingException ex) {
+ buf = mess.getBytes();
+ }
+ DatagramPacket data = new DatagramPacket(buf, buf.length, group, config.getMultiport());
+ try {
+ s.send(data);
+ } catch (Exception ex) {
+ log.error("Unable to send colllected load information: " + ex);
+ s.close();
+ s = null;
+ return -1;
+ }
+ return 0;
+ }
+
+}
Added: tomcat/trunk/java/org/apache/catalina/ha/backend/Sender.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ha/backend/Sender.java?rev=763635&view=auto
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/ha/backend/Sender.java (added)
+++ tomcat/trunk/java/org/apache/catalina/ha/backend/Sender.java Thu Apr 9 13:00:21 2009
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.catalina.ha.backend;
+
+/*
+ * Interface to send data to proxies
+ *
+ */
+public interface Sender {
+
+ /**
+ * Set the configuration parameters
+ */
+ public void init(HeartbeatListener config);
+
+ /**
+ * Send the message to the proxies
+ */
+ public int send(String mess) throws Exception;
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r763635 - in /tomcat/trunk/java/org/apache/catalina/ha/backend:
HeartbeatListener.java MultiCastSender.java Sender.java
Posted by sebb <se...@gmail.com>.
On 09/04/2009, jfclere@apache.org <jf...@apache.org> wrote:
> Author: jfclere
> Date: Thu Apr 9 13:00:21 2009
> New Revision: 763635
>
> URL: http://svn.apache.org/viewvc?rev=763635&view=rev
> Log:
> Move the multi logic to MultiCastSender with
> the idea to TCP sockets and a list of proxy too.
>
> Added:
> tomcat/trunk/java/org/apache/catalina/ha/backend/MultiCastSender.java
> tomcat/trunk/java/org/apache/catalina/ha/backend/Sender.java
Should have svn:eol-style=native property ...
> Modified:
> tomcat/trunk/java/org/apache/catalina/ha/backend/HeartbeatListener.java
>
> 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=763635&r1=763634&r2=763635&view=diff
> ==============================================================================
> --- tomcat/trunk/java/org/apache/catalina/ha/backend/HeartbeatListener.java (original)
> +++ tomcat/trunk/java/org/apache/catalina/ha/backend/HeartbeatListener.java Thu Apr 9 13:00:21 2009
> @@ -55,8 +55,6 @@
> public void setPort(int port) { this.port = port; }
>
> /* for multicasting stuff */
> - MulticastSocket s = null;
> - InetAddress group = null;
> String ip = "224.0.1.105"; /* Multicast IP */
> int multiport = 23364; /* Multicast Port */
> int ttl = 16;
> @@ -70,23 +68,17 @@
>
> private CollectedInfo coll = null;
>
> + private Sender sender = null;
> +
> public void containerEvent(ContainerEvent event) {
> }
>
> public void lifecycleEvent(LifecycleEvent event) {
> Object source = event.getLifecycle();
> if (Lifecycle.PERIODIC_EVENT.equals(event.getType())) {
> - if (s == null) {
> - try {
> - group = InetAddress.getByName(ip);
> - s = new MulticastSocket(port);
> - s.setTimeToLive(16);
> - s.joinGroup(group);
> - } catch (Exception ex) {
> - log.error("Unable to use multicast: " + ex);
> - s = null;
> - return;
> - }
> + if (sender == null) {
> + sender = new MultiCastSender();
> + sender.init(this);
> }
>
> /* Read busy and ready */
> @@ -108,19 +100,10 @@
> }
> String output = new String();
> output = "v=1&ready=" + coll.ready + "&busy=" + coll.busy;
> - byte[] buf;
> - try {
> - buf = output.getBytes("US-ASCII");
> - } catch (UnsupportedEncodingException ex) {
> - buf = output.getBytes();
> - }
> - DatagramPacket data = new DatagramPacket(buf, buf.length, group, multiport);
> try {
> - s.send(data);
> + sender.send(output);
> } catch (Exception ex) {
> log.error("Unable to send colllected load information: " + ex);
> - s.close();
> - s = null;
> }
> }
> }
>
> Added: 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=763635&view=auto
> ==============================================================================
> --- tomcat/trunk/java/org/apache/catalina/ha/backend/MultiCastSender.java (added)
> +++ tomcat/trunk/java/org/apache/catalina/ha/backend/MultiCastSender.java Thu Apr 9 13:00:21 2009
> @@ -0,0 +1,79 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one or more
> + * contributor license agreements. See the NOTICE file distributed with
> + * this work for additional information regarding copyright ownership.
> + * The ASF licenses this file to You under the Apache License, Version 2.0
> + * (the "License"); you may not use this file except in compliance with
> + * the License. You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +
> +
> +package org.apache.catalina.ha.backend;
> +
> +import org.apache.juli.logging.Log;
> +import org.apache.juli.logging.LogFactory;
> +
> +import java.net.MulticastSocket;
> +import java.net.InetAddress;
> +import java.net.DatagramPacket;
> +import java.io.UnsupportedEncodingException;
> +
> +/*
> + * Sender to proxies using multicast socket.
> + */
> +public class MultiCastSender
> + implements Sender {
> +
> + private static Log log = LogFactory.getLog(HeartbeatListener.class);
> +
> + HeartbeatListener config = null;
> +
> + /* for multicasting stuff */
> + MulticastSocket s = null;
> + InetAddress group = null;
> +
> + public void init(HeartbeatListener config) {
> + this.config = config;
> + }
> +
> + public int send(String mess) throws Exception {
> + if (s == null) {
> + try {
> + group = InetAddress.getByName(config.getGroup());
> + s = new MulticastSocket(config.getMultiport());
> + s.setTimeToLive(config.getTtl());
> + s.joinGroup(group);
> + } catch (Exception ex) {
> + log.error("Unable to use multicast: " + ex);
> + s = null;
> + return -1;
> + }
> + }
> +
> + byte[] buf;
> + try {
> + buf = mess.getBytes("US-ASCII");
> + } catch (UnsupportedEncodingException ex) {
> + buf = mess.getBytes();
> + }
> + DatagramPacket data = new DatagramPacket(buf, buf.length, group, config.getMultiport());
> + try {
> + s.send(data);
> + } catch (Exception ex) {
> + log.error("Unable to send colllected load information: " + ex);
> + s.close();
> + s = null;
> + return -1;
> + }
> + return 0;
> + }
> +
> +}
>
> Added: tomcat/trunk/java/org/apache/catalina/ha/backend/Sender.java
> URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ha/backend/Sender.java?rev=763635&view=auto
> ==============================================================================
> --- tomcat/trunk/java/org/apache/catalina/ha/backend/Sender.java (added)
> +++ tomcat/trunk/java/org/apache/catalina/ha/backend/Sender.java Thu Apr 9 13:00:21 2009
> @@ -0,0 +1,36 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one or more
> + * contributor license agreements. See the NOTICE file distributed with
> + * this work for additional information regarding copyright ownership.
> + * The ASF licenses this file to You under the Apache License, Version 2.0
> + * (the "License"); you may not use this file except in compliance with
> + * the License. You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +
> +
> +package org.apache.catalina.ha.backend;
> +
> +/*
> + * Interface to send data to proxies
> + *
> + */
> +public interface Sender {
> +
> + /**
> + * Set the configuration parameters
> + */
> + public void init(HeartbeatListener config);
> +
> + /**
> + * Send the message to the proxies
> + */
> + public int send(String mess) throws Exception;
> +}
>
>
>
> ---------------------------------------------------------------------
> 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