Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 8. JBoss EAP MBean Services
A managed bean, sometimes simply referred to as an MBean, is a type of JavaBean that is created with dependency injection. MBean services are the core building blocks of the JBoss EAP server.
8.1. Writing JBoss MBean Services Copier lienLien copié sur presse-papiers!
Writing a custom MBean service that relies on a JBoss service requires the service interface method pattern. A JBoss MBean service interface method pattern consists of a set of life cycle operations that inform an MBean service when it can create, start, stop, and destroy itself.
You can manage the dependency state using any of the following approaches:
- If you want specific methods to be called on your MBean, declare those methods in your MBean interface. This approach allows your MBean implementation to avoid dependencies on JBoss specific classes.
-
If you are not bothered about dependencies on JBoss specific classes, then you may have your MBean interface extend the
ServiceMBeaninterface andServiceMBeanSupportclass. TheServiceMBeanSupportclass provides implementations of the service lifecycle methods like create, start, and stop. To handle a specific event like thestart()event, you need to overridestartService()method provided by theServiceMBeanSupportclass.
8.1.1. A Standard MBean Example Copier lienLien copié sur presse-papiers!
This section develops two sample MBean services packaged together in a service archive (.sar).
ConfigServiceMBean interface declares specific methods like the start, getTimeout, and stop methods to start, hold, and stop the MBean correctly without using any JBoss specific classes. ConfigService class implements ConfigServiceMBean interface and consequently implements the methods used within that interface.
The PlainThread class extends the ServiceMBeanSupport class and implements the PlainThreadMBean interface. PlainThread starts a thread and uses ConfigServiceMBean.getTimeout() to determine how long the thread should sleep.
Example: MBean Services Class
The jboss-service.xml descriptor shows how the ConfigService class is injected into the PlainThread class using the inject tag. The inject tag establishes a dependency between PlainThreadMBean and ConfigServiceMBean, and thus allows PlainThreadMBean use ConfigServiceMBean easily.
Example: jboss-service.xml Service Descriptor
After writing the MBeans example, you can package the classes and the jboss-service.xml descriptor in the META-INF folder of a service archive (.sar).
8.2. Deploying JBoss MBean Services Copier lienLien copié sur presse-papiers!
Deploy and test sample MBeans in managed domain
Use the following command to deploy the sample MBeans (ServiceMBeanTest.sar) in a managed domain:
deploy ~/Desktop/ServiceMBeanTest.sar --all-server-groups
deploy ~/Desktop/ServiceMBeanTest.sar --all-server-groups
Deploy and test sample MBeans on a standalone server
Use the following command to build and deploy the sample MBeans (ServiceMBeanTest.sar) on a standalone server:
deploy ~/Desktop/ServiceMBeanTest.sar
deploy ~/Desktop/ServiceMBeanTest.sar
Undeploy sample MBeans
Use the following command to undeploy the sample MBeans:
undeploy ServiceMBeanTest.sar
undeploy ServiceMBeanTest.sar