|
Java™ Platform Standard Ed. 7 DRAFT ea-b76 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjavax.management.event.EventClient
public class EventClient extends Object implements EventConsumer, NotificationManager
This class is used to manage its notification listeners on the client
side in the same way as on the MBean server side. This class needs to work
with an EventClientDelegateMBean on the server side.
A user can specify an EventRelay object to specify how to receive
notifications forwarded by the EventClientDelegateMBean. By default,
the class FetchingEventRelay is used.
A user can specify an Executor
to distribute notifications to local listeners. If no executor is
specified, the thread in the EventRelay which calls EventReceiver.receive will be reused to distribute
the notifications (in other words, to call the handleNotification method of the
appropriate listeners). It is useful to make a separate thread do this
distribution in some cases. For example, if network communication is slow,
the forwarding thread can concentrate on communication while, locally,
the distributing thread distributes the received notifications. Another
usage is to share a thread pool between many clients, for scalability.
Note, though, that if the Executor can create more than one thread
then it is possible that listeners will see notifications in a different
order from the order in which they were sent.
An object of this class sends notifications to listeners added with
addEventClientListener(javax.management.NotificationListener, javax.management.NotificationFilter, java.lang.Object). The type of each such notification is one of FAILED, NONFATAL,
or NOTIFS_LOST.
| Modifier and Type | Field and Description |
|---|---|
static long |
DEFAULT_REQUESTED_LEASE_TIME
The default lease time that EventClient instances will request, in milliseconds. |
static String |
FAILED
A notification string type used by an EventClient object
to inform a listener added by addEventClientListener(javax.management.NotificationListener, javax.management.NotificationFilter, java.lang.Object) that
it failed to get notifications from a remote server, and that it is
possible that no more notifications will be delivered. |
static String |
NONFATAL
Reports that an unexpected exception has been received by the EventRelay object but that it is non-fatal. |
static String |
NOTIFS_LOST
A notification string type used by an EventClient object
to inform a listener added by addEventClientListener that it has detected that notifications have
been lost. |
| Constructor and Description |
|---|
EventClient(EventClientDelegateMBean delegate)
Constructs an EventClient object with a specified
EventClientDelegateMBean. |
EventClient(EventClientDelegateMBean delegate,
EventRelay eventRelay,
Executor distributingExecutor,
ScheduledExecutorService leaseScheduler,
long requestedLeaseTime)
Constructs an EventClient object with the specified
EventClientDelegateMBean, EventRelay
object, and distributing thread. |
EventClient(MBeanServerConnection conn)
Constructs a default EventClient object. |
| Modifier and Type | Method and Description |
|---|---|
void |
addEventClientListener(NotificationListener listener,
NotificationFilter filter,
Object handback)
Adds a listener to receive the EventClient notifications specified in
getEventClientNotificationInfo(). |
Collection<ListenerInfo> |
addListeners(Collection<ListenerInfo> listeners)
Adds a set of listeners to the remote MBeanServer. |
void |
addNotificationListener(ObjectName name,
NotificationListener listener,
NotificationFilter filter,
Object handback)
Adds a listener to a registered MBean. |
void |
close()
Closes this EventClient, removes all listeners and stops receiving notifications. |
boolean |
closed()
Determine if this EventClient is closed. |
String |
getClientId()
Get the client id of this EventClient in the
EventClientDelegateMBean. |
static MBeanServerConnection |
getEventClientConnection(MBeanServerConnection conn)
Constructs an MBeanServerConnection that uses an EventClient object,
if the underlying connection has an EventClientDelegateMBean. |
static MBeanServerConnection |
getEventClientConnection(MBeanServerConnection conn,
EventRelay eventRelay)
Constructs an MBeanServerConnection that uses an EventClient
object with a user-specific EventRelay
object. |
MBeanNotificationInfo[] |
getEventClientNotificationInfo()
Get the types of notification that an EventClient can send
to listeners added with addEventClientListener. |
EventRelay |
getEventRelay()
Return the EventRelay associated with this
EventClient. |
Collection<ListenerInfo> |
getListeners()
Returns the collection of listeners that have been added through this EventClient and not subsequently removed. |
long |
getRequestedLeaseTime()
Return the lease time that this EventClient requests
on every lease renewal. |
void |
removeEventClientListener(NotificationListener listener)
Removes a listener added to receive EventClient notifications specified in
getEventClientNotificationInfo(). |
void |
removeNotificationListener(ObjectName name,
NotificationListener listener)
Removes a listener from a registered MBean. |
void |
removeNotificationListener(ObjectName name,
NotificationListener listener,
NotificationFilter filter,
Object handback)
Removes a listener from a registered MBean. |
void |
subscribe(ObjectName name,
NotificationListener listener,
NotificationFilter filter,
Object handback)
Subscribes a listener to receive events from an MBean or a set of MBeans represented by an ObjectName pattern. |
void |
unsubscribe(ObjectName name,
NotificationListener listener)
Unsubscribes a listener which is listening to an MBean or a set of MBeans represented by an ObjectName pattern. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String FAILED
A notification string type used by an EventClient object
to inform a listener added by addEventClientListener(javax.management.NotificationListener, javax.management.NotificationFilter, java.lang.Object) that
it failed to get notifications from a remote server, and that it is
possible that no more notifications will be delivered.
addEventClientListener(javax.management.NotificationListener, javax.management.NotificationFilter, java.lang.Object),
EventReceiver.failed(java.lang.Throwable),
Constant Field Valuespublic static final String NONFATAL
Reports that an unexpected exception has been received by the EventRelay object but that it is non-fatal. For example, a notification
received is not serializable or its class is not found.
addEventClientListener(javax.management.NotificationListener, javax.management.NotificationFilter, java.lang.Object),
EventReceiver.nonFatal(java.lang.Exception),
Constant Field Valuespublic static final String NOTIFS_LOST
A notification string type used by an EventClient object
to inform a listener added by addEventClientListener that it has detected that notifications have
been lost. The userData of the
notification is a Long which is an upper bound on the number of lost
notifications that have just been detected.
addEventClientListener(javax.management.NotificationListener, javax.management.NotificationFilter, java.lang.Object),
Constant Field Valuespublic static final long DEFAULT_REQUESTED_LEASE_TIME
EventClientDelegateMBean.lease(java.lang.String, long),
Constant Field Values| Constructor Detail |
|---|
public EventClient(MBeanServerConnection conn)
throws IOException
Constructs a default EventClient object.
This object creates a FetchingEventRelay object to
receive notifications forwarded by the EventClientDelegateMBean.
The EventClientDelegateMBean that it works with is the
one registered with the default ObjectName. The thread from the FetchingEventRelay
object that fetches the notifications is also used to distribute them.
conn - An MBeanServerConnection object used to communicate
with an EventClientDelegateMBean MBean.IllegalArgumentException - If conn is null.IOException - If an I/O error occurs when communicating with the
EventClientDelegateMBean.
public EventClient(EventClientDelegateMBean delegate)
throws IOException
EventClient object with a specified
EventClientDelegateMBean.
This object creates a FetchingEventRelay object to receive
notifications forwarded by the EventClientDelegateMBean. The
thread from the FetchingEventRelay object that fetches the
notifications is also used to distribute them.
delegate - An EventClientDelegateMBean object to work with.IllegalArgumentException - If delegate is null.IOException - If an I/O error occurs when communicating with the
the EventClientDelegateMBean.
public EventClient(EventClientDelegateMBean delegate,
EventRelay eventRelay,
Executor distributingExecutor,
ScheduledExecutorService leaseScheduler,
long requestedLeaseTime)
throws IOException
EventClient object with the specified
EventClientDelegateMBean, EventRelay
object, and distributing thread.
delegate - An EventClientDelegateMBean object to work with.
Usually, this will be a proxy constructed using
EventClientDelegate.getProxy(javax.management.MBeanServerConnection).eventRelay - An object used to receive notifications
forwarded by the EventClientDelegateMBean. If null, a
FetchingEventRelay object will be used.distributingExecutor - Used to distribute notifications to local
listeners. Only one job at a time will be submitted to this Executor.
If distributingExecutor is null, the thread that calls
EventReceiver.receive from the EventRelay object is used.leaseScheduler - An object that will be used to schedule the
periodic lease updates.
If null, a default scheduler will be used.requestedLeaseTime - The lease time used to keep this client alive
in the EventClientDelegateMBean. A value of zero is equivalent
to the default value.IllegalArgumentException - If delegate is null.IOException - If an I/O error occurs when communicating with the
EventClientDelegateMBean.| Method Detail |
|---|
public void close()
throws IOException
Closes this EventClient, removes all listeners and stops receiving notifications.
This method calls EventClientDelegateMBean.removeClient(String) and EventRelay.stop(). Both operations occur even if one of them
throws an IOException.
IOException - if an I/O error occurs when communicating with
EventClientDelegateMBean, or if EventRelay.stop()
throws an IOException.public boolean closed()
Determine if this EventClient is closed.
EventClient is closed.public EventRelay getEventRelay()
Return the EventRelay associated with this
EventClient.
EventRelay object used.public long getRequestedLeaseTime()
Return the lease time that this EventClient requests
on every lease renewal.
EventClientDelegateMBean.lease(java.lang.String, long)
public void addNotificationListener(ObjectName name,
NotificationListener listener,
NotificationFilter filter,
Object handback)
throws InstanceNotFoundException,
IOException
NotificationManagerAdds a listener to a registered MBean. Notifications emitted by the MBean will be forwarded to the listener.
addNotificationListener in interface NotificationManagername - The name of the MBean on which the listener should
be added.listener - The listener object which will handle the
notifications emitted by the registered MBean.filter - The filter object. If filter is null, no
filtering will be performed before handling notifications.handback - The context to be sent to the listener when a
notification is emitted.InstanceNotFoundException - The MBean name provided
does not match any of the registered MBeans.IOException - A communication problem occurred when
talking to the MBean server.MBeanServerConnection.addNotificationListener(
ObjectName, NotificationListener, NotificationFilter, Object).
public void removeNotificationListener(ObjectName name,
NotificationListener listener)
throws InstanceNotFoundException,
ListenerNotFoundException,
IOException
NotificationManagerRemoves a listener from a registered MBean.
If the listener is registered more than once, perhaps with different filters or callbacks, this method will remove all those registrations.
removeNotificationListener in interface NotificationManagername - The name of the MBean on which the listener should
be removed.listener - The listener to be removed.InstanceNotFoundException - The MBean name provided
does not match any of the registered MBeans.ListenerNotFoundException - The listener is not
registered in the MBean.IOException - A communication problem occurred when
talking to the MBean server.MBeanServerConnection.removeNotificationListener(
ObjectName, NotificationListener).
public void removeNotificationListener(ObjectName name,
NotificationListener listener,
NotificationFilter filter,
Object handback)
throws InstanceNotFoundException,
ListenerNotFoundException,
IOException
NotificationManagerRemoves a listener from a registered MBean.
The MBean must have a listener that exactly matches the
given listener, filter, and
handback parameters. If there is more than one
such listener, only one is removed.
The filter and handback parameters
may be null if and only if they are null in a listener to be
removed.
removeNotificationListener in interface NotificationManagername - The name of the MBean on which the listener should
be removed.listener - The listener to be removed.filter - The filter that was specified when the listener
was added.handback - The handback that was specified when the
listener was added.InstanceNotFoundException - The MBean name provided
does not match any of the registered MBeans.ListenerNotFoundException - The listener is not
registered in the MBean, or it is not registered with the given
filter and handback.IOException - A communication problem occurred when
talking to the MBean server.MBeanServerConnection.removeNotificationListener(
ObjectName, NotificationListener, NotificationFilter, Object).
public void unsubscribe(ObjectName name,
NotificationListener listener)
throws ListenerNotFoundException,
IOException
EventConsumerUnsubscribes a listener which is listening to an MBean or a set of
MBeans represented by an ObjectName pattern.
The listener to be removed must have been added by the subscribe method with the given name. If the name is a pattern, then the subscribe must have used the same
pattern. If the same listener has been subscribed more than once to the
name, perhaps with different filters or handbacks, then all such
listeners are removed.
unsubscribe in interface EventConsumername - The name of the MBean or an ObjectName pattern
representing a set of MBeans to which the listener was subscribed.listener - A listener that was previously subscribed to the
MBean(s).ListenerNotFoundException - The given listener was not
subscribed to the given name.IOException - for a remote client, thrown if
an I/O error occurs.EventConsumer.unsubscribe(
ObjectName, NotificationListener).
public void subscribe(ObjectName name,
NotificationListener listener,
NotificationFilter filter,
Object handback)
throws IOException
EventConsumerSubscribes a listener to receive events from an MBean or a set
of MBeans represented by an ObjectName pattern.
An event emitted by an MBean is forwarded to every listener that was subscribed with the name of that MBean, or with a pattern that matches that name.
subscribe in interface EventConsumername - The name of an MBean or an ObjectName pattern
representing a set of MBeans to which the listener should listen.listener - The listener object that will handle the
notifications emitted by the MBeans.filter - The filter object. If filter is null, no
filtering will be performed before notification handling.handback - The context to be sent to the listener when a
notification is emitted.IOException - for a remote client, thrown if
an I/O error occurs.EventConsumer.subscribe(
ObjectName, NotificationListener, NotificationFilter, Object).
public Collection<ListenerInfo> addListeners(Collection<ListenerInfo> listeners)
throws IOException
Adds a set of listeners to the remote MBeanServer. This method can
be used to copy the listeners from one EventClient to another.
A listener is represented by a ListenerInfo object. The listener
is added by calling subscribe(ObjectName,
NotificationListener, NotificationFilter, Object) if the method
isSubscription
returns true; otherwise it is added by calling
addNotificationListener(ObjectName, NotificationListener,
NotificationFilter, Object).
The method returns the listeners which were added successfully. The
elements in the returned collection are a subset of the elements in
listeners. If all listeners were added successfully, the two
collections are the same. If no listener was added successfully, the
returned collection is empty.
listeners - the listeners to add.IOException - If an I/O error occurs.getListeners()public Collection<ListenerInfo> getListeners()
Returns the collection of listeners that have been added through
this EventClient and not subsequently removed. The returned
collection contains one entry for every listener added with
addNotificationListener or
subscribe and not subsequently removed with
removeNotificationListener or
unsubscribe, respectively.
EventClient has been closed.addListeners(java.util.Collection)
public void addEventClientListener(NotificationListener listener,
NotificationFilter filter,
Object handback)
EventClient notifications specified in
getEventClientNotificationInfo().
listener - A listener to receive EventClient notifications.filter - A filter to select which notifications are to be delivered
to the listener, or null if all notifications are to be delivered.handback - An object to be given to the listener along with each
notification. Can be null.NullPointerException - If listener is null.removeEventClientListener(javax.management.NotificationListener)
public void removeEventClientListener(NotificationListener listener)
throws ListenerNotFoundException
EventClient notifications specified in
getEventClientNotificationInfo().
listener - A listener to receive EventClient notifications.NullPointerException - If listener is null.ListenerNotFoundException - If the listener is not added to
this EventClient.public MBeanNotificationInfo[] getEventClientNotificationInfo()
Get the types of notification that an EventClient can send
to listeners added with addEventClientListener.
EventClient.FAILED,
NONFATAL,
NOTIFS_LOST
public static MBeanServerConnection getEventClientConnection(MBeanServerConnection conn)
throws IOException
MBeanServerConnection that uses an EventClient object,
if the underlying connection has an EventClientDelegateMBean.
The EventClient object creates a default
FetchingEventRelay object to
receive notifications forwarded by the EventClientDelegateMBean.
The EventClientDelegateMBean it works with is the
default one registered with the ObjectName
OBJECT_NAME.
The thread from the FetchingEventRelay object that fetches the
notifications is also used to distribute them.
conn - An MBeanServerConnection object used to communicate
with an EventClientDelegateMBean.IllegalArgumentException - If the value of conn is null,
or the default EventClientDelegateMBean is not registered.IOException - If an I/O error occurs.
public static MBeanServerConnection getEventClientConnection(MBeanServerConnection conn,
EventRelay eventRelay)
throws IOException
EventClient
object with a user-specific EventRelay
object.
The EventClientDelegateMBean which it works with is the
default one registered with the ObjectName
OBJECT_NAME
The thread that calls EventReceiver.receive from the EventRelay object is used
to distribute notifications to their listeners.
conn - An MBeanServerConnection object used to communicate
with an EventClientDelegateMBean.eventRelay - A user-specific object used to receive notifications
forwarded by the EventClientDelegateMBean. If null, the default
FetchingEventRelay object is used.IllegalArgumentException - If the value of conn is null,
or the default EventClientDelegateMBean is not registered.IOException - If an I/O error occurs.public String getClientId()
Get the client id of this EventClient in the
EventClientDelegateMBean.
EventClientDelegateMBean.addClient
|
Java™ Platform Standard Ed. 7 DRAFT ea-b76 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. Use is subject to license terms.