Java Reference
In-Depth Information
Leave the Class Loader field empty, to tell the
HelloAgent
MBean server to use
the default class loader to find the Java Class value. The agent will use the values
you have entered to create an object name like
HelloAgent:name=helloWorld2
With all the values in place, you are ready to create this new
HelloWorld
instance. At this point, you have three Action options to choose from in the
drop-down list:
■
Create—
Tells the
MBeanServer
to create an MBean using a no-argument
constructor
■
Unregister—
Works only if you have specified an
ObjectName
of an existing
MBean registered in the agent
■
Constructors—
Loads the specified MBean class and presents you with a list
of constructors to use in creation of the MBean
These options are similar to the Operations section of the MBean View. For now,
choose the Create option.
Click the Send Request button, and you will see a success message telling you
the agent created and registered the new MBean. Go back to the Agent View and
verify this using the list of MBeans.
Using constructors with arguments
Remember that your
HelloWorldMBean
implementation class,
HelloWorld
, has two
constructors: the default constructor and a constructor that takes an initial value
for the
Greeting
attribute. Let's register a final instance of the
HelloWorld
MBean
by using this second constructor. To do so, perform the following steps:
Go back to the Admin View and enter appropriate values to create a new
HelloWorld
MBean. Be sure to enter a unique Key value (such as
name=helloWorld3
).
1
This time, select Constructors from the Action list and click the Send
Request button. You will see a list of constructors (in this case, two), one
of which displays a text field for its single input parameter.
2
Type a value for the
Greeting
attribute, and then click the Create button
associated with the constructor. If you entered valid data for the object
name and class fields, you will see the “creation successful” message again.
3
Go back to the Agent View to verify that the MBean list now contains
three instances of the
HelloWorld
MBean.
4