Move the class from cluster to ha.backend
authorjfclere <jfclere@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 9 Apr 2009 06:54:21 +0000 (06:54 +0000)
committerjfclere <jfclere@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 9 Apr 2009 06:54:21 +0000 (06:54 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@763533 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/cluster/CollectedInfo.java [deleted file]
java/org/apache/catalina/cluster/HeartbeatListener.java [deleted file]
java/org/apache/catalina/ha/backend/CollectedInfo.java [new file with mode: 0644]
java/org/apache/catalina/ha/backend/HeartbeatListener.java [new file with mode: 0644]

diff --git a/java/org/apache/catalina/cluster/CollectedInfo.java b/java/org/apache/catalina/cluster/CollectedInfo.java
deleted file mode 100644 (file)
index ba44036..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * 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.cluster;
-
-/* for MBean to read ready and busy */
-
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-import javax.management.ObjectInstance;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.Set;
-
-import org.apache.tomcat.util.modeler.Registry;
-import org.apache.juli.logging.Log;
-import org.apache.juli.logging.LogFactory;
-
-/*
- * Listener to provider informations to mod_heartbeat.c
- * *msg_format = "v=%u&ready=%u&busy=%u"; (message to send).
- * send the muticast merssage using the format...
- * what about the bind(IP. port) only IP makes sense (for the moment).
- * BTW:v  = version :-)
- */
-public class CollectedInfo {
-
-    /* Collect info via JMX */
-    protected MBeanServer mBeanServer = null;
-    protected ObjectName objName = null;
-
-    int ready;
-    int busy;
-
-    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);
-        mBeanServer = Registry.getRegistry(null, null).getMBeanServer();
-        String onStr = "*:type=ThreadPool,*";
-        ObjectName objectName = new ObjectName(onStr);
-        Set set = mBeanServer.queryMBeans(objectName, null);
-        Iterator<ObjectInstance> iterator = set.iterator();
-        while (iterator.hasNext()) {
-            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
-             */
-            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)
-                break; /* Only port done */
-            String [] shosts = elenames[1].split("%2F");
-            if (shosts[0].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));
-        
-    }
-
-    public void refresh() throws Exception {
-        if (mBeanServer == null || objName == null) {
-            throw(new Exception("Not initialized!!!"));
-        }
-        Integer imax = (Integer) mBeanServer.getAttribute(objName, "maxThreads");
-
-        // the currentThreadCount could be 0 before the threads are created...
-        // Integer iready = (Integer) mBeanServer.getAttribute(objName, "currentThreadCount");
-
-        Integer ibusy  = (Integer) mBeanServer.getAttribute(objName, "currentThreadsBusy");
-
-        busy = ibusy.intValue();
-        ready = imax.intValue() - ibusy;
-    }
-}
diff --git a/java/org/apache/catalina/cluster/HeartbeatListener.java b/java/org/apache/catalina/cluster/HeartbeatListener.java
deleted file mode 100644 (file)
index eb16275..0000000
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * 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.cluster;
-
-import org.apache.catalina.ContainerEvent;
-import org.apache.catalina.ContainerListener;
-import org.apache.catalina.Engine;
-import org.apache.catalina.Lifecycle;
-import org.apache.catalina.LifecycleEvent;
-import org.apache.catalina.LifecycleListener;
-import org.apache.juli.logging.Log;
-import org.apache.juli.logging.LogFactory;
-
-import org.apache.catalina.connector.Connector;
-
-import java.net.MulticastSocket;
-import java.net.InetAddress;
-import java.net.DatagramPacket;
-import java.io.UnsupportedEncodingException;
-
-import org.apache.tomcat.util.modeler.Registry;
-
-/*
- * Listener to provider informations to mod_heartbeat.c
- * *msg_format = "v=%u&ready=%u&busy=%u"; (message to send).
- * send the muticast merssage using the format...
- * what about the bind(IP. port) only IP makes sense (for the moment).
- * BTW:v  = version :-)
- */
-public class HeartbeatListener
-    implements LifecycleListener, ContainerListener {
-
-    private static Log log = LogFactory.getLog(HeartbeatListener.class);
-
-    /* To allow to select the connector */
-    int port = 0;
-    String host = null;
-    public void setHost(String host) { this.host = host; }
-    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;
-
-    public void setGroup(String ip) { this.ip = ip; }
-    public String getGroup() { return ip; }
-    public void setMultiport(int multiport) { this.multiport = multiport; }
-    public int getMultiport() { return multiport; }
-    public void setTtl(int ttl) { this.ttl = ttl; }
-    public int getTtl() { return ttl; }
-
-    private CollectedInfo coll = 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;
-                } 
-            }
-
-            /* Read busy and ready */
-            if (coll == null) {
-                try {
-                    coll = new CollectedInfo(host, port);
-                } catch (Exception ex) {
-                    log.error("Unable to initialize info collection: " + ex);
-                    coll = null;
-                    return;
-                } 
-            }
-            try {
-                coll.refresh();
-            } catch (Exception ex) {
-                log.error("Unable to collect load information: " + ex);
-                coll = null;
-                return;
-            }
-            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);
-            } catch (Exception ex) {
-                log.error("Unable to send colllected load information: " + ex);
-                s.close();
-                s = null;
-            }
-        }
-    }
-
-}
diff --git a/java/org/apache/catalina/ha/backend/CollectedInfo.java b/java/org/apache/catalina/ha/backend/CollectedInfo.java
new file mode 100644 (file)
index 0000000..1a24ee3
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * 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;
+
+/* for MBean to read ready and busy */
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.ObjectInstance;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.tomcat.util.modeler.Registry;
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+
+/*
+ * Listener to provider informations to mod_heartbeat.c
+ * *msg_format = "v=%u&ready=%u&busy=%u"; (message to send).
+ * send the muticast merssage using the format...
+ * what about the bind(IP. port) only IP makes sense (for the moment).
+ * BTW:v  = version :-)
+ */
+public class CollectedInfo {
+
+    /* Collect info via JMX */
+    protected MBeanServer mBeanServer = null;
+    protected ObjectName objName = null;
+
+    int ready;
+    int busy;
+
+    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);
+        mBeanServer = Registry.getRegistry(null, null).getMBeanServer();
+        String onStr = "*:type=ThreadPool,*";
+        ObjectName objectName = new ObjectName(onStr);
+        Set set = mBeanServer.queryMBeans(objectName, null);
+        Iterator<ObjectInstance> iterator = set.iterator();
+        while (iterator.hasNext()) {
+            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
+             */
+            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)
+                break; /* Only port done */
+            String [] shosts = elenames[1].split("%2F");
+            if (shosts[0].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));
+        
+    }
+
+    public void refresh() throws Exception {
+        if (mBeanServer == null || objName == null) {
+            throw(new Exception("Not initialized!!!"));
+        }
+        Integer imax = (Integer) mBeanServer.getAttribute(objName, "maxThreads");
+
+        // the currentThreadCount could be 0 before the threads are created...
+        // Integer iready = (Integer) mBeanServer.getAttribute(objName, "currentThreadCount");
+
+        Integer ibusy  = (Integer) mBeanServer.getAttribute(objName, "currentThreadsBusy");
+
+        busy = ibusy.intValue();
+        ready = imax.intValue() - ibusy;
+    }
+}
diff --git a/java/org/apache/catalina/ha/backend/HeartbeatListener.java b/java/org/apache/catalina/ha/backend/HeartbeatListener.java
new file mode 100644 (file)
index 0000000..e196cd7
--- /dev/null
@@ -0,0 +1,128 @@
+/*
+ * 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.catalina.ContainerEvent;
+import org.apache.catalina.ContainerListener;
+import org.apache.catalina.Engine;
+import org.apache.catalina.Lifecycle;
+import org.apache.catalina.LifecycleEvent;
+import org.apache.catalina.LifecycleListener;
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+
+import org.apache.catalina.connector.Connector;
+
+import java.net.MulticastSocket;
+import java.net.InetAddress;
+import java.net.DatagramPacket;
+import java.io.UnsupportedEncodingException;
+
+import org.apache.tomcat.util.modeler.Registry;
+
+/*
+ * Listener to provider informations to mod_heartbeat.c
+ * *msg_format = "v=%u&ready=%u&busy=%u"; (message to send).
+ * send the muticast merssage using the format...
+ * what about the bind(IP. port) only IP makes sense (for the moment).
+ * BTW:v  = version :-)
+ */
+public class HeartbeatListener
+    implements LifecycleListener, ContainerListener {
+
+    private static Log log = LogFactory.getLog(HeartbeatListener.class);
+
+    /* To allow to select the connector */
+    int port = 0;
+    String host = null;
+    public void setHost(String host) { this.host = host; }
+    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;
+
+    public void setGroup(String ip) { this.ip = ip; }
+    public String getGroup() { return ip; }
+    public void setMultiport(int multiport) { this.multiport = multiport; }
+    public int getMultiport() { return multiport; }
+    public void setTtl(int ttl) { this.ttl = ttl; }
+    public int getTtl() { return ttl; }
+
+    private CollectedInfo coll = 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;
+                } 
+            }
+
+            /* Read busy and ready */
+            if (coll == null) {
+                try {
+                    coll = new CollectedInfo(host, port);
+                } catch (Exception ex) {
+                    log.error("Unable to initialize info collection: " + ex);
+                    coll = null;
+                    return;
+                } 
+            }
+            try {
+                coll.refresh();
+            } catch (Exception ex) {
+                log.error("Unable to collect load information: " + ex);
+                coll = null;
+                return;
+            }
+            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);
+            } catch (Exception ex) {
+                log.error("Unable to send colllected load information: " + ex);
+                s.close();
+                s = null;
+            }
+        }
+    }
+
+}