Some practical Use Cases where Dynamic MBeans can be used are described below:
Case 1
Consider the case of managing a Web server. If role-based service has
to be implemented, say for example, only the users having admin privileges
can start or stop the server. A dynamic MBean can be written which
contains an operation submitUserInfo taking two arguments, say username and
password. If the username and the password match properly, then getMBeanInfo
will return an MBeanInfo object exposing the operations startService and stopService.
Otherwise, the admin operations will not be exposed.
Case 2
Consider the case of configuring a logger. It is obvious that the logger
should not be active while configuring its properties. A dynamic MBean
can be written which exposes the properties of the logger as read only attributes
when the logger is running. It also exposes an operation to stop the
logger. Once the logger is stopped, the attributes should be read write
so that the properties can be configured. This type of scenario can
easily be addressed by writing a dynamic MBean. A sample dynamic MBean
is also provided in the examples section.