The MBean interceptor example in the examples directory shows you two of the main functions of MBean interceptors, forwarding requests to a specific MBean interceptor, and creating virtual MBeans.
The examplesDir/MBeanInterceptor directory contains the following source files:
MasterInterceptor.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 interceptor
Another MBean interceptor, the FileMBeanInterceptor
FileMBeanInterceptor.java. This is an MBean interceptor that mirrors the contents of a file system directory by faking MBeans which represent files and directories. These MBeans are completely virtual. The FileMBeanInterceptor owns a reserved domain name, the file domain in this example, which is used by the MasterInterceptor to decide which requests to divert to the FileMBeanInterceptor
Agent.java. This class implements a simple Java DMK agent which instantiates a MasterInterceptor and plugs in a FileMBeanInterceptor. This class shows how to instantiate the MasterInterceptor, how to plug it into the MBeanServer, and how to plug the DefaultMBeanInterceptor and FileMBeanInterceptor into the MasterInterceptor.
Compile all files in the examplesDir/MBeanInterceptor directory with the javac command.
For example, on the Solaris platform, type:
$ cd examplesDir/MBeanInterceptor/ $ javac -classpath classpath *.java |
Run the example using the classes you have just built, by typing the following command in a terminal window:
$ java -classpath classpath Agent |
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:
http://localhost:8082/ |
You only see the MBeans registered in the DefaultMBeanInterceptor, namely the connector and adaptor MBeans, and the MBeanServerDelegate.
Press Enter to insert the FileMBeanInterceptor 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:
http://localhost:8082/ |
Press Enter to stop the agent.