This commit is contained in:
2024-11-30 19:03:49 +08:00
commit 1e6763c160
3806 changed files with 737676 additions and 0 deletions

View File

@@ -0,0 +1,144 @@
/*
* 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.Set;
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) {
if (channel == null || channel.getName() == null) {
return null;
}
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;
// It doesn't matter if existing object gets over-written. This object
// holds minimal state and that state will be the same for all objects
// created for the same channel.
registryCache.put(channel.getName(), registry);
return registry;
}
public static void removeRegistry(Channel channel, boolean clear) {
JmxRegistry registry = registryCache.get(channel.getName());
if (registry == null) return;
if (clear) {
registry.clearMBeans();
}
registryCache.remove(channel.getName());
}
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);
if (mbserver.isRegistered(oName)) {
mbserver.unregisterMBean(oName);
}
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);
}
}
private void clearMBeans() {
String query = baseOname.toString() + ",*";
try {
ObjectName name = new ObjectName(query);
Set<ObjectName> onames = mbserver.queryNames(name, null);
for (ObjectName objectName : onames) {
unregisterJmx(objectName);
}
} catch (MalformedObjectNameException e) {
log.error(sm.getString("jmxRegistry.objectName.failed", query), e);
}
}
}

View File

@@ -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.failed=Failed to register object [{0}] with name [{1}]
jmxRegistry.registerJmx.notCompliant=The requested object[{0}] is not compliant with JMX specification
jmxRegistry.unregisterJmx.failed=Failed to unregister MBean with name [{0}]
jmxRegistry.unregisterJmx.notFound=The requested ObjectName [{0}] has not been registered in the MBeanServer

View File

@@ -0,0 +1,16 @@
# 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.registerJmx.failed=Fallo al registrar el objeto [{0}] con nombre [{1}]\n

View File

@@ -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=Le nom de domaine JMX n'est pas spécifié
jmxRegistry.objectName.failed=L''ObjectName [{0}] demandé est invalide
jmxRegistry.registerJmx.failed=Echec de l''enregistrement de l''objet [{0}] avec le nom [{1}]
jmxRegistry.registerJmx.notCompliant=L''objet demandé [{0}] n''est pas compatible avec la spécification JMX
jmxRegistry.unregisterJmx.failed=Echec du désenregistrement du MBean nommé [{0}]
jmxRegistry.unregisterJmx.notFound=L''ObjectName [{0}] demandé n''a pas été enregistré dans le serveur JMX

View File

@@ -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 ドメインが未指定です。
jmxRegistry.objectName.failed=不正なオブジェクト名 [{0}] を要求されました。
jmxRegistry.registerJmx.failed=オブジェクト [{0}] を名前 [{1}] で登録できませんでした。
jmxRegistry.registerJmx.notCompliant=要求されたオブジェクト[{0}]はJMX仕様に準拠していません。
jmxRegistry.unregisterJmx.failed=名前[{0}]のMBeanの登録を解除できませんでした。
jmxRegistry.unregisterJmx.notFound=要求されたObjectName [{0}]はMBeanServerに登録されていません。

View File

@@ -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 도메인이 지정되지 않았습니다.
jmxRegistry.objectName.failed=요청된 ObjectName [{0}]은(는) 유효하지 않습니다.
jmxRegistry.registerJmx.failed=[{1}](이)라는 이름으로 객체 [{0}]을(를) 등록하지 못했습니다.
jmxRegistry.registerJmx.notCompliant=요청된 객체 [{0}]은(는) JMX 스펙과 호환되지 않습니다.
jmxRegistry.unregisterJmx.failed=[{0}](이)라는 이름의 MBean에 대한 등록을 제거하지 못했습니다.
jmxRegistry.unregisterJmx.notFound=요청된 객체[{0}]는 MBeanServer에 등록되지 않았습니다.

View File

@@ -0,0 +1,17 @@
# 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域
jmxRegistry.registerJmx.failed=无法注册名称为 [{1}] 的对象 [{0}]