Author: remy.maucherat(a)jboss.com
Date: 2008-05-19 13:02:28 -0400 (Mon, 19 May 2008)
New Revision: 631
Modified:
trunk/java/org/jboss/web/cluster/ClusterListener.java
trunk/java/org/jboss/web/cluster/mbeans-descriptors.xml
trunk/webapps/docs/changelog.xml
Log:
- Generate JVM Route for the engine.
- Register listener in JMX.
Modified: trunk/java/org/jboss/web/cluster/ClusterListener.java
===================================================================
--- trunk/java/org/jboss/web/cluster/ClusterListener.java 2008-05-19 11:05:59 UTC (rev
630)
+++ trunk/java/org/jboss/web/cluster/ClusterListener.java 2008-05-19 17:02:28 UTC (rev
631)
@@ -34,6 +34,8 @@
import java.util.HashMap;
import java.util.Iterator;
+import javax.management.ObjectName;
+
import org.apache.catalina.Container;
import org.apache.catalina.ContainerEvent;
import org.apache.catalina.ContainerListener;
@@ -48,10 +50,12 @@
import org.apache.catalina.Service;
import org.apache.catalina.connector.Connector;
import org.apache.catalina.core.StandardContext;
+import org.apache.catalina.core.StandardServer;
import org.apache.catalina.util.StringManager;
import org.apache.tomcat.util.IntrospectionUtils;
import org.apache.tomcat.util.buf.CharChunk;
import org.apache.tomcat.util.buf.UEncoder;
+import org.apache.tomcat.util.modeler.Registry;
import org.jboss.logging.Logger;
@@ -60,8 +64,6 @@
* This listener communicates with a front end mod_cluster enabled proxy to
* automatically maintain the node configuration according to what is
* deployed.
- *
- * FIXME: listeners don't get registered in JMX: this one should register itself
*/
public class ClusterListener
implements LifecycleListener, ContainerListener {
@@ -97,6 +99,12 @@
protected State state = State.OK;
+ /**
+ * JMX registration information.
+ */
+ protected ObjectName oname;
+
+
// ------------------------------------------------------------- Properties
@@ -246,12 +254,55 @@
* node.
*/
protected void startServer(Server server) {
+
+ // JMX registration
+ if (oname==null) {
+ try {
+ oname = new ObjectName(((StandardServer) server).getDomain() +
":type=ClusterListener");
+ Registry.getRegistry(null, null).registerComponent(this, oname, null);
+ } catch (Exception e) {
+ log.error("Error registering ",e);
+ }
+ }
+
Service[] services = server.findServices();
for (int i = 0; i < services.length; i++) {
services[i].getContainer().addContainerListener(this);
- ((Lifecycle) services[i].getContainer()).addLifecycleListener(this);
- config((Engine) services[i].getContainer());
- Container[] children = services[i].getContainer().findChildren();
+
+ Engine engine = (Engine) services[i].getContainer();
+ if (engine.getJvmRoute() == null) {
+ // Automagical JVM route (address + port + engineName)
+ try {
+ Connector connector =
findProxyConnector(engine.getService().findConnectors());
+ InetAddress localAddress =
+ (InetAddress)
IntrospectionUtils.getProperty(connector.getProtocolHandler(), "address");
+ String hostName = null;
+ if (localAddress == null) {
+ Socket connection = null;
+ if (proxyAddress == null) {
+ connection = new Socket("127.0.0.1", proxyPort);
+ } else {
+ connection = new Socket(proxyAddress, proxyPort);
+ }
+ localAddress = connection.getLocalAddress();
+ }
+ if (localAddress != null) {
+ hostName = localAddress.getHostName();
+ } else {
+ // Fallback
+ hostName = "127.0.0.1";
+ }
+ String jvmRoute = hostName + ":" + connector.getPort() +
":" + engine.getName();
+ engine.setJvmRoute(jvmRoute);
+ log.info("Engine [" + engine.getName() + "] will use
jvmRoute value: [" + jvmRoute + "]");
+ } catch (Exception e) {
+ throw new IllegalStateException("JVMRoute must be set, automatic
generation failed", e);
+ }
+ }
+
+ ((Lifecycle) engine).addLifecycleListener(this);
+ config(engine);
+ Container[] children = engine.findChildren();
for (int j = 0; j < children.length; j++) {
children[j].addContainerListener(this);
Container[] children2 = children[j].findChildren();
@@ -268,6 +319,16 @@
* node.
*/
protected void stopServer(Server server) {
+
+ // JMX unregistration
+ if (oname==null) {
+ try {
+ Registry.getRegistry(null, null).unregisterComponent(oname);
+ } catch (Exception e) {
+ log.error("Error registering ",e);
+ }
+ }
+
Service[] services = server.findServices();
for (int i = 0; i < services.length; i++) {
services[i].getContainer().removeContainerListener(this);
@@ -297,12 +358,7 @@
// Collect configuration from the connectors and service and call CONFIG
Connector connector = findProxyConnector(engine.getService().findConnectors());
HashMap<String, String> parameters = new HashMap<String, String>();
- if (engine.getJvmRoute() == null) {
- // FIXME: automagical JVM route (some hash of address + port + engineName ?)
- throw new IllegalStateException("JVMRoute must be set");
- } else {
- parameters.put("JVMRoute", engine.getJvmRoute());
- }
+ parameters.put("JVMRoute", engine.getJvmRoute());
boolean reverseConnection =
Boolean.TRUE.equals(IntrospectionUtils.getProperty(connector.getProtocolHandler(),
"reverseConnection"));
boolean ssl =
Modified: trunk/java/org/jboss/web/cluster/mbeans-descriptors.xml
===================================================================
--- trunk/java/org/jboss/web/cluster/mbeans-descriptors.xml 2008-05-19 11:05:59 UTC (rev
630)
+++ trunk/java/org/jboss/web/cluster/mbeans-descriptors.xml 2008-05-19 17:02:28 UTC (rev
631)
@@ -21,6 +21,18 @@
type="java.lang.String"
writeable="false"/>
+ <attribute name="proxyPort"
+ description="Port used to connect to the proxy"
+ type="int"/>
+
+ <attribute name="proxyAddress"
+ description="Address used to connect to the proxy"
+ type="java.net.InetAddress"/>
+
+ <attribute name="socketTimeout"
+ description="Connection timeout for communication with the
proxy"
+ type="int"/>
+
<operation name="reset"
description="Move the node out of an error state"
impact="ACTION"
Modified: trunk/webapps/docs/changelog.xml
===================================================================
--- trunk/webapps/docs/changelog.xml 2008-05-19 11:05:59 UTC (rev 630)
+++ trunk/webapps/docs/changelog.xml 2008-05-19 17:02:28 UTC (rev 631)
@@ -16,6 +16,31 @@
<body>
+<section name="JBoss Web 2.1.1.CR4 (remm)">
+ <subsection name="General">
+ <changelog>
+ </changelog>
+ </subsection>
+ <subsection name="Catalina">
+ <changelog>
+ <update>
+ ClusterListener will automatically generate a JVMRoute in most cases. (remm)
+ </update>
+ <update>
+ Register ClusterListener in JMX. (remm)
+ </update>
+ </changelog>
+ </subsection>
+ <subsection name="Coyote">
+ <changelog>
+ </changelog>
+ </subsection>
+ <subsection name="Jasper">
+ <changelog>
+ </changelog>
+ </subsection>
+</section>
+
<section name="JBoss Web 2.1.1.CR3 (remm)">
<subsection name="General">
<changelog>