javaee-spec
  1. javaee-spec
  2. JAVAEE_SPEC-21

Provide @Resource and/or @Inject injection of the currently used platform MBeanServer to any managed bean (EJB Component and/or CDI managed bean)

    Details

    • Type: New Feature New Feature
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Labels:
      None

      Description

      My proposal is to specify in EE 7 that MBeanServer injection should be able in a container environment.

      The reason for this proposal is, that some AS provide it's own platform specific MBeanServer, so that ManagementFactory.getPlatformMBeanServer() will not provide the correct MBeanServer.

      To build platform independent components, the container should provide the correct MBeanServer via @Resource or @Inject.

      With this, one for example can implement an interceptor with @AroundConstruct to do the registration of a MXBean in a container environment.

      This would pass the rule of separating concerns and will get a clear EJB Pojo as well.

      Example:

      @Inherited
      @InterceptorBinding
      @Target({TYPE}) @Retention(RUNTIME) public @interface MBean {
          @NotBinding String value() default "";
      }
      
      @Interceptor @MBean
      public class MBeanInterceptor {
      
          @Resource
          MBeanServer server;
      
          @PostConstruct
          public void registerBean(InvocationContext ctx) {
              ctx.proceed();
              ObjectName on = ... // get objectname from annotation value
              server.register(on, ctx.getTarget());
              // or do the neccessary DynamicMBean work here...
          }
      
          @PreDestroy
          public void unregister(InvocationContext ctx) {
              ObjectName on = ... // get objectname from annotation
              server.unregister(on);
              ctx.proceed();
          }
      }
      
      @Singleton @Startup @MBean("com.example:type=MyMXBean")
      public class MyMXBean {
      // ...
      }
      

      So with @Resource injection, this will work even on appservers with its own MBeanServer, not only with JVM PlatformServer, but the developer do not care about this.

      Next, @Resource injection could be used also in a normal EJB to do some client work (observe notifications, get attributes aso.) with a registered mbean without the need to distinguish about the right MBeanServer to be used.

        Activity

        Hide
        Bill Shannon added a comment -

        For some time I've hoped that we would more fully define the use of JMX in Java EE
        applications. Sadly, it hasn't been a priority. Defining access to an MBeanServer
        is just a part of it.

        This is something we should consider to consider in future releases, but without
        significant customer feedback that this is important it's unlikely this will be
        addressed anytime soon.

        Show
        Bill Shannon added a comment - For some time I've hoped that we would more fully define the use of JMX in Java EE applications. Sadly, it hasn't been a priority. Defining access to an MBeanServer is just a part of it. This is something we should consider to consider in future releases, but without significant customer feedback that this is important it's unlikely this will be addressed anytime soon.

          People

          • Assignee:
            ldemichiel
            Reporter:
            rherschke
          • Votes:
            5 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: