java类javax.management.AttributeChangeNotification的实例源码

ModelMBeanNotificationPublisher.java 文件源码 项目:spring4-understanding 阅读 19 收藏 0 点赞 0 评论 0
/**
 * Send the supplied {@link Notification} using the wrapped
 * {@link ModelMBean} instance.
 * @param notification the {@link Notification} to be sent
 * @throws IllegalArgumentException if the supplied {@code notification} is {@code null}
 * @throws UnableToSendNotificationException if the supplied {@code notification} could not be sent
 */
@Override
public void sendNotification(Notification notification) {
    Assert.notNull(notification, "Notification must not be null");
    replaceNotificationSourceIfNecessary(notification);
    try {
        if (notification instanceof AttributeChangeNotification) {
            this.modelMBean.sendAttributeChangeNotification((AttributeChangeNotification) notification);
        }
        else {
            this.modelMBean.sendNotification(notification);
        }
    }
    catch (MBeanException ex) {
        throw new UnableToSendNotificationException("Unable to send notification [" + notification + "]", ex);
    }
}
NotificationListenerTests.java 文件源码 项目:spring4-understanding 阅读 18 收藏 0 点赞 0 评论 0
@Override
public void handleNotification(Notification notification, Object handback) {
    if (notification instanceof AttributeChangeNotification) {
        AttributeChangeNotification attNotification = (AttributeChangeNotification) notification;
        String attributeName = attNotification.getAttributeName();

        Integer currentCount = (Integer) this.attributeCounts.get(attributeName);

        if (currentCount != null) {
            int count = currentCount.intValue() + 1;
            this.attributeCounts.put(attributeName, new Integer(count));
        } else {
            this.attributeCounts.put(attributeName, new Integer(1));
        }

        this.attributeHandbacks.put(attributeName, handback);
    }
}
ModelMBeanNotificationPublisher.java 文件源码 项目:my-spring-cache-redis 阅读 21 收藏 0 点赞 0 评论 0
/**
 * Send the supplied {@link Notification} using the wrapped
 * {@link ModelMBean} instance.
 * @param notification the {@link Notification} to be sent
 * @throws IllegalArgumentException if the supplied {@code notification} is {@code null}
 * @throws UnableToSendNotificationException if the supplied {@code notification} could not be sent
 */
@Override
public void sendNotification(Notification notification) {
    Assert.notNull(notification, "Notification must not be null");
    replaceNotificationSourceIfNecessary(notification);
    try {
        if (notification instanceof AttributeChangeNotification) {
            this.modelMBean.sendAttributeChangeNotification((AttributeChangeNotification) notification);
        }
        else {
            this.modelMBean.sendNotification(notification);
        }
    }
    catch (MBeanException ex) {
        throw new UnableToSendNotificationException("Unable to send notification [" + notification + "]", ex);
    }
}
MX4JModelMBean.java 文件源码 项目:gemfirexd-oss 阅读 28 收藏 0 点赞 0 评论 0
public void sendAttributeChangeNotification(Attribute oldAttribute, Attribute newAttribute) throws MBeanException, RuntimeOperationsException
{
   if (oldAttribute == null || newAttribute == null) throw new RuntimeOperationsException(new IllegalArgumentException(LocalizedStrings.MX4JModelMBean_ATTRIBUTE_CANNOT_BE_NULL.toLocalizedString()));
   if (!oldAttribute.getName().equals(newAttribute.getName())) throw new RuntimeOperationsException(new IllegalArgumentException(LocalizedStrings.MX4JModelMBean_ATTRIBUTE_NAMES_CANNOT_BE_DIFFERENT.toLocalizedString()));

   // TODO: the source must be the object name of the MBean if the listener was registered through MBeanServer
   Object oldValue = oldAttribute.getValue();
   AttributeChangeNotification n = new AttributeChangeNotification(this,
                                                                   1,
                                                                   System.currentTimeMillis(),
                                                                   "Attribute value changed",
                                                                   oldAttribute.getName(),
                                                                   oldValue == null ? null : oldValue.getClass().getName(),
                                                                   oldValue,
                                                                   newAttribute.getValue());
   sendAttributeChangeNotification(n);
}
NvpnNbrControlPathAlarm.java 文件源码 项目:netvirt 阅读 21 收藏 0 点赞 0 评论 0
@Override
public void raiseAlarm(String alarmName, String additionalText, String source, String detailsInfo) {
    if (alarmName == null || source == null || detailsInfo == null) {
        LOG.error("NvpnNbrControlPathAlarm.raiseAlarm has bad argument");
        return;
    }
    ArrayList<String> raiseAlarmObject = new ArrayList<>();
    raiseAlarmObject.add(alarmName);
    raiseAlarmObject.add(additionalText);
    raiseAlarmObject.add(source);
    raiseAlarmObject.add(detailsInfo);
    sendNotification(new AttributeChangeNotification(this,
        sequenceNumber.getAndIncrement(), System.currentTimeMillis(),
        NvpnJMXAlarmAgent.OP_RAISEALARM, "raiseAlarmObject", "List",
        "", raiseAlarmObject));
}
NvpnNbrControlPathAlarm.java 文件源码 项目:netvirt 阅读 41 收藏 0 点赞 0 评论 0
@Override
public void clearAlarm(String alarmName, String additionalText, String source, String detailsInfo) {
    if (alarmName == null || source == null || detailsInfo == null) {
        LOG.error("NvpnNbrControlPathAlarm.clearAlarm has bad argument");
        return;
    }
    ArrayList<String> clearAlarmObject = new ArrayList<>();
    clearAlarmObject.add(alarmName);
    clearAlarmObject.add(additionalText);
    clearAlarmObject.add(source);
    clearAlarmObject.add(detailsInfo);
    sendNotification(new AttributeChangeNotification(this,
            sequenceNumber.getAndIncrement(), System.currentTimeMillis(),
            NvpnJMXAlarmAgent.OP_CLEARALARM, "clearAlarmObject", "List",
            "", clearAlarmObject));
}
ScanManager.java 文件源码 项目:jdk8u_jdk 阅读 26 收藏 0 点赞 0 评论 0
/**
 * Enqueue a state changed notification for the given states.
 **/
