Author: markt Date: Sun Sep 2 22:26:09 2012 New Revision: 1380072 URL: http://svn.apache.org/viewvc?rev=1380072&view=rev Log: Cluster JMX improvements - expose cluster members - expose deployer
Modified: tomcat/tc7.0.x/trunk/ (props changed) tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/deploy/mbeans-descriptors.xml tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/jmx/ClusterJmxHelper.java tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/membership/MemberImpl.java tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/membership/mbeans-descriptors.xml tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Propchange: tomcat/tc7.0.x/trunk/ ------------------------------------------------------------------------------ Merged /tomcat/trunk:r1379639,1379647,1379649,1379665,1380066 Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/deploy/mbeans-descriptors.xml URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/deploy/mbeans-descriptors.xml?rev=1380072&r1=1380071&r2=1380072&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/deploy/mbeans-descriptors.xml (original) +++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/deploy/mbeans-descriptors.xml Sun Sep 2 22:26:09 2012 @@ -19,10 +19,10 @@ <mbean name="FarmWarDeployer" className="org.apache.catalina.mbeans.ClassNameMBean" - description="Farm Deployer - Broken" + description="Farm Deployer" domain="Catalina" group="Cluster" - type="org.apache.catalina.ha.deploy.FarmWarDeployer"/> + type="org.apache.catalina.ha.deploy.FarmWarDeployer"> <attribute name="deployDir" description="Deployment directory." @@ -39,4 +39,5 @@ name="watchEnabled" description="Is watching enabled?" type="boolean"/> + </mbean> </mbeans-descriptors> Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/jmx/ClusterJmxHelper.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/jmx/ClusterJmxHelper.java?rev=1380072&r1=1380071&r2=1380072&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/jmx/ClusterJmxHelper.java (original) +++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/jmx/ClusterJmxHelper.java Sun Sep 2 22:26:09 2012 @@ -23,9 +23,7 @@ import javax.management.ObjectName; import org.apache.catalina.core.StandardEngine; import org.apache.catalina.core.StandardHost; -import org.apache.catalina.ha.authenticator.ClusterSingleSignOn; import org.apache.catalina.ha.deploy.FarmWarDeployer; -import org.apache.catalina.ha.session.DeltaManager; import org.apache.catalina.ha.tcp.SimpleTcpCluster; import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; @@ -34,7 +32,11 @@ import org.apache.tomcat.util.modeler.Re /** * * @author Filip Hanik + * + * @deprecated Unused - registration now happens via + * {@link org.apache.catalina.util.LifecycleMBeanBase} */ +@Deprecated public class ClusterJmxHelper { protected static Registry registry = Registry.getRegistry(null,null); @@ -83,9 +85,7 @@ public class ClusterJmxHelper { protected static void initDefaultCluster() { initMetaData(SimpleTcpCluster.class); - initMetaData(DeltaManager.class); initMetaData(FarmWarDeployer.class); //not functional yet - initMetaData(ClusterSingleSignOn.class); //not functional yet } public static boolean registerDefaultCluster(SimpleTcpCluster cluster) { Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java?rev=1380072&r1=1380071&r2=1380072&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java (original) +++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java Sun Sep 2 22:26:09 2012 @@ -24,6 +24,9 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import javax.management.ObjectName; import org.apache.catalina.Container; import org.apache.catalina.Context; @@ -40,13 +43,13 @@ import org.apache.catalina.ha.ClusterLis import org.apache.catalina.ha.ClusterManager; import org.apache.catalina.ha.ClusterMessage; import org.apache.catalina.ha.ClusterValve; -import org.apache.catalina.ha.jmx.ClusterJmxHelper; import org.apache.catalina.ha.session.ClusterSessionListener; import org.apache.catalina.ha.session.DeltaManager; import org.apache.catalina.ha.session.JvmRouteBinderValve; import org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener; import org.apache.catalina.ha.session.SessionMessage; import org.apache.catalina.ha.util.IDynamicProperty; +import org.apache.catalina.mbeans.MBeanUtils; import org.apache.catalina.tribes.Channel; import org.apache.catalina.tribes.ChannelListener; import org.apache.catalina.tribes.Member; @@ -54,7 +57,7 @@ import org.apache.catalina.tribes.Member import org.apache.catalina.tribes.group.GroupChannel; import org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor; import org.apache.catalina.tribes.group.interceptors.TcpFailureDetector; -import org.apache.catalina.util.LifecycleBase; +import org.apache.catalina.util.LifecycleMBeanBase; import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; import org.apache.tomcat.util.IntrospectionUtils; @@ -65,7 +68,6 @@ import org.apache.tomcat.util.res.String * setting up a cluster and provides callers with a valid multicast * receiver/sender. * - * FIXME remove install/remove/start/stop context dummys * FIXME wrote testcases * * @author Filip Hanik @@ -73,8 +75,8 @@ import org.apache.tomcat.util.res.String * @author Peter Rossbach * @version $Id$ */ -public class SimpleTcpCluster extends LifecycleBase - implements CatalinaCluster, LifecycleListener, IDynamicProperty, +public class SimpleTcpCluster extends LifecycleMBeanBase + implements CatalinaCluster, LifecycleListener, IDynamicProperty, MembershipListener, ChannelListener{ public static final Log log = LogFactory.getLog(SimpleTcpCluster.class); @@ -154,6 +156,7 @@ public class SimpleTcpCluster extends Li private List<Valve> valves = new ArrayList<Valve>(); private org.apache.catalina.ha.ClusterDeployer clusterDeployer; + private ObjectName onameClusterDeployer; /** * Listeners of messages @@ -174,6 +177,9 @@ public class SimpleTcpCluster extends Li private int channelStartOptions = Channel.DEFAULT; + private Map<Member,ObjectName> memberOnameMap = + new ConcurrentHashMap<Member,ObjectName>(); + // ------------------------------------------------------------- Properties public SimpleTcpCluster() { @@ -626,11 +632,20 @@ public class SimpleTcpCluster extends Li log.trace(sm.getString("SimpleTcpCluster.event.log", lifecycleEvent.getType(), lifecycleEvent.getData())); } + // ------------------------------------------------------ public + @SuppressWarnings("deprecation") @Override - protected void initInternal() { - // NOOP + protected void initInternal() throws LifecycleException { + super.initInternal(); + if (clusterDeployer != null) { + StringBuilder name = new StringBuilder("type=Cluster"); + Container container = getContainer(); + name.append(MBeanUtils.getContainerKeyProperties(container)); + name.append(",component=Deployer"); + onameClusterDeployer = register(clusterDeployer, name.toString()); + } } @@ -653,9 +668,7 @@ public class SimpleTcpCluster extends Li channel.addChannelListener(this); channel.start(channelStartOptions); if (clusterDeployer != null) clusterDeployer.start(); - //register JMX objects - ClusterJmxHelper.registerDefaultCluster(this); - // Notify our interested LifecycleListeners + registerMember(channel.getLocalMember(false)); } catch (Exception x) { log.error("Unable to start cluster.", x); throw new LifecycleException(x); @@ -737,6 +750,7 @@ public class SimpleTcpCluster extends Li setState(LifecycleState.STOPPING); + unregisterMember(channel.getLocalMember(false)); if (clusterDeployer != null) clusterDeployer.stop(); this.managers.clear(); try { @@ -745,9 +759,6 @@ public class SimpleTcpCluster extends Li channel.removeChannelListener(this); channel.removeMembershipListener(this); this.unregisterClusterValve(); - //unregister JMX objects - ClusterJmxHelper.unregisterDefaultCluster(this); - } catch (Exception x) { log.error("Unable to stop cluster valve.", x); } @@ -755,8 +766,12 @@ public class SimpleTcpCluster extends Li @Override - protected void destroyInternal() { - // NOOP + protected void destroyInternal() throws LifecycleException { + if (onameClusterDeployer != null) { + unregister(onameClusterDeployer); + onameClusterDeployer = null; + } + super.destroyInternal(); } @@ -834,6 +849,9 @@ public class SimpleTcpCluster extends Li if (log.isInfoEnabled()) log.info("Replication member added:" + member); // Notify our interested LifecycleListeners fireLifecycleEvent(BEFORE_MEMBERREGISTER_EVENT, member); + + registerMember(member); + // Notify our interested LifecycleListeners fireLifecycleEvent(AFTER_MEMBERREGISTER_EVENT, member); } catch (Exception x) { @@ -854,6 +872,9 @@ public class SimpleTcpCluster extends Li if (log.isInfoEnabled()) log.info("Received member disappeared:" + member); // Notify our interested LifecycleListeners fireLifecycleEvent(BEFORE_MEMBERUNREGISTER_EVENT, member); + + unregisterMember(member); + // Notify our interested LifecycleListeners fireLifecycleEvent(AFTER_MEMBERUNREGISTER_EVENT, member); } catch (Exception x) { @@ -952,4 +973,52 @@ public class SimpleTcpCluster extends Li public void setChannelStartOptions(int channelStartOptions) { this.channelStartOptions = channelStartOptions; } + + + // --------------------------------------------------------------------- JMX + + @SuppressWarnings("deprecation") + @Override + protected String getDomainInternal() { + Container container = getContainer(); + if (container == null) { + return null; + } + return MBeanUtils.getDomain(container); + } + + @SuppressWarnings("deprecation") + @Override + protected String getObjectNameKeyProperties() { + StringBuilder name = new StringBuilder("type=Cluster"); + + Container container = getContainer(); + if (container != null) { + name.append(MBeanUtils.getContainerKeyProperties(container)); + } + + return name.toString(); + } + + @SuppressWarnings("deprecation") + private void registerMember(Member member) { + // JMX registration + StringBuilder name = new StringBuilder("type=Cluster"); + Container container = getContainer(); + if (container != null) { + name.append(MBeanUtils.getContainerKeyProperties(container)); + } + name.append(",component=Member,name="); + name.append(ObjectName.quote(member.getName())); + + ObjectName oname = register(member, name.toString()); + memberOnameMap.put(member, oname); + } + + private void unregisterMember(Member member) { + ObjectName oname = memberOnameMap.remove(member); + if (oname != null) { + unregister(oname); + } + } } Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/membership/MemberImpl.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/membership/MemberImpl.java?rev=1380072&r1=1380071&r2=1380072&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/membership/MemberImpl.java (original) +++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/membership/MemberImpl.java Sun Sep 2 22:26:09 2012 @@ -474,6 +474,10 @@ public class MemberImpl implements Membe } } + public int getMsgCount() { + return this.msgCount; + } + /** * Contains information on how long this member has been online. * The result is the number of milli seconds this member has been Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/membership/mbeans-descriptors.xml URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/membership/mbeans-descriptors.xml?rev=1380072&r1=1380071&r2=1380072&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/membership/mbeans-descriptors.xml (original) +++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/membership/mbeans-descriptors.xml Sun Sep 2 22:26:09 2012 @@ -97,4 +97,69 @@ impact="ACTION" returnType="void"/> </mbean> + <mbean + name="MemberImpl" + description="Cluster member" + domain="Catalina" + group="Cluster" + type="org.apache.catalina.tribes.membership.MemberImpl"> + <attribute + name="failing" + description="Has a problem been observed with this member (failing is worse than suspect)" + type="boolean" + is="true" + writeable="false"/> + <attribute + name="hostname" + description="The name of the host where this member is located" + type="String" + writeable="false"/> + <attribute + name="memberAliveTime" + description="The number of milliseconds since this member was created" + type="long" + writeable="false"/> + <attribute + name="msgCount" + description="The number of messages send by this member" + type="int" + writeable="false"/> + <attribute + name="name" + description="The unique name of this member within the cluster" + type="String" + writeable="false"/> + <attribute + name="port" + description="The tcp port the member is listening on" + type="int" + writeable="false"/> + <attribute + name="ready" + description="Is this member ready to send messages" + type="boolean" + is="true" + writeable="false"/> + <attribute + name="securePort" + description="The tcp(SSL) port the member is listening on" + type="int" + writeable="false"/> + <attribute + name="serviceStartTime" + description="The time the member was started" + type="long" + writeable="false"/> + <attribute + name="suspect" + description="Has a potential problem been observed with this member (failing is worse than suspect)" + type="boolean" + is="true" + writeable="false"/> + <attribute + name="udpPort" + description="The upd port the member is listening on" + type="int" + writeable="false"/> + </mbean> </mbeans-descriptors> Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1380072&r1=1380071&r2=1380072&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original) +++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Sun Sep 2 22:26:09 2012 @@ -53,6 +53,16 @@ They eventually become mixed with the numbered issues. (I.e., numbered issues to not "pop up" wrt. others). --> +<section name="Tomcat 7.0.31 (markt)"> + <subsection name="Cluster"> + <changelog> + <add> + Make the cluster members and the cluster deployer associated with the + cluster accessible via JMX. (markt) + </add> + </changelog> + </subsection> +</section> <section name="Tomcat 7.0.30 (markt)"> <subsection name="Catalina"> <changelog> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org