Buttso Does the BLOG Thing :

 

Steve Button

Subscribe to "Buttso Does the BLOG Thing" in Radio UserLand.

 

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.

 
 

Configuring MBeans with OC4J

Configuring MBeans with OC4J

With the 10.0.3 Developer Preview we have out on OTN, you can now deploy, configure and use your very own MBeans.

There's basically three scenarios that we can look at for this.

1 -- Statically deploying to the default application

Here you are deploying your MBean to OC4J and making use of the default application that is provided. This basically deploys the MBean at the container level. To do this, you need to perform two tasks.

Firstly, package your MBean classes into a JAR file and then copy the JAR file to the j2ee/home/applib directory of your OC4J installation. This makes the JAR file accessible to the container.

Secondly, tell OC4J about your MBean by adding an additionaal tag to the default application configuration file. Open j2ee/home/config/application.xml and add an entry of the form:

Where the class attribute is the fully qualified name of your MBean class.

Now start OC4J to have the MBean instantiated. When you go to the JMX Console (http://localhost:8888/adminoc4j/oc4j) you should now see your MBean listed under the default application section.

2 -- Statically deploying with an application

If you are providing MBeans to manage an application, then you can include the MBeans inside of the EAR file and statically configure these using a similar approach to but using the orion-application.xml file for your application.

Firstly, you need to make the MBean classes available to the application. The easiest way to do this is to put them in a JAR file and put the JAR file at the outer level of your EAR file structure.

EAR file:
  /META-INF
    application.xml
    orion-application.xml
  MyMBeans.jar
  web.war
  ejb.jar

Secondly, you need to create an orion-application.xml file. This file is a proprietary deployment descriptor for OC4J and provides OC4J with additional information about your application. The orion-application.xml file resides in the same directory as the standard J2EE application.xml file.

In the orion-application.xml file, you need to provide two pieces of information. The first is to tell OC4J about the additional library it has available -- in this case, the JAR file with your MBeans. The second is to tell OC4J about the MBeans you have.

Given the directory structure above, the orion-application.xml file would contain:

<orion-application>
  
   <!-- Include the library which contains the MBean classes -->
   <library path="MyMBeans.jar"/>

   <!-- Statically register the MBeans for this application -->
   <jmx-mbean objectname=":name=MyMBean" class="your.mbean.class">
     <description>My MBean</description>
   </jmx-mbean>   

   <!-- Add in any other MBeans you have -->

</orion-application>

Lastly, create the EAR archive file and deploy it to OC4J in the usual manner (btw -- have you seen the application deployment task available with http://localhost:8888/adminoc4j).



Now when you view the JMX console you should see your MBean listed under the application name.

3 -- Dynamically registering from an application

The last option I'm discussing here allows you to register MBeans from within the code of an application. This obviously requires the classes that make up the MBean to be available to the application. This can be accomplished using the embedded library technique in option 2, or by using the container level library technique described in section 1.

So assuming that you have the MBean classes you need available to the application, registering your MBean with the OC4J MBeanServer is quite simple.

Here's a code snippet which will register a MBean:

  try
  {
    // get a ref to the MBeanServer
    MBeanServer _mbeanServer = MBeanServerFactory.createMBeanServer();
 
    // Construct the name for the bean
    ObjectName obj = new ObjectName("name=MyMBean");
 
    // Here's the full name of the MBean
    System.out.println("obj = " + obj.getCanonicalName());
 
    // dynamically register the SimpleStandardExtend MBean
    ObjectInstance newobj = _mbeanServer.registerMBean(new SimpleBean(),obj);
  }
  catch(Exception e)
  {
    // there are a whole bunch of detailed exceptions you can catch here
    // Just for simplicity, dump out the stacktrace to show any that occur
    e.printStackTrace();
  }

This will register the MBean with the MBeanServer, allowing it to be displayed in the OC4J JMX console.

Anyway, that's how you basically go about registering MBeans with OC4J.

Bye Now!








© Copyright 2004 buttso.
Last update: 2/19/2004; 3:42:37 PM.

Click here to visit the Radio UserLand website.