javaee / javaee-spec

Java EE Platform Specification
https://javaee.github.io/javaee-spec
Other
389 stars 69 forks source link

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

Open glassfishrobot opened 11 years ago

glassfishrobot commented 11 years ago

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.

glassfishrobot commented 11 years ago

Reported by rherschke

glassfishrobot commented 11 years ago

@bshannon said: 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.

glassfishrobot commented 7 years ago

This issue was imported from java.net JIRA JAVAEE_SPEC-21