Customise the CMC

You can customise the view you see of a particular server component in two ways: by defining additional MBeans to a server component that you are monitoring, or by adding a custom tab to the console's display.

Adding an MBean

An MBean is a Java class that follows certain rules.  It is added to the server component that hosts the object it describes, and is then registered with an MBeanServer.  As well as a name, each MBean can have attributes and operations, and can fire off notifications when its values change.

To add a new MBean, you would write some Java code to describe the management interface required, and register its name with the MBeanServer.  The following example defines an MBean called ExampleMBean, with a QueueLength attribute.

public interface ExampleMBean {
    int getQueueLength();
    void setQueueLength( int queueLength );
}

public class Example implements ExampleMBean {
    private int queueLength = 1024;

    public synchronized  int getQueueLength() {
        return queueLength;
    }

    public synchronized  void setQueueLength( int queueLength ) {
        this.queueLength = queueLength;
    }
}

public class Main {
    public static void main( String[] args ) throws Exception  {
        DataSource datasource = DataSourceFactory.createDataSource(args);
        Example mBean = new Example();
        ObjectName name = new ObjectName("javadatasrc.server.demo:type=ExampleMBean");
        datasource.getMBeanServer().registerMBean(mBean, name);
    }
}

Having done this, you'll need to add the following line to the server component's XML config file, in order to enable JMX on that server, so that it can be monitored via CMC:

<jmxManager enable="true" rmiRegistryPort="1099" />

Adding new tab to the CMC

Each tab displayed on the CMC is defined in two places.  The content and structure is described in an XML file, while the functionality is defined by creating a Java Swing JPanel component that implements the View interface.

The tabs to be displayed in the console are defined in XML, like so:

<ConsoleConfig>
  <Properties />
  <Views>
    <View Id="datasource_overview">
      <Properties />
    </View>
    <View Id="datasource_peers">
      <Properties />
    </View>
    <View Id="datasource_logging">
      <Properties />
    </View>
    <View Id="explorer">
      <Properties />
    </View>
  </Views>
</ConsoleConfig>

Each <View> then has a separate XML file to describe its content, as well as to identify the Java class that defines its functionality, the location of the help file for that tab, and the location of any graphic to be used as an icon for the tab.  The XML would look something like this:

<View>
     <Class>com.caplin.view.explorer.ExplorerView</Class>
     <Name>Explorer</Name>
     <LongDescription>Generic JMX Explorer View</LongDescription>
     <HelpTopic>explorer.tab</HelpTopic>
     <Icon>/conf/folder_view.png</Icon>

     <Menus>
          <Menu Name="Edit">
               <Action Name="Refresh"/>
          </Menu>
          <Menu Name="Options">
              <Action Name="ShowExplorer"/>
              <Action Name="ShowMessages"/>
          </Menu>
     </Menus>

     <ToolBar>
          <Action Name="Refresh"/>
          <Action Name="ShowExplorer"/>
          <Action Name="ShowMessages"/>
     </ToolBar>
</View>