JMX Component MBeans

Fabric3 supports exporting components as JMX Beans using the Fabric3 management annotations.

Publishing Components as MBeans

Composite scoped components (and system extension components) can be exposed as JMX MBeans using the org.fabric3.api.annotations.management.Management and the org.fabric3.api.annotations.management.ManagementOperation annotations. The following is an example that publishes an MBean with an attribute and two management operations:

@Scope("COMPOSITE")
@Management(description = "A calculator component")
public class HelloServiceImpl implements HelloService {

    @ManagementOperation(description = "The greeting text")
    public void setGreeting(String greeting) {
        //...
    }
    
    @ManagementOperation(description = "The greeting text")
    public String getGreeting() {
        //...
    }

    @ManagementOperation(description = "Start auditing")
    public void startAudit() {
        // ...
    }

    @ManagementOperation(description = "Stop auditing")
    public void stopAudit() {
        // ..
    }
}

It is also possible to set the JMX group on the @Management attribute, which is used to display MBeans in a common hierarchy in a JMX client:

@Scope("COMPOSITE")
@Management(group = "Hello Components", description = "A calculator component")
public class HelloServiceImpl implements HelloService {
   //...
}

JMX Security

JMX authorization can be enabled at an MBean or operation level using the readRoles and writeRoles parameters for @Management and the rolesAllowed parameter for @ManagementOperation. By default on system components, readRoles is set to ROLE_FABRIC3_ADMIN and ROLE_FABRIC3_OBSERVER while writeRoles is set to ROLE_FABRIC3_ADMIN. The following example enables custom authorization:

@Scope("COMPOSITE")
@Management(readRoles={"ROLE_OPERATIONS", "ROLE_ADMIN"}, writeRoles={"ROLE_ADMIN"})
public class HelloServiceImpl implements HelloService {

    @ManagementOperation(rolesAllowed={"ROLE_SUPER_ADMIN"})
    public void setSecretGreeting(String greeting) {
        //...
    }
    
    @ManagementOperation(rolesAllowed={"ROLE_SUPER_ADMIN"})
    public String getSecretGreeting() {
        //...
    }

    @ManagementOperation
    public void startAudit() {
        // ...
    }

    @ManagementOperation
    public void stopAudit() {
        // ..
    }
}