如何让 JMX 变得简单

发布于 2024-09-18 04:24:27 字数 148 浏览 3 评论 0原文

我需要向 JMX 公开 30 个不同类中的大约 60 个操作。使用DynamicMBean 来实现它有点烦人。我正在寻找一种快速而优雅的方法来做到这一点。

我知道 Spring 有一个很好的注释方式,但我没有在这个项目中使用 spring。

I need to expose about 60 operations in a 30 different classes to JMX. Making it with DynamicMBean is a bit annoying. I am looking for a fast and elegant way to do it.

I know that Spring has a nice way with annotations but i am not using spring in this project.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

烟沫凡尘 2024-09-25 04:24:27

请看一下我的 SimpleJmx Java 包,它旨在使用注释通过 JMX 轻松发布 Bean。它也有客户端代码。

快速代码示例:

// you can also use the platform mbean server
JmxServer jmxServer = new JmxServer(8000);
jmxServer.start();
// register our lookupCache object defined below
jmxServer.register(lookupCache);
...
jmxServer.stop();

以下是定义 bean 的方法。

@JmxResource(domainName = "j256", description = "Lookup cache")
public class LookupCache {
    @JmxAttributeField(description = "Number of hits in the cache")
    private int hitCount;
    ...

    @JmxOperation(description = "Flush the cache")
    public void flushCache() {
       ...
    }
}

欢迎反馈。

Please take a look at my SimpleJmx Java package which is designed to easily publish beans via JMX using annotations. It also has client code as well.

Quick code sample:

// you can also use the platform mbean server
JmxServer jmxServer = new JmxServer(8000);
jmxServer.start();
// register our lookupCache object defined below
jmxServer.register(lookupCache);
...
jmxServer.stop();

Here's how to define a bean.

@JmxResource(domainName = "j256", description = "Lookup cache")
public class LookupCache {
    @JmxAttributeField(description = "Number of hits in the cache")
    private int hitCount;
    ...

    @JmxOperation(description = "Flush the cache")
    public void flushCache() {
       ...
    }
}

Feedback welcome.

阳光的暖冬 2024-09-25 04:24:27

如果只是一组简单的操作,您可以使用 Clojure contrib 中提供的 JMX 支持:

Clojure Contrib

Clojure 编译为 Java,因此与当前项目集成不会有太多问题。

If it's just a set of easy operations, you could use the JMX support provided in Clojure contrib:

Clojure Contrib

Clojure compiles to Java so you would not have much problems integrating with your current project.

囚你心 2024-09-25 04:24:27

您是否看过 @MXBean 注释,它可能就是您所追求的,并且是 Java 6 的一部分。

Have you seen the @MXBean annotation, it may be what you're after, and is part of Java 6.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文