Class StandardEmitterMBean
- All Implemented Interfaces:
DynamicMBean, MBeanRegistration, NotificationBroadcaster, NotificationEmitter
An MBean whose management interface is determined by reflection on a Java interface, and that emits notifications.
The following example shows how to use the public constructor
StandardEmitterMBean(implementation, mbeanInterface, emitter) to
create an MBean emitting notifications with any
implementation class name Impl, with a management
interface defined (as for current Standard MBeans) by any interface
Intf, and with any implementation of the interface
NotificationEmitter. The example uses the class
NotificationBroadcasterSupport as an implementation
of the interface NotificationEmitter.
MBeanServer mbs;
...
final String[] types = new String[] {"sun.disc.space","sun.disc.alarm"};
final MBeanNotificationInfo info = new MBeanNotificationInfo(
types,
Notification.class.getName(),
"Notification about disc info.");
final NotificationEmitter emitter =
new NotificationBroadcasterSupport(info);
final Intf impl = new Impl(...);
final Object mbean = new StandardEmitterMBean(
impl, Intf.class, emitter);
mbs.registerMBean(mbean, objectName);
- Since:
- 1.6
- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedStandardEmitterMBean(Class<?> mbeanInterface, boolean isMXBean, NotificationEmitter emitter) Make an MBean whose management interface is specified bymbeanInterface, and where notifications are handled by the givenNotificationEmitter.protectedStandardEmitterMBean(Class<?> mbeanInterface, NotificationEmitter emitter) Make an MBean whose management interface is specified bymbeanInterface, and where notifications are handled by the givenNotificationEmitter.<T>StandardEmitterMBean(T implementation, Class<T> mbeanInterface, boolean isMXBean, NotificationEmitter emitter) Make an MBean whose management interface is specified bymbeanInterface, with the given implementation and where notifications are handled by the givenNotificationEmitter.<T>StandardEmitterMBean(T implementation, Class<T> mbeanInterface, NotificationEmitter emitter) Make an MBean whose management interface is specified bymbeanInterface, with the given implementation and where notifications are handled by the givenNotificationEmitter. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) Adds a listener to this MBean.Returns an array indicating, for each notification this MBean may send, the name of the Java class of the notification and the notification type.voidRemoves a listener from this MBean.voidremoveNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) Removes a listener from this MBean.voidSends a notification.Methods declared in class StandardMBean
cacheMBeanInfo, getAttribute, getAttributes, getCachedMBeanInfo, getClassName, getConstructors, getDescription, getDescription, getDescription, getDescription, getDescription, getDescription, getDescription, getImpact, getImplementation, getImplementationClass, getMBeanInfo, getMBeanInterface, getParameterName, getParameterName, invoke, postDeregister, postRegister, preDeregister, preRegister, setAttribute, setAttributes, setImplementationModifier and TypeMethodDescriptionprotected voidcacheMBeanInfo(MBeanInfo info) Customization hook: cache the MBeanInfo built for this object.getAttribute(String attribute) Obtain the value of a specific attribute of the Dynamic MBean.getAttributes(String[] attributes) Get the values of several attributes of the Dynamic MBean.protected MBeanInfoCustomization hook: Return the MBeanInfo cached for this object.protected StringgetClassName(MBeanInfo info) Customization hook: Get the className that will be used in the MBeanInfo returned by this MBean.protected MBeanConstructorInfo[]getConstructors(MBeanConstructorInfo[] ctors, Object impl) Customization hook: Get the MBeanConstructorInfo[] that will be used in the MBeanInfo returned by this MBean.protected StringCustomization hook: Get the description that will be used in the MBeanAttributeInfo returned by this MBean.protected StringCustomization hook: Get the description that will be used in the MBeanConstructorInfo returned by this MBean.protected StringgetDescription(MBeanConstructorInfo ctor, MBeanParameterInfo param, int sequence) Customization hook: Get the description that will be used for the sequence MBeanParameterInfo of the MBeanConstructorInfo returned by this MBean.protected StringCustomization hook: Get the description that will be used in the MBeanFeatureInfo returned by this MBean.protected StringgetDescription(MBeanInfo info) Customization hook: Get the description that will be used in the MBeanInfo returned by this MBean.protected StringCustomization hook: Get the description that will be used in the MBeanOperationInfo returned by this MBean.protected StringgetDescription(MBeanOperationInfo op, MBeanParameterInfo param, int sequence) Customization hook: Get the description that will be used for the sequence MBeanParameterInfo of the MBeanOperationInfo returned by this MBean.protected intgetImpact(MBeanOperationInfo info) Customization hook: Get the impact flag of the operation that will be used in the MBeanOperationInfo returned by this MBean.Get the implementation of this Standard MBean (or MXBean).Class<?> Get the class of the implementation of this Standard MBean (or MXBean).Get theMBeanInfofor this MBean.final Class<?> Get the Management Interface of this Standard MBean (or MXBean).protected StringgetParameterName(MBeanConstructorInfo ctor, MBeanParameterInfo param, int sequence) Customization hook: Get the name that will be used for the sequence MBeanParameterInfo of the MBeanConstructorInfo returned by this MBean.protected StringgetParameterName(MBeanOperationInfo op, MBeanParameterInfo param, int sequence) Customization hook: Get the name that will be used for the sequence MBeanParameterInfo of the MBeanOperationInfo returned by this MBean.Allows an action to be invoked on the Dynamic MBean.voidAllows the MBean to perform any operations needed after having been unregistered in the MBean server.voidpostRegister(Boolean registrationDone) Allows the MBean to perform any operations needed after having been registered in the MBean server or after the registration has failed.voidAllows the MBean to perform any operations it needs before being unregistered by the MBean server.preRegister(MBeanServer server, ObjectName name) Allows the MBean to perform any operations it needs before being registered in the MBean server.voidsetAttribute(Attribute attribute) Set the value of a specific attribute of the Dynamic MBean.setAttributes(AttributeList attributes) Sets the values of several attributes of the Dynamic MBean.voidsetImplementation(Object implementation) Replace the implementation object wrapped in this object.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Creates and returns a copy of this object.booleanIndicates whether some other object is "equal to" this one.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.Finalization is deprecated and subject to removal in a future release.final Class<?> getClass()Returns the runtime class of thisObject.inthashCode()Returns a hash code value for this object.final voidnotify()Wakes up a single thread that is waiting on this object's monitor.final voidWakes up all threads that are waiting on this object's monitor.toString()Returns a string representation of the object.final voidwait()Causes the current thread to wait until it is awakened, typically by being notified or interrupted.final voidwait(long timeoutMillis) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.final voidwait(long timeoutMillis, int nanos) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
-
Constructor Details
-
StandardEmitterMBean
public <T> StandardEmitterMBean(T implementation, Class<T> mbeanInterface, NotificationEmitter emitter) Make an MBean whose management interface is specified by
mbeanInterface, with the given implementation and where notifications are handled by the givenNotificationEmitter. The resultant MBean implements theNotificationEmitterinterface by forwarding its methods toemitter. It is legal and useful forimplementationandemitterto be the same object.If
emitteris an instance ofNotificationBroadcasterSupportthen the MBean'ssendNotificationmethod will callemitter.sendNotification.The array returned by
getNotificationInfo()on the new MBean is a copy of the array returned byemitter.getNotificationInfo()at the time of construction. If the array returned byemitter.getNotificationInfo()later changes, that will have no effect on this object'sgetNotificationInfo().- Type Parameters:
T- the implementation type of the MBean- Parameters:
implementation- the implementation of the MBean interface.mbeanInterface- a Standard MBean interface.emitter- the object that will handle notifications.- Throws:
IllegalArgumentException- if thembeanInterfacedoes not follow JMX design patterns for Management Interfaces, or if the givenimplementationdoes not implement the specified interface, or ifemitteris null.
-
StandardEmitterMBean
public <T> StandardEmitterMBean(T implementation, Class<T> mbeanInterface, boolean isMXBean, NotificationEmitter emitter) Make an MBean whose management interface is specified by
mbeanInterface, with the given implementation and where notifications are handled by the givenNotificationEmitter. This constructor can be used to make either Standard MBeans or MXBeans. The resultant MBean implements theNotificationEmitterinterface by forwarding its methods toemitter. It is legal and useful forimplementationandemitterto be the same object.If
emitteris an instance ofNotificationBroadcasterSupportthen the MBean'ssendNotificationmethod will callemitter.sendNotification.The array returned by
getNotificationInfo()on the new MBean is a copy of the array returned byemitter.getNotificationInfo()at the time of construction. If the array returned byemitter.getNotificationInfo()later changes, that will have no effect on this object'sgetNotificationInfo().- Type Parameters:
T- the implementation type of the MBean- Parameters:
implementation- the implementation of the MBean interface.mbeanInterface- a Standard MBean interface.isMXBean- If true, thembeanInterfaceparameter names an MXBean interface and the resultant MBean is an MXBean.emitter- the object that will handle notifications.- Throws:
IllegalArgumentException- if thembeanInterfacedoes not follow JMX design patterns for Management Interfaces, or if the givenimplementationdoes not implement the specified interface, or ifemitteris null.
-
StandardEmitterMBean
Make an MBean whose management interface is specified by
mbeanInterface, and where notifications are handled by the givenNotificationEmitter. The resultant MBean implements theNotificationEmitterinterface by forwarding its methods toemitter.If
emitteris an instance ofNotificationBroadcasterSupportthen the MBean'ssendNotificationmethod will callemitter.sendNotification.The array returned by
getNotificationInfo()on the new MBean is a copy of the array returned byemitter.getNotificationInfo()at the time of construction. If the array returned byemitter.getNotificationInfo()later changes, that will have no effect on this object'sgetNotificationInfo().This constructor must be called from a subclass that implements the given
mbeanInterface.- Parameters:
mbeanInterface- a StandardMBean interface.emitter- the object that will handle notifications.- Throws:
IllegalArgumentException- if thembeanInterfacedoes not follow JMX design patterns for Management Interfaces, or ifthisdoes not implement the specified interface, or ifemitteris null.
-
StandardEmitterMBean
protected StandardEmitterMBean(Class<?> mbeanInterface, boolean isMXBean, NotificationEmitter emitter) Make an MBean whose management interface is specified by
mbeanInterface, and where notifications are handled by the givenNotificationEmitter. This constructor can be used to make either Standard MBeans or MXBeans. The resultant MBean implements theNotificationEmitterinterface by forwarding its methods toemitter.If
emitteris an instance ofNotificationBroadcasterSupportthen the MBean'ssendNotificationmethod will callemitter.sendNotification.The array returned by
getNotificationInfo()on the new MBean is a copy of the array returned byemitter.getNotificationInfo()at the time of construction. If the array returned byemitter.getNotificationInfo()later changes, that will have no effect on this object'sgetNotificationInfo().This constructor must be called from a subclass that implements the given
mbeanInterface.- Parameters:
mbeanInterface- a StandardMBean interface.isMXBean- If true, thembeanInterfaceparameter names an MXBean interface and the resultant MBean is an MXBean.emitter- the object that will handle notifications.- Throws:
IllegalArgumentException- if thembeanInterfacedoes not follow JMX design patterns for Management Interfaces, or ifthisdoes not implement the specified interface, or ifemitteris null.
-
-
Method Details
-
removeNotificationListener
public void removeNotificationListener(NotificationListener listener) throws ListenerNotFoundException Description copied from interface:NotificationBroadcasterRemoves a listener from this MBean. If the listener has been registered with different handback objects or notification filters, all entries corresponding to the listener will be removed.- Specified by:
removeNotificationListenerin interfaceNotificationBroadcaster- Parameters:
listener- A listener that was previously added to this MBean.- Throws:
ListenerNotFoundException- The listener is not registered with the MBean.- See Also:
-
removeNotificationListener
public void removeNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) throws ListenerNotFoundException Description copied from interface:NotificationEmitterRemoves a listener from this MBean. The MBean must have a listener that exactly matches the given
listener,filter, andhandbackparameters. If there is more than one such listener, only one is removed.The
filterandhandbackparameters may be null if and only if they are null in a listener to be removed.- Specified by:
removeNotificationListenerin interfaceNotificationEmitter- Parameters:
listener- A listener that was previously added to this MBean.filter- The filter that was specified when the listener was added.handback- The handback that was specified when the listener was added.- Throws:
ListenerNotFoundException- The listener is not registered with the MBean, or it is not registered with the given filter and handback.
-
addNotificationListener
public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) Description copied from interface:NotificationBroadcasterAdds a listener to this MBean.- Specified by:
addNotificationListenerin interfaceNotificationBroadcaster- Parameters:
listener- The listener object which will handle the notifications emitted by the broadcaster.filter- The filter object. If filter is null, no filtering will be performed before handling notifications.handback- An opaque object to be sent back to the listener when a notification is emitted. This object cannot be used by the Notification broadcaster object. It should be resent unchanged with the notification to the listener.- See Also:
-
getNotificationInfo
Description copied from interface:NotificationBroadcasterReturns an array indicating, for each notification this MBean may send, the name of the Java class of the notification and the notification type.
It is not illegal for the MBean to send notifications not described in this array. However, some clients of the MBean server may depend on the array being complete for their correct functioning.
- Specified by:
getNotificationInfoin interfaceNotificationBroadcaster- Returns:
- the array of possible notifications.
-
sendNotification
Sends a notification.
If the
emitterparameter to the constructor was an instance ofNotificationBroadcasterSupportthen this method will callemitter.sendNotification.- Parameters:
n- the notification to send.- Throws:
ClassCastException- if theemitterparameter to the constructor was not aNotificationBroadcasterSupport.
-