The MBean server interceptor example in the examples directory shows you two of the main functions of MBean server interceptors, forwarding requests to a specific MBean server interceptor, and creating virtual MBeans.
The examplesDir/current/MBeanServerInterceptor directory contains the following source files:
MasterMBeanServerInterceptor.java. This master interceptor receives all requests from the MBean server and, depending on the value of the domain part of the ObjectName, forwards them to one of the following interceptors:
The default MBean server interceptor.
Another MBean server interceptor, the FileMBeanServerInterceptor.
FileMBeanServerInterceptor.java. This is an MBean server interceptor that mirrors the contents of a file system directory by faking MBeans which represent files and directories. These MBeans are completely virtual. The FileMBeanServerInterceptor owns a reserved domain name, the file domain in this example, which is used by the MasterMBeanServerInterceptor to decide which requests to divert to the FileMBeanServerInterceptor.
Agent.java. This class implements a simple Java DMK agent which instantiates a MasterMBeanServerInterceptor and plugs in a FileMBeanServerInterceptor. This class shows how to instantiate the MasterMBeanServerInterceptor, how to plug it into the MBean Server, and how to plug the DefaultMBeanServerInterceptor and FileMBeanServerInterceptor into the MasterMBeanServerInterceptor.
Compile all files in the examplesDir/current/MBeanServerInterceptor directory with the javac command.
For example, on the Solaris platform, type:
$ cd examplesDir/current/MBeanServerInterceptor/ $ javac -classpath classpath *.java
Run the example using the classes you have just built, by typing the following command in a terminal window:
$ java \ -Djavax.management.builder.initial=com.sun.jdmk.JdmkMBeanServerBuilder \ Agent
Here, you can see that the javax.management.builder.initial system property is set to com.sun.jdmk.JdmkMBeanServerBuilder before the Agent is started, as explained in 7.3 Changing the Default Interceptor.
Interact with the agent through the standard input and output in the window where it was started.
Load the agent's URL in your web browser:
You only see the MBeans registered in the DefaultMBeanInterceptor, namely the connector and adaptor MBeans, and the MBeanServerDelegate.
Press Enter to insert the FileMBeanServerInterceptor and view the files from the local directory as virtual MBeans.
Reload the agent's URL in your web browser to view the new MBeans:
Press Enter to stop the agent.