本文整理汇总了Java中javax.management.NotificationListener类的典型用法代码示例。如果您正苦于以下问题:Java NotificationListener类的具体用法?Java NotificationListener怎么用?Java NotificationListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NotificationListener类属于javax.management包,在下文中一共展示了NotificationListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addNotificationListener
import javax.management.NotificationListener; //导入依赖的package包/类
public void addNotificationListener(ObjectName name,
NotificationListener listener,
NotificationFilter filter,
Object handback)
throws InstanceNotFoundException,
IOException {
final boolean debug = logger.debugOn();
if (debug)
logger.debug("addNotificationListener" +
"(ObjectName,NotificationListener,"+
"NotificationFilter,Object)",
"name=" + name
+ ", listener=" + listener
+ ", filter=" + filter
+ ", handback=" + handback);
final Integer listenerID =
addListenerWithSubject(name,
new MarshalledObject<NotificationFilter>(filter),
delegationSubject,true);
rmiNotifClient.addNotificationListener(listenerID, name, listener,
filter, handback,
delegationSubject);
}
示例2: removeNotificationListener
import javax.management.NotificationListener; //导入依赖的package包/类
@Override
public synchronized void removeNotificationListener(ObjectName name,
NotificationListener listener) throws InstanceNotFoundException,
ListenerNotFoundException {
mbs.removeNotificationListener(name, listener);
// TODO: slow implementation ... but fast one takes a lot of time to do :-)
Iterator<Listener2> iter = listeners2.iterator();
while(iter.hasNext()) {
Listener2 l = iter.next();
if (SafeEquals.equals(name, l.name) && SafeEquals.equals(listener, l.listener)) {
listeners.remove(l);
unregisteredListeners.remove(l);
iter.remove();
}
}
}
示例3: removeNotificationListener
import javax.management.NotificationListener; //导入依赖的package包/类
/**
* Removes a listener for Notifications from the RequiredModelMBean.
*
* @param listener The listener name which was handling notifications
* emitted by the registered MBean.
* This method will remove all information related to this listener.
*
* @exception ListenerNotFoundException The listener is not registered
* in the MBean or is null.
*
* @see #addNotificationListener
**/
public void removeNotificationListener(NotificationListener listener)
throws ListenerNotFoundException {
if (listener == null)
throw new ListenerNotFoundException(
"Notification listener is null");
final String mth="removeNotificationListener(NotificationListener)";
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
RequiredModelMBean.class.getName(), mth, "Entry");
}
if (generalBroadcaster == null)
throw new ListenerNotFoundException(
"No notification listeners registered");
generalBroadcaster.removeNotificationListener(listener);
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
RequiredModelMBean.class.getName(), mth, "Exit");
}
}
示例4: removeNotificationListener
import javax.management.NotificationListener; //导入依赖的package包/类
public synchronized Integer
removeNotificationListener(ObjectName name,
NotificationListener listener,
NotificationFilter filter,
Object handback)
throws ListenerNotFoundException, IOException {
if (logger.traceOn()) {
logger.trace("removeNotificationListener",
"Remove the listener "+listener+" from "+name);
}
beforeRemove();
Integer liId = getListenerId(name, listener,
filter, handback);
infoList.remove(liId);
return liId;
}
示例5: addNotificationListener
import javax.management.NotificationListener; //导入依赖的package包/类
public synchronized void addNotificationListener(Integer listenerID,
ObjectName name,
NotificationListener listener,
NotificationFilter filter,
Object handback,
Subject delegationSubject)
throws IOException, InstanceNotFoundException {
if (logger.traceOn()) {
logger.trace("addNotificationListener",
"Add the listener "+listener+" at "+name);
}
infoList.put(listenerID,
new ClientListenerInfo(listenerID,
name,
listener,
filter,
handback,
delegationSubject));
init(false);
}
示例6: ScanDirAgent
import javax.management.NotificationListener; //导入依赖的package包/类
/**
* Creates a new instance of ScanDirAgent
* You will need to call {@link #init()} later on in order to initialize
* the application.
* @see #main
**/
public ScanDirAgent() {
// Initialize the notification queue
queue = new LinkedBlockingQueue<Notification>();
// Creates the listener.
listener = new NotificationListener() {
public void handleNotification(Notification notification,
Object handback) {
try {
// Just put the received notification in the queue.
// It will be consumed later on by 'waitForClose()'
//
LOG.finer("Queuing received notification "+notification);
queue.put(notification);
} catch (InterruptedException ex) {
// OK
}
}
};
}
示例7: removeNotificationListener
import javax.management.NotificationListener; //导入依赖的package包/类
/**
* Removes a listener for Notifications from the RequiredModelMBean.
*
* @param listener The listener name which was handling notifications
* emitted by the registered MBean.
* This method will remove all information related to this listener.
*
* @exception ListenerNotFoundException The listener is not registered
* in the MBean or is null.
*
* @see #addNotificationListener
**/
public void removeNotificationListener(NotificationListener listener)
throws ListenerNotFoundException {
if (listener == null)
throw new ListenerNotFoundException(
"Notification listener is null");
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
}
if (generalBroadcaster == null)
throw new ListenerNotFoundException(
"No notification listeners registered");
generalBroadcaster.removeNotificationListener(listener);
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
MODELMBEAN_LOGGER.log(Level.TRACE, "Exit");
}
}
示例8: removeNotificationListener
import javax.management.NotificationListener; //导入依赖的package包/类
/**
* Remove a notification event listener from this MBean.
*
* @param listener The listener to be removed (any and all registrations
* for this listener will be eliminated)
*
* @exception ListenerNotFoundException if this listener is not
* registered in the MBean
*/
@Override
public void removeNotificationListener(NotificationListener listener)
throws ListenerNotFoundException {
synchronized (entries) {
Iterator<BaseNotificationBroadcasterEntry> items =
entries.iterator();
while (items.hasNext()) {
BaseNotificationBroadcasterEntry item = items.next();
if (item.listener == listener)
items.remove();
}
}
}
示例9: if
import javax.management.NotificationListener; //导入依赖的package包/类
/**
* Add an attribute change notification event listener to this MBean.
*
* @param listener Listener that will receive event notifications
* @param name Name of the attribute of interest, or <code>null</code>
* to indicate interest in all attributes
* @param handback Handback object to be sent along with event
* notifications
*
* @exception IllegalArgumentException if the listener parameter is null
*/
@Override
public void addAttributeChangeNotificationListener
(NotificationListener listener, String name, Object handback)
throws IllegalArgumentException {
if (listener == null)
throw new IllegalArgumentException("Listener is null");
if (attributeBroadcaster == null)
attributeBroadcaster = new BaseNotificationBroadcaster();
if( log.isDebugEnabled() )
log.debug("addAttributeNotificationListener " + listener);
BaseAttributeFilter filter = new BaseAttributeFilter(name);
attributeBroadcaster.addNotificationListener
(listener, filter, handback);
}
示例10: removeNotificationListener
import javax.management.NotificationListener; //导入依赖的package包/类
public void removeNotificationListener(ObjectName name,
ObjectName listener,
NotificationFilter filter,
Object handback)
throws InstanceNotFoundException, ListenerNotFoundException {
NotificationListener instance = getListener(listener);
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
MBEANSERVER_LOGGER.logp(Level.FINER,
DefaultMBeanServerInterceptor.class.getName(),
"removeNotificationListener",
"ObjectName = " + name + ", Listener = " + listener);
}
server.removeNotificationListener(name, instance, filter, handback);
}
示例11: notify
import javax.management.NotificationListener; //导入依赖的package包/类
/**
* Return true if the notification was sent successfully, false otherwise.
* @param type
* @param message
* @return true if the notification succeeded
*/
public boolean notify(final String type, String message) {
try {
Notification n = new Notification(
type,
this,
sequence.incrementAndGet(),
System.currentTimeMillis(),
"["+type+"] "+message);
sendNotification(n);
for (NotificationListener listener : listeners) {
listener.handleNotification(n,this);
}
return true;
}catch (Exception x) {
if (log.isDebugEnabled()) {
log.debug("Notify failed. Type="+type+"; Message="+message,x);
}
return false;
}
}
示例12: addNotificationListener
import javax.management.NotificationListener; //导入依赖的package包/类
private void addNotificationListener(final ObjectName name,
final NotificationListener listener,
final NotificationFilter filter,
final Object handback)
throws Exception {
try {
AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
public Void run() throws InstanceNotFoundException {
mBeanServer.addNotificationListener(name,
listener,
filter,
handback);
return null;
}
});
} catch (Exception e) {
throw extractException(e);
}
}
示例13: addAttributeChangeNotificationListener
import javax.management.NotificationListener; //导入依赖的package包/类
/**
* Add an attribute change notification event listener to this MBean.
*
* @param listener
* Listener that will receive event notifications
* @param name
* Name of the attribute of interest, or <code>null</code> to
* indicate interest in all attributes
* @param handback
* Handback object to be sent along with event notifications
*
* @exception IllegalArgumentException
* if the listener parameter is null
*/
@Override
public void addAttributeChangeNotificationListener(NotificationListener listener, String name, Object handback)
throws IllegalArgumentException {
if (listener == null)
throw new IllegalArgumentException("Listener is null");
if (attributeBroadcaster == null)
attributeBroadcaster = new BaseNotificationBroadcaster();
if (log.isDebugEnabled())
log.debug("addAttributeNotificationListener " + listener);
BaseAttributeFilter filter = new BaseAttributeFilter(name);
attributeBroadcaster.addNotificationListener(listener, filter, handback);
}
示例14: removeNotificationListener
import javax.management.NotificationListener; //导入依赖的package包/类
public void removeNotificationListener(NotificationListener listener)
throws ListenerNotFoundException {
synchronized (listenerLock) {
List<ListenerInfo> newList = new ArrayList<>(listenerList);
/* We scan the list of listeners in reverse order because
in forward order we would have to repeat the loop with
the same index after a remove. */
for (int i=newList.size()-1; i>=0; i--) {
ListenerInfo li = newList.get(i);
if (li.listener == listener)
newList.remove(i);
}
if (newList.size() == listenerList.size())
throw new ListenerNotFoundException("Listener not registered");
listenerList = newList;
}
}
示例15: listenerOp
import javax.management.NotificationListener; //导入依赖的package包/类
private static void listenerOp(MBeanServerConnection mserver, NotificationListener listener, boolean adding)
throws Exception {
if (adding) {
mserver.addNotificationListener(delegateName, listener, null, null);
} else {
mserver.removeNotificationListener(delegateName, listener);
}
}