The JMX technology provides the tools for building distributed, Web-based, modular and dynamic solutions for managing and monitoring devices, applications, and service-driven networks.
— Oracle Documentation
https://www.oracle.com/technetwork/java/javase/tech/javamanagement-140525.html
https://www.oracle.com/technetwork/java/javase/tech/javamanagement-140525.html
Type | Description |
---|---|
Standard |
JavaBean implémentant une interface définie au moment du dévelopement |
Dynamic |
Implémente l’interface DynamicMBean |
Type | Description |
---|---|
Open |
Dynamic MBean qui respecte certaines conventions |
Model |
MBean dynamiques générique entièrement configurable |
-
Interface dont le nom finit par
MBean
-
Seules les propriétés et les attributs définis seront exposés
-
Classe d’implémentation nommée comme l’interface sans le suffixe
MBean
public interface FooMBean {
String getName();
String getValue();
void setValue(String value);
void printNameAndValue();
}
public class Foo implements FooMBean {
private final String name;
private String value;
@Inject
public Foo(NamingService service) {
this.name = service.generateUniqueNameFor(this);
}
@Override
public String getName() { return name; }
@Override
public String getValue() { return value; }
@Override
public void setValue(String value) { this.value = value; }
@Override
public void printNameAndValue() {
System.out.println(name + ":" + value);
}
}
-
Identifie le MBean de manière unique
-
Composé :
-
D’un nom de domaine
-
Un ensemble de paires nom-valeur
-
-
p.e.
ch.frankel.jmx:type=MyBean,foo=bar
var foo = new Foo(new NamingService());
var mBeanServer =
ManagementFactory.getPlatformMBeanServer();
try {
var name = ObjectName.getInstance(
"ch.frankel.hesge:type=MBean,name=foo");
mBeanServer.registerMBean(foo, name);
} catch (MalformedObjectNameException |
NotCompliantMBeanException |
InstanceAlreadyExistsException |
MBeanRegistrationException e) {
e.printStackTrace();
}
var mBeanServer = ManagementFactory.getPlatformMBeanServer();
try {
var name = ObjectName.getInstance(
"ch.frankel.hesge:type=MBean,name=foo");
mBeanServer.registerMBean(foo, name);
var attribute = new Attribute("value", "newValue");
mBeanServer.setAttribute(oName, attribute);
} catch (OperationsException |
MBeanException |
ReflectionException e) {
e.printStackTrace();
}