![]() |
|||
![]() |
![]() ![]() |
![]() |
![]() ![]() |
![]() |
![]() ![]() |
![]() |
| |||||||
24.2.2 Using Legacy Standard MBean ProxiesOnce the proxies are generated and available in your application's classpath, their usage is straightforward. For each of the proxy objects it wants to use, the application needs to instantiate its proxy class and then bind it to a ProxyHandler object. The application is responsible for creating and binding all of the proxies that it wants to use, and it must unbind and free them when they are no longer needed. Note - The binding methods in the Proxy interface in previous releases of Java DMK are deprecated in favor of the new setServer and getServer methods. This change is necessary so that proxies can be bound to any ProxyHandler object, to enable for both local and remote proxies. All parameters for binding the proxy can be given in its constructor, which makes it very simple to instantiate and bind a proxy in one step. Example 24-2 Instantiating and Binding a Legacy Proxy in One Step
If the class name of your proxy is not known at compile time, you will have to instantiate its class dynamically. In the following code, we obtain the proxy class name that corresponds to an MBean, and we call its first constructor. This must be the constructor that takes an ObjectInstance identifying the MBean, and we must dynamically build the call to this constructor. We then call the setServer method to bind the new proxy instance. Example 24-3 Instantiating and Binding a Legacy Proxy Class Dynamically
Once a proxy is bound, you can access the attributes and operations of its MBean through direct calls to the proxy object, as shown in the following example. Example 24-4 Accessing a Standard MBean Through Its Legacy Proxy
24.2.3 Running the Legacy Standard Proxy ExampleThe examplesDir/legacy/SimpleClients directory contains all of the files for the ClientMBeanProxy application that demonstrates the use of standard MBean proxies.
|
$ cd examplesDir/legacy/SimpleClients/ $ javac -classpath classpath *.java |
Generate the proxy MBeans classes and compile them. To do this, from the same directory as above, type the following commands:
$ installDir/SUNWjdmk/jdmk5.0/proxygen SimpleStandard $ javac -classpath classpath SimpleStandardProxy.java |
Start the base agent in a terminal window with the following command:
$ java -classpath classpath BaseAgent |
The agent creates the RMI connector server to which the client application will establish a connection, and then it waits for management operations.
Wait for the agent to be completely initialized, then, in another window on the same host, start the management application with the following command:
$ java -classpath classpath ClientMBeanProxy |
Press Enter in the manager window to step through the example.
As seen in the code examples, the client application instantiates the proxy objects to access the MBean it has created in the base agent.
Press Enter one last time to exit the manager application, but leave the base agent running for the next example.
![]() ![]() |