从JBoss 4.x到JBoss 7的端口MBean [英] Port MBean from JBoss 4.x to JBoss 7

查看:164
本文介绍了从JBoss 4.x到JBoss 7的端口MBean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们目前正在将一些项目从JBoss 4.x移植到JBoss 7.
到目前为止,除了我们通常用来提供的MBean之外,一切似乎都运行正常简单的管理操作。

we're currently in the process of porting some of our projects from JBoss 4.x to JBoss 7. So far everything seems to work fine, except for our MBeans, which we're commonly using to provide simple management operations.

我现在已经搜索了很长一段时间,但要么我无法使用正确的搜索词,要么我错过了一些知识来弥补JBoss 4.x和JBoss 7中MBean定义之间的差距。

I've been searching for quite a while now, but either I'm incapable of comming up with the correct search term or I'm missing some piece of knowledge to bridge the gap between MBean definition in JBoss 4.x and JBoss 7.

因此,希望有人可以提供我可能缺少的内容或者我必须阅读(可能是一些文档,示例等)。

Thus, hopefully someone can provide a hint on what I might be missing or where I'd have to read on (maybe some documentation, examples etc.)

在Jboss 4.x中,我们的MBean通常如下所示:

In Jboss 4.x our MBeans often look like this:

@Service( objectName = "Domain:Name=SomeMBean",
  xmbean="resource:<path-to-xmbean.xml>")
class SomeMBean 
{
  @EJB
  private SomeService someService;    

  public String someOperation()
  {
     someService.doSomething();
     return "success";
  }
}

我们使用 @Service 用于定义对象名称和xmbean描述符的注释,JBoss会自动注册那些mbeans。

We used the @Service annotation to define the object name and xmbean descriptor and JBoss would automatically register those mbeans.

显然,在JBoss 7中 @Service 注释不再存在,因此需要另一种方法。

Apparently, in JBoss 7 the @Service annotation doesn't exist anymore and thus another approach is needed.

到目前为止,我设法用手动注册MBean平台mbean服务器,但我更喜欢JBoss自动执行此操作。另外,到目前为止,我还没有设法提供方法/参数的描述(尽管那些功能更加出色)。

So far, I managed to register the MBean manually with the platform mbean server, but I'd rather like JBoss to do that automatically. Additionally, I didn't manage to provide descriptions for the methods/parameters so far (although those are more of a nice to have feature).

我会重复问题是为了清晰起见:

I'll repeat the question for clarity:

我如何在JBoss 7(Java EE 6)中定义一个提供以下功能的MBean?

How would I define an MBean in JBoss 7 (Java EE 6) that provides the following features?


  • 自动部署

  • 访问EJB

  • 可通过JConsole或JMX-Console访问(我目前使用Dimitris Andreadis'端口)

  • 提供方法/参数的描述

  • automatic deployment
  • access to EJBs
  • accessible through JConsole or JMX-Console (I'm currently using Dimitris Andreadis' port)
  • provide descriptions for methods/parameters

更新

这是我到目前为止所得到的:

Here's what I got so far:

首先,我找到了这个投影,它使用了CDI用于包装相应注释的任何bean的注入目标,并在 postConstruct()方法中执行JMX注册: http://code.google.com/p/jmx-annotations/ 。此外,扫描找到的MBean以获取类/属性/方法/参数注释,这些注释提供带注释属性的描述。

First, I found this projection, which uses CDI to wrap the injection target of any bean that is annotated accordingly and does the JMX registration in the postConstruct() method: http://code.google.com/p/jmx-annotations/. Additionally, the found MBeans are scanned for class/attribute/method/parameter annotations that provide a description for the annotated property.

然而, postConstruct ()似乎没有为EJB调用方法(我假设这是为了不与EJB容器冲突)。因此,MBeans现在不应该是EJB而是普通的CDI bean。

However, the postConstruct() method seems not to be called for EJBs (I assume that is in order not to clash with the EJB container). Thus MBeans now should not be EJBs but plain CDI beans.

因此,缺点是MBean不会自动实例化。为了解决这个问题,有一个单例bean在启动时循环遍历 BeanManager 中的所有bean,并创建每个找到的MBean的实例。因为MBean仍然有它们的注入目标,所以不会调用它的 postConstruct()方法,并且bean将在MBean服务器中注册。

Thus, however, has the drawback that MBeans are not automatically instantiated. To overcome this, there is a singleton bean that at startup loops through all beans in the BeanManager and creates an instance of every MBean found. Because the MBeans still have their injection target, its postConstruct() method will no be called and the bean will be registered in the MBean server.

以下是启动过程的概述:

Here's a rough overview of the startup procedure:


  • 自定义CDI扩展扫描每个CDI bean以获取自定义@ MBean注释

  • 为每个可以包含注入目标的可忽略MBean

  • 将启动一个单独的bean,它的@PostConstruct方法将创建一个实例MBean

  • 将调用MBean注入目标的 postConstruct()方法,因此MBean在MBean服务器中注册

  • a custom CDI extension scans each CDI bean for the custom @MBean annotation
  • for each elligible MBean the injection target is wrapped
  • a singleton bean will be started which in its @PostConstruct method will create instances of the MBeans
  • the postConstruct() method of the MBean's injection target will be called and thus the MBean is registered in the MBean server

此方法的一个缺点是执行MBean方法时缺少事务上下文(任何EJB调用都将在事务上下文中运行)。但是,如果需要,可以使用CDI拦截器来修复,这将提供事务上下文。 Seam项目似乎有适当的拦截器。

One drawback of this method would be the missing transaction context when executing MBean methods (any EJB calls will run in a transaction context). Howver, this could be fixed using a CDI interceptor that will provide for the transaction context, if needed. The Seam project seems to have appropriate interceptors for that.

我仍然不确定这是否是一个理智和稳定的方法,所以任何建设性的评论,提示等都是非常欢迎。

I'm still not sure if this is a sane and stable approach, so any constructive comments, hints etc. are more than welcome.

推荐答案

使用@Startup的Singleton EJB? http://www.adam-bien.com/roller/abien/entry/singleton_the_simplest_possible_jmx

Singleton EJB with @Startup? http://www.adam-bien.com/roller/abien/entry/singleton_the_simplest_possible_jmx

这篇关于从JBoss 4.x到JBoss 7的端口MBean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