Java Reference
In-Depth Information
registerMBean() method of the MBeanServer object. If the ObjectName is not
unique, the MBeanServer will throw a javax.management.InstanceAlreadyExist-
sException exception, indicating that an MBean was already registered with an
identical ObjectName . The MBean server does not compare actual MBean
object values for equality—only their associated object names.
2.4 Running the agent
Let's review what you have accomplished so far. First, you created your first
MBean, contained in the HelloWorld class. It exposes a single attribute—its greet-
ing—as a manageable resource. (Recall that a manageable resource is any resource
that can be encapsulated by an MBean to provide access and/or configuration.)
Next, you created the HelloAgent class, which is a simple JMX agent. The
agent will contain your MBean and provide you with a mechanism for managing
it. That leaves you with one more task to do: compile, run, and contact this agent.
2.4.1
Compiling the agent
To get the agent started, you need to compile your Java source code and execute
the HelloAgent class. To compile your classes, execute the following command
after ensuring your environment is set up correctly ( CLASSPATH and so forth):
javac jmxbook\ch2\*.java
2.4.2
Running the agent
The following command will run the HelloAgent :
java jmxbook.ch2.HelloAgent
After executing these commands, your agent should be running. The command
prompt will not return, because the HelloAgent process does not exit. However,
you should see the output “HelloAgent is running”, indicating that the agent
has started.
2.4.3
Contacting the agent
To contact the running HelloAgent , you need to use an HTML client. Any web
browser will do the trick. For this example, the HTML adapter of the HelloAgent
defaults to listening on port 9092. If you do not have that port available, go back
to the HelloAgent code, add the following line after the adapter's constructor is
called, and add your own port value:
adapter.setPort( [port value] );
Search WWH ::




Custom Search