Example Creating an instance of MBeanInfo

public class Queue extends Basic implements DynamicMBean { // . . .

public static final String NOTIF_STALLED_FULL = "sample.Queue.stalled.full";

public static final String NOTIF_STALLED_EMPTY = "sample.Queue.stalled.empty"; // . . .

public Queue(int queueSize) { // . . . // Attributes attributeInfo[0] = new MBeanAttributeInfo( "QueueSize", Integer.TYPE.getName(),

"Maximum number of items the queue may contain at one time.", true, true, false); attributeInfo[1] = new MBeanAttributeInfo(

"NumberOfConsumers", Integer.TYPE.getName(), "The number of consumers pulling from this Queue.", true, false, false); attributeInfo[2] = new MBeanAttributeInfo(

"NumberOfSuppliers", Integer.TYPE.getName(), "The number of suppliers supplying to this Queue.", true, false, false); attributeInfo[3] = new MBeanAttributeInfo( "QueueFull", Boolean.TYPE.getName(), "Indicates whether or not the Queue is full.", true, false, true); attributeInfo[4] = new MBeanAttributeInfo( "QueueEmpty", Boolean.TYPE.getName(), "Indicates whether or not the Queue is empty.", true, false, true); attributeInfo[5] = new MBeanAttributeInfo( "Suspended", Boolean.TYPE.getName(),

"Indicates whether or not the Queue is currently suspended.", true, false, true);

attributeInfo[6] = new MBeanAttributeInfo( "EndOfInput", Boolean.TYPE.getName(),

"Indicates if end-of-input has been signalled by all suppliers.", true, false, true); attributeInfo[7] = new MBeanAttributeInfo(

"NumberOfItemsProcessed", Long.TYPE.getName(),

"The number of items that have been removed from the Queue.", true, false, false); attributeInfo[8] = new MBeanAttributeInfo( "AddWaitTime", Long.TYPE.getName(),

"No. Milliseconds spent waiting to add because Queue was full.", true, false, false); attributeInfo[9] = new MBeanAttributeInfo( "RemoveWaitTime", Long.TYPE.getName(),

"No. milliseconds spent waiting to remove because Queue was empty.", true, false, false); // Constructors

Class[] signature = {Integer.TYPE}; Constructor constructor = null; MBeanConstructorInfo[] constructorInfo = new MBeanConstructorInfo[1]; try {

constructor = this.getClass().getConstructor(signature); constructorInfo[0] = new MBeanConstructorInfo( "Custom constructor", constructor); } catch (Exception e) { e.printStackTrace();

// Operations

MBeanOperationInfo[] operationInfo = new MBeanOperationInfo[3]; MBeanParameterInfo[] parms = new MBeanParameterInfo[0]; operationInfo[0] = new MBeanOperationInfo(

"suspend", "Suspends processing of the Queue.", parms, Void.TYPE.getName(), MBeanOperationInfo.ACTION); operationInfo[1] = new MBeanOperationInfo(

"resume", "Resumes processing of the Queue.", parms, Void.TYPE.getName(), MBeanOperationInfo.ACTION); operationInfo[2] = new MBeanOperationInfo( "reset", "Resets the state of this MBean.", parms, Void.TYPE.getName(), MBeanOperationInfo.ACTION); // Notifications

MBeanNotificationInfo[] notificationInfo = new MBeanNotificationInfo[1];

String[] notificationTypes = new String[2]; notificationTypes[0] = NOTIF_STALLED_FULL; notificationTypes[1] = NOTIF_STALLED_EMPTY; notificationInfo[0] = new MBeanNotificationInfo( notificationTypes, "StalledQueueNotifications",

"Potential stall notifications emitted by the Queue."

  • ;
  • MBeanInfo

_MBeanInfo = new MBeanInfo( "Queue", "Queue MBean", attributelnfo, constructorInfo, operationInfo, notificationInfo

In this example, 10 attributes, 1 constructor, 3 operations, and 2 notifications describe the Queue as a managed resource. Notice the private variable _MBeaninfo, which is used to hold an instance of the MBeaninfo object that contains the metadata for the Queue MBean. This variable is returned by the getMBeanInfo() method(part of the DynamicMBean interface) that is invoked by a management application to discover the management interface of an MBean.

In this section, we looked at how to create all of the metadata classes necessary to fully describe the management interface of a dynamic MBean. In the next section, we will take a closer look at how the information in the MBeaninfo object must match up to the logic in the implementation of the DynamicMBean interface.

0 0

Post a comment

  • Receive news updates via email from this site