You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by kf...@apache.org on 2017/04/10 08:03:39 UTC
svn commit: r1790789 - in /tomcat/trunk: java/org/apache/catalina/tribes/
java/org/apache/catalina/tribes/group/ java/org/apache/catalina/tribes/jmx/
webapps/docs/
Author: kfujino
Date: Mon Apr 10 08:03:39 2017
New Revision: 1790789
URL: http://svn.apache.org/viewvc?rev=1790789&view=rev
Log:
Add JMX support for Tribes component.
-TODO: Membership, Sender, Receiver, Interceptors.
Added:
tomcat/trunk/java/org/apache/catalina/tribes/JmxChannel.java (with props)
tomcat/trunk/java/org/apache/catalina/tribes/group/GroupChannelMBean.java (with props)
tomcat/trunk/java/org/apache/catalina/tribes/jmx/
tomcat/trunk/java/org/apache/catalina/tribes/jmx/JmxRegistry.java (with props)
tomcat/trunk/java/org/apache/catalina/tribes/jmx/LocalStrings.properties (with props)
Modified:
tomcat/trunk/java/org/apache/catalina/tribes/group/GroupChannel.java
tomcat/trunk/webapps/docs/changelog.xml
Added: tomcat/trunk/java/org/apache/catalina/tribes/JmxChannel.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/tribes/JmxChannel.java?rev=1790789&view=auto
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/tribes/JmxChannel.java (added)
+++ tomcat/trunk/java/org/apache/catalina/tribes/JmxChannel.java Mon Apr 10 08:03:39 2017
@@ -0,0 +1,58 @@
+/*
+ * 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.tribes;
+
+
+public interface JmxChannel {
+
+ /**
+ * If set to true, this channel is registered with jmx.
+ * @return true if this channel will be registered with jmx.
+ */
+ public boolean isJmxEnabled();
+
+ /**
+ * If set to true, this channel is registered with jmx.
+ * @param jmxEnabled set to true if this channel should be registered with jmx.
+ */
+ public void setJmxEnabled(boolean jmxEnabled);
+
+ /**
+ * Return the jmx domain which this channel is registered.
+ * @return jmxDomain
+ */
+ public String getJmxDomain();
+
+ /**
+ * Set the jmx domain which this channel should be registered.
+ * @param jmxDomain The jmx domain which this channel should be registered.
+ */
+ public void setJmxDomain(String jmxDomain);
+
+ /**
+ * Return the jmx prefix which will be used with channel ObjectName.
+ * @return jmxPrefix
+ */
+ public String getJmxPrefix();
+
+ /**
+ * Set the jmx prefix which will be used with channel ObjectName.
+ * @param jmxPrefix The jmx prefix which will be used with channel ObjectName.
+ */
+ public void setJmxPrefix(String jmxPrefix);
+
+}
Propchange: tomcat/trunk/java/org/apache/catalina/tribes/JmxChannel.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tomcat/trunk/java/org/apache/catalina/tribes/group/GroupChannel.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/tribes/group/GroupChannel.java?rev=1790789&r1=1790788&r2=1790789&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/tribes/group/GroupChannel.java (original)
+++ tomcat/trunk/java/org/apache/catalina/tribes/group/GroupChannel.java Mon Apr 10 08:03:39 2017
@@ -22,6 +22,8 @@ import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
+import javax.management.ObjectName;
+
import org.apache.catalina.tribes.ByteMessage;
import org.apache.catalina.tribes.Channel;
import org.apache.catalina.tribes.ChannelException;
@@ -32,6 +34,7 @@ import org.apache.catalina.tribes.Channe
import org.apache.catalina.tribes.ChannelSender;
import org.apache.catalina.tribes.ErrorHandler;
import org.apache.catalina.tribes.Heartbeat;
+import org.apache.catalina.tribes.JmxChannel;
import org.apache.catalina.tribes.ManagedChannel;
import org.apache.catalina.tribes.Member;
import org.apache.catalina.tribes.MembershipListener;
@@ -42,6 +45,7 @@ import org.apache.catalina.tribes.group.
import org.apache.catalina.tribes.io.BufferPool;
import org.apache.catalina.tribes.io.ChannelData;
import org.apache.catalina.tribes.io.XByteBuffer;
+import org.apache.catalina.tribes.jmx.JmxRegistry;
import org.apache.catalina.tribes.util.Arrays;
import org.apache.catalina.tribes.util.Logs;
import org.apache.catalina.tribes.util.StringManager;
@@ -55,7 +59,9 @@ import org.apache.juli.logging.LogFactor
* The channel has an chain of interceptors that can modify the message or perform other logic.<br>
* It manages a complete group, both membership and replication.
*/
-public class GroupChannel extends ChannelInterceptorBase implements ManagedChannel {
+public class GroupChannel extends ChannelInterceptorBase
+ implements ManagedChannel, JmxChannel, GroupChannelMBean {
+
private static final Log log = LogFactory.getLog(GroupChannel.class);
protected static final StringManager sm = StringManager.getManager(GroupChannel.class);
@@ -111,6 +117,26 @@ public class GroupChannel extends Channe
protected String name = null;
/**
+ * the jmx domain which this channel is registered.
+ */
+ private String jmxDomain = "ClusterChannel";
+
+ /**
+ * the jmx prefix which will be used with channel ObjectName.
+ */
+ private String jmxPrefix = "";
+
+ /**
+ * If set to true, this channel is registered with jmx.
+ */
+ private boolean jmxEnabled = true;
+
+ /**
+ * the ObjectName of this channel.
+ */
+ private ObjectName oname = null;
+
+ /**
* Creates a GroupChannel. This constructor will also
* add the first interceptor in the GroupChannel.<br>
* The first interceptor is always the channel itself.
@@ -432,6 +458,9 @@ public class GroupChannel extends Channe
public synchronized void start(int svc) throws ChannelException {
setupDefaultStack();
if (optionCheck) checkOptionFlags();
+ // register jmx
+ JmxRegistry jmxRegistry = JmxRegistry.getRegistry(this);
+ if (jmxRegistry != null) this.oname = jmxRegistry.registerJmx(",component=Channel", this);
super.start(svc);
if ( hbthread == null && heartbeat ) {
hbthread = new HeartbeatThread(this,heartbeatSleeptime);
@@ -452,6 +481,10 @@ public class GroupChannel extends Channe
hbthread = null;
}
super.stop(svc);
+ if (oname != null) {
+ JmxRegistry.getRegistry(this).unregisterJmx(oname);
+ oname = null;
+ }
}
/**
@@ -640,6 +673,36 @@ public class GroupChannel extends Channe
this.name = name;
}
+ @Override
+ public boolean isJmxEnabled() {
+ return jmxEnabled;
+ }
+
+ @Override
+ public void setJmxEnabled(boolean jmxEnabled) {
+ this.jmxEnabled = jmxEnabled;
+ }
+
+ @Override
+ public String getJmxDomain() {
+ return jmxDomain;
+ }
+
+ @Override
+ public void setJmxDomain(String jmxDomain) {
+ this.jmxDomain = jmxDomain;
+ }
+
+ @Override
+ public String getJmxPrefix() {
+ return jmxPrefix;
+ }
+
+ @Override
+ public void setJmxPrefix(String jmxPrefix) {
+ this.jmxPrefix = jmxPrefix;
+ }
+
/**
*
* <p>Title: Interceptor Iterator</p>
Added: tomcat/trunk/java/org/apache/catalina/tribes/group/GroupChannelMBean.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/tribes/group/GroupChannelMBean.java?rev=1790789&view=auto
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/tribes/group/GroupChannelMBean.java (added)
+++ tomcat/trunk/java/org/apache/catalina/tribes/group/GroupChannelMBean.java Mon Apr 10 08:03:39 2017
@@ -0,0 +1,62 @@
+/*
+ * 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.tribes.group;
+
+import java.io.Serializable;
+
+import org.apache.catalina.tribes.ChannelException;
+import org.apache.catalina.tribes.ChannelListener;
+import org.apache.catalina.tribes.ErrorHandler;
+import org.apache.catalina.tribes.Member;
+import org.apache.catalina.tribes.MembershipListener;
+import org.apache.catalina.tribes.UniqueId;
+
+public interface GroupChannelMBean {
+
+ // Attributes
+ public boolean getOptionCheck();
+
+ public boolean getHeartbeat();
+
+ public long getHeartbeatSleeptime();
+
+ // Operations
+ public void start(int svc) throws ChannelException;
+
+ public void stop(int svc) throws ChannelException;
+
+ public UniqueId send(Member[] destination, Serializable msg, int options)
+ throws ChannelException;
+
+ public UniqueId send(Member[] destination, Serializable msg, int options, ErrorHandler handler)
+ throws ChannelException;
+
+ public void addMembershipListener(MembershipListener listener);
+
+ public void addChannelListener(ChannelListener listener);
+
+ public void removeMembershipListener(MembershipListener listener);
+
+ public void removeChannelListener(ChannelListener listener);
+
+ public boolean hasMembers() ;
+
+ public Member[] getMembers() ;
+
+ public Member getLocalMember(boolean incAlive);
+
+}
Propchange: tomcat/trunk/java/org/apache/catalina/tribes/group/GroupChannelMBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: tomcat/trunk/java/org/apache/catalina/tribes/jmx/JmxRegistry.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/tribes/jmx/JmxRegistry.java?rev=1790789&view=auto
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/tribes/jmx/JmxRegistry.java (added)
+++ tomcat/trunk/java/org/apache/catalina/tribes/jmx/JmxRegistry.java Mon Apr 10 08:03:39 2017
@@ -0,0 +1,112 @@
+/*
+ * 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.tribes.jmx;
+
+import java.lang.management.ManagementFactory;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.NotCompliantMBeanException;
+import javax.management.ObjectName;
+
+import org.apache.catalina.tribes.Channel;
+import org.apache.catalina.tribes.JmxChannel;
+import org.apache.catalina.tribes.util.StringManager;
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+
+public class JmxRegistry {
+
+ private static final Log log = LogFactory.getLog(JmxRegistry.class);
+ protected static final StringManager sm = StringManager.getManager(JmxRegistry.class);
+ private static ConcurrentHashMap<String, JmxRegistry> registryCache = new ConcurrentHashMap<>();
+
+ private MBeanServer mbserver = ManagementFactory.getPlatformMBeanServer();
+ private ObjectName baseOname = null;
+
+ private JmxRegistry() {
+ }
+
+ public static JmxRegistry getRegistry(Channel channel) {
+ JmxRegistry registry = registryCache.get(channel.getName());
+ if (registry != null) return registry;
+
+ if (!(channel instanceof JmxChannel)) return null;
+ JmxChannel jmxChannel = (JmxChannel) channel;
+ if (!jmxChannel.isJmxEnabled()) return null;
+ ObjectName baseOn = createBaseObjectName(jmxChannel.getJmxDomain(),
+ jmxChannel.getJmxPrefix(), channel.getName());
+ if (baseOn == null) return null;
+ // create registry
+ registry = new JmxRegistry();
+ registry.baseOname = baseOn;
+ registryCache.putIfAbsent(channel.getName(), registry);
+ return registry;
+ }
+
+ private static ObjectName createBaseObjectName(String domain, String prefix, String name) {
+ if (domain == null) {
+ log.warn(sm.getString("jmxRegistry.no.domain"));
+ return null;
+ }
+ ObjectName on = null;
+ StringBuilder sb = new StringBuilder(domain);
+ sb.append(':');
+ sb.append(prefix);
+ sb.append("type=Channel,channel=");
+ sb.append(name);
+ try {
+ on = new ObjectName(sb.toString());
+ } catch (MalformedObjectNameException e) {
+ log.error(sm.getString("jmxRegistry.objectName.failed", sb.toString()), e);
+ }
+ return on;
+ }
+
+ public ObjectName registerJmx(String keyprop, Object bean) {
+ String oNameStr = baseOname.toString() + keyprop;
+ ObjectName oName = null;
+ try {
+ oName = new ObjectName(oNameStr);
+ mbserver.registerMBean(bean, oName);
+ } catch (NotCompliantMBeanException e) {
+ log.warn(sm.getString("jmxRegistry.registerJmx.notCompliant", bean), e);
+ return null;
+ } catch (MalformedObjectNameException e) {
+ log.error(sm.getString("jmxRegistry.objectName.failed", oNameStr), e);
+ return null;
+ } catch (Exception e) {
+ log.error(sm.getString("jmxRegistry.registerJmx.failed", bean, oNameStr), e);
+ return null;
+ }
+ return oName;
+ }
+
+ public void unregisterJmx(ObjectName oname) {
+ if (oname ==null) return;
+ try {
+ mbserver.unregisterMBean(oname);
+ } catch (InstanceNotFoundException e) {
+ log.warn(sm.getString("jmxRegistry.unregisterJmx.notFound", oname), e);
+ } catch (Exception e) {
+ log.warn(sm.getString("jmxRegistry.unregisterJmx.failed", oname), e);
+ }
+ }
+
+}
Propchange: tomcat/trunk/java/org/apache/catalina/tribes/jmx/JmxRegistry.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: tomcat/trunk/java/org/apache/catalina/tribes/jmx/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/tribes/jmx/LocalStrings.properties?rev=1790789&view=auto
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/tribes/jmx/LocalStrings.properties (added)
+++ tomcat/trunk/java/org/apache/catalina/tribes/jmx/LocalStrings.properties Mon Apr 10 08:03:39 2017
@@ -0,0 +1,21 @@
+# 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.
+
+jmxRegistry.no.domain=JMX domain is not specified
+jmxRegistry.objectName.failed=The requested ObjectName [{0}] is not valid
+jmxRegistry.registerJmx.notCompliant=The requested object[{0}] is not compliant with JMX specification
+jmxRegistry.registerJmx.failed=Failed to register object [{0}] with name [{1}]
+jmxRegistry.unregisterJmx.notFound=The requested ObjectName [{0}] has not been registered in the MBeanServer
+jmxRegistry.unregisterJmx.failed=Failed to unregister MBean with name [{0}]
\ No newline at end of file
Propchange: tomcat/trunk/java/org/apache/catalina/tribes/jmx/LocalStrings.properties
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1790789&r1=1790788&r2=1790789&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Mon Apr 10 08:03:39 2017
@@ -100,6 +100,13 @@
</fix>
</changelog>
</subsection>
+ <subsection name="Tribes">
+ <changelog>
+ <add>
+ Add JMX support for Tribes components. (kfujino)
+ </add>
+ </changelog>
+ </subsection>
<subsection name="jdbc-pool">
<changelog>
<scode>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org