private void queueStateChangedNotification(
                long sequence,
                long time,
                ScanState old,
                ScanState current) {
    final AttributeChangeNotification n =
            new AttributeChangeNotification(SCAN_MANAGER_NAME,sequence,time,
            "ScanManager State changed to "+current,"State",
            ScanState.class.getName(),old.toString(),current.toString());
    // Queue the notification. We have created an unlimited queue, so
    // this method should always succeed.
    try {
        if (!pendingNotifs.offer(n,2,TimeUnit.SECONDS)) {
            LOG.fine("Can't queue Notification: "+n);
        }
    } catch (InterruptedException x) {
            LOG.fine("Can't queue Notification: "+x);
    }
}
CommunicatorServer.java 文件源码 项目:jdk8u_jdk 阅读 29 收藏 0 点赞 0 评论 0
/**
 * Returns an array of MBeanNotificationInfo objects describing
 * the notification types sent by this CommunicatorServer.
 * There is only one type of notifications sent by the CommunicatorServer:
 * it is <tt>{@link javax.management.AttributeChangeNotification}</tt>,
 * sent when the <tt>State</tt> attribute of this CommunicatorServer
 * changes.
 */
@Override
public MBeanNotificationInfo[] getNotificationInfo() {

    // Initialize notifInfos on first call to getNotificationInfo()
    //
    if (notifInfos == null) {
        notifInfos = new MBeanNotificationInfo[1];
        String[] notifTypes = {
            AttributeChangeNotification.ATTRIBUTE_CHANGE};
        notifInfos[0] = new MBeanNotificationInfo( notifTypes,
                 AttributeChangeNotification.class.getName(),
                 "Sent to notify that the value of the State attribute "+
                 "of this CommunicatorServer instance has changed.");
    }

    return notifInfos.clone();
}
SimpleStandard.java 文件源码 项目:jdk8u_jdk 阅读 20 收藏 0 点赞 0 评论 0
/**
 * Operation: reset to their initial values the "State" and "NbChanges"
 * attributes of the "SimpleStandard" standard MBean.
 */
public void reset() {
    checkSubject();
    AttributeChangeNotification acn =
        new AttributeChangeNotification(this,
                                        0,
                                        0,
                                        "NbChanges reset",
                                        "NbChanges",
                                        "Integer",
                                        new Integer(nbChanges),
                                        new Integer(0));
    state = "initial state";
    nbChanges = 0;
    nbResets++;
    sendNotification(acn);
}
SimpleStandard.java 文件源码 项目:jdk8u_jdk 阅读 22 收藏 0 点赞 0 评论 0
/**
 * Operation: reset to their initial values the "State" and "NbChanges"
 * attributes of the "SimpleStandard" standard MBean.
 */
public void reset() {
    checkSubject("reset");
    AttributeChangeNotification acn =
        new AttributeChangeNotification(this,
                                        0,
                                        0,
                                        "NbChanges reset",
                                        "NbChanges",
                                        "Integer",
                                        new Integer(nbChanges),
                                        new Integer(0));
    state = "initial state";
    nbChanges = 0;
    nbResets++;
    sendNotification(acn);
}


问题


面经


文章

微信
公众号

扫码关注公众号