Author: markt Date: Sun Sep 2 22:06:06 2012 New Revision: 1380066 URL: http://svn.apache.org/viewvc?rev=1380066&view=rev Log: Make Cluster member information available via JMX Restructure cluster MBean names to better group MBeans in JConsole UI.
Modified: tomcat/trunk/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java tomcat/trunk/java/org/apache/catalina/tribes/membership/MemberImpl.java tomcat/trunk/java/org/apache/catalina/tribes/membership/mbeans-descriptors.xml Modified: tomcat/trunk/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java?rev=1380066&r1=1380065&r2=1380066&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java (original) +++ tomcat/trunk/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java Sun Sep 2 22:06:06 2012 @@ -24,6 +24,7 @@ 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; @@ -163,6 +164,8 @@ public class SimpleTcpCluster extends Li private int channelStartOptions = Channel.DEFAULT; + private Map<Member,ObjectName> memberOnameMap = new ConcurrentHashMap<>(); + // ------------------------------------------------------------- Properties public SimpleTcpCluster() { @@ -608,11 +611,12 @@ public class SimpleTcpCluster extends Li protected void initInternal() throws LifecycleException { super.initInternal(); if (clusterDeployer != null) { - StringBuilder name = new StringBuilder("type=ClusterDeployer"); + StringBuilder name = new StringBuilder("type=Cluster"); Container container = getContainer(); if (container != null) { name.append(container.getMBeanKeyProperties()); } + name.append(",component=Deployer"); onameClusterDeployer = register(clusterDeployer, name.toString()); } } @@ -637,6 +641,7 @@ public class SimpleTcpCluster extends Li channel.addChannelListener(this); channel.start(channelStartOptions); if (clusterDeployer != null) clusterDeployer.start(); + registerMember(channel.getLocalMember(false)); } catch (Exception x) { log.error("Unable to start cluster.", x); throw new LifecycleException(x); @@ -718,6 +723,7 @@ public class SimpleTcpCluster extends Li setState(LifecycleState.STOPPING); + unregisterMember(channel.getLocalMember(false)); if (clusterDeployer != null) clusterDeployer.stop(); this.managers.clear(); try { @@ -816,6 +822,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) { @@ -836,6 +845,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) { @@ -931,4 +943,25 @@ public class SimpleTcpCluster extends Li return name.toString(); } + + private void registerMember(Member member) { + // JMX registration + StringBuilder name = new StringBuilder("type=Cluster"); + Container container = getContainer(); + if (container != null) { + name.append(container.getMBeanKeyProperties()); + } + 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/trunk/java/org/apache/catalina/tribes/membership/MemberImpl.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/tribes/membership/MemberImpl.java?rev=1380066&r1=1380065&r2=1380066&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/tribes/membership/MemberImpl.java (original) +++ tomcat/trunk/java/org/apache/catalina/tribes/membership/MemberImpl.java Sun Sep 2 22:06:06 2012 @@ -458,6 +458,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/trunk/java/org/apache/catalina/tribes/membership/mbeans-descriptors.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/tribes/membership/mbeans-descriptors.xml?rev=1380066&r1=1380065&r2=1380066&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/tribes/membership/mbeans-descriptors.xml (original) +++ tomcat/trunk/java/org/apache/catalina/tribes/membership/mbeans-descriptors.xml Sun Sep 2 22:06:06 2012 @@ -92,4 +92,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> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org