javax.management.AttributeChangeNotification类的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(11.0k)|赞(0)|评价(0)|浏览(154)

本文整理了Java中javax.management.AttributeChangeNotification类的一些代码示例,展示了AttributeChangeNotification类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AttributeChangeNotification类的具体详情如下:
包路径:javax.management.AttributeChangeNotification
类名称:AttributeChangeNotification

AttributeChangeNotification介绍

暂无

代码示例

代码示例来源:origin: apache/geode

@Override
public void sendAttributeChangeNotification(Attribute oldAttribute, Attribute newAttribute)
  throws MBeanException, RuntimeOperationsException {
 if (oldAttribute == null || newAttribute == null)
  throw new RuntimeOperationsException(new IllegalArgumentException(
    "Attribute cannot be null."));
 if (!oldAttribute.getName().equals(newAttribute.getName()))
  throw new RuntimeOperationsException(new IllegalArgumentException(
    "Attribute names cannot be different."));
 // 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);
}

代码示例来源:origin: groovy/groovy-core

private static Map buildAttributeNotificationPacket(AttributeChangeNotification note) {
    Map<String, Object> result = new HashMap<String, Object>();
    result.put("oldValue", note.getOldValue());
    result.put("newValue", note.getNewValue());
    result.put("attribute", note.getAttributeName());
    result.put("attributeType", note.getAttributeType());
    result.put("sequenceNumber", note.getSequenceNumber());
    result.put("timeStamp", note.getTimeStamp());
    return result;
  }
}

代码示例来源:origin: apache/geode

@Override
public void sendAttributeChangeNotification(AttributeChangeNotification notification)
  throws MBeanException, RuntimeOperationsException {
 if (notification == null)
  throw new RuntimeOperationsException(new IllegalArgumentException(
    "Notification cannot be null."));
 getAttributeChangeBroadcaster().sendNotification(notification);
 Logger modelMBeanLogger = getModelMBeanLogger(notification.getType());
 if (modelMBeanLogger != null)
  if (modelMBeanLogger.isEnabledFor(Logger.DEBUG))
   modelMBeanLogger.debug("ModelMBean log: " + new Date() + " - " + notification);
 Logger logger = getLogger();
 if (logger.isEnabledFor(Logger.DEBUG))
  logger.debug("Attribute change notification " + notification + " sent");
}

代码示例来源:origin: wildfly/wildfly

/**
   * Helper for sending out state change notifications
   */
  private void sendStateChangeNotification(int oldState, int newState, String msg, Throwable t) {
    long now = System.currentTimeMillis();
    AttributeChangeNotification stateChangeNotification = new AttributeChangeNotification(this,
        getNextNotificationSequenceNumber(), now, msg, "State", "java.lang.Integer", new Integer(oldState),
        new Integer(newState));
    stateChangeNotification.setUserData(t);
    sendNotification(stateChangeNotification);
  }
}

代码示例来源:origin: mercyblitz/segmentfault-lessons

/**
 * 处理通知/事件
 *
 * @param notification
 * @param handback
 */
@Override
public void handleNotification(Notification notification, Object handback) {
  AttributeChangeNotification attributeChangeNotification = (AttributeChangeNotification) notification;
  String oldData = (String) attributeChangeNotification.getOldValue();
  String newData = (String) attributeChangeNotification.getNewValue();
  System.out.printf("The notification of data's attribute  - old data : %s , new data : %s \n", oldData, newData);
}

代码示例来源:origin: org.glassfish.common/amx-core

out = new AttributeChangeNotification(
    source,
    a.getSequenceNumber(),
    a.getTimeStamp(),
    a.getMessage(),
    a.getAttributeName(),
    a.getAttributeType(),
    a.getOldValue(),
    a.getNewValue());

代码示例来源:origin: org.glassfish.main.common/amx-core

public String stringify(Object o)
{
  final AttributeChangeNotification notif = (AttributeChangeNotification) o;
  final StringBuffer b = super._stringify(notif);
  append(b, "");
  final String attrName = notif.getAttributeName();
  final String oldValue = SmartStringifier.toString(notif.getOldValue());
  final String newValue = SmartStringifier.toString(notif.getNewValue());
  final String msg = attrName + ": " + oldValue + " => " + newValue;
  b.append(msg);
  return (b.toString());
}

代码示例来源:origin: codefollower/Tomcat-Research

/**
 * <p>Test whether notification enabled for this event.
 * Return true if:</p>
 * <ul>
 * <li>This is an attribute change notification</li>
 * <li>Either the set of accepted names is empty (implying that all
 *     attribute names are of interest) or the set of accepted names
 *     includes the name of the attribute in this notification</li>
 * </ul>
 */
@Override
public boolean isNotificationEnabled(Notification notification) {
  if (notification == null)
    return (false);
  if (!(notification instanceof AttributeChangeNotification))
    return (false);
  AttributeChangeNotification acn =
    (AttributeChangeNotification) notification;
  if (!AttributeChangeNotification.ATTRIBUTE_CHANGE.equals(acn.getType()))
    return (false);
  synchronized (names) {
    if (names.size() < 1)
      return (true);
    else
      return (names.contains(acn.getAttributeName()));
  }
}

代码示例来源:origin: com.haulmont.thirdparty/eclipselink

public void handleNotification(Notification notification, Object handback) {
    switch (server) {
    case 0: {  // handle WebLogic notification
      if (notification instanceof AttributeChangeNotification) {
        AttributeChangeNotification acn = (AttributeChangeNotification) notification;
        if (acn.getAttributeName().equals(WLS_ACTIVE_VERSION_STATE)) {
          if (acn.getNewValue().equals(0)) {
            resetHelperContext(appName);
          }
        }
      }
      break;
    }
    case 1: {  // handle JBoss notification
      // assumes 'user data' is an ObjectName containing an 'id' property which indicates the archive file name
      appName = getApplicationNameFromJBossClassLoader(((ObjectName) notification.getUserData()).getKeyProperty(JBOSS_ID_KEY));
      // we receive notifications for all service stops in JBoss;  only call reset if necessary
      if (helperContexts.containsKey(appName)) {
        resetHelperContext(appName);
      }
      break;
    }
    }
  }
}

代码示例来源:origin: com.github.nyla-solutions/nyla.solutions.core

public void handleNotification(Notification notification,
                  Object handback) {
    System.out.println("\nReceived notification:");
    System.out.println("\tClassName: " + notification.getClass().getName());
    System.out.println("\tSource: " + notification.getSource());
    System.out.println("\tType: " + notification.getType());
    System.out.println("\tMessage: " + notification.getMessage());
    if (notification instanceof AttributeChangeNotification) {
      AttributeChangeNotification acn =
        (AttributeChangeNotification) notification;
      System.out.println("\tAttributeName: " + acn.getAttributeName());
      System.out.println("\tAttributeType: " + acn.getAttributeType());
      System.out.println("\tNewValue: " + acn.getNewValue());
      System.out.println("\tOldValue: " + acn.getOldValue());
    }
  }
}

代码示例来源:origin: mx4j/mx4j-tools

public void handleNotification(Notification notification, Object object)
{
 AttributeChangeNotification anot = (AttributeChangeNotification)notification;
 addEntry(new Date(), (Number)anot.getNewValue());
}

代码示例来源:origin: org.jboss.jbossas/jboss-as-jmx-remoting

if(ch.getAttributeName().equals("State") && hasActions())
  Object src = ch.getSource();
  if(src instanceof ObjectName)
   fireStateChange(new MBeanLocator(server, obj), ((Integer) ch.getOldValue()).intValue(), ((Integer) ch.getNewValue()).intValue());
   return;

代码示例来源:origin: spring-projects/spring-framework

@Override
  public boolean isNotificationEnabled(Notification notification) {
    if (notification instanceof AttributeChangeNotification) {
      AttributeChangeNotification changeNotification = (AttributeChangeNotification) notification;
      return "Name".equals(changeNotification.getAttributeName());
    }
    else {
      return false;
    }
  }
});

代码示例来源:origin: org.jboss.jbossas/jboss-as-management

/**
* A notification from the underlying JBoss service.
*
* @param msg      The notification msg, AttributeChangeNotification is what we
*                 care about
* @param handback not used
*/
public void handleNotification(Notification msg, Object handback)
{
 if (msg instanceof AttributeChangeNotification)
 {
   AttributeChangeNotification change = (AttributeChangeNotification) msg;
   String attrName = change.getAttributeName();
   Object newValue = change.getNewValue();
   if ("State".equals(attrName) && newValue != null && newValue instanceof Integer)
   {
    int newState = ((Integer) newValue).intValue();
    long eventTime = -1;
    if (newState == ServiceMBean.STARTED)
    {
      eventTime = change.getTimeStamp();
    }
    if (newState == ServiceMBean.STARTED)
      setStartTime(eventTime);
    int jsr77State = convertJBossState(newState);
    setState(jsr77State);
   }
 }
}

代码示例来源:origin: commons-modeler/commons-modeler

String name=anotif.getAttributeName();
Object value=anotif.getNewValue();
Object source=anotif.getSource();
String mname=null;

代码示例来源:origin: org.jboss.jbossas/jboss-as-jmx-remoting

if(ch.getAttributeName().equals("State") &&
 (ch.getAttributeType().equals(Integer.TYPE.getName()) || ch.getAttributeType().equals(Integer.class.getName())))

代码示例来源:origin: wildfly/wildfly-core

private void writeNotification(AttributeChangeNotification notification, Path path) {
  try (BufferedWriter in = Files.newBufferedWriter(path, StandardCharsets.UTF_8, StandardOpenOption.APPEND)) {
    in.write(String.format("%s %s %s %s", notification.getType(), notification.getSequenceNumber(), notification.getSource().toString(), notification.getMessage()));
    in.newLine();
    in.flush();
      try (BufferedWriter in = Files
          .newBufferedWriter(path, StandardCharsets.UTF_8, StandardOpenOption.APPEND)) {
        in.write(String.format("%s %s %s %s", notification.getType(),
            notification.getSequenceNumber(), notification.getSource().toString(),
            notification.getMessage()));
        in.newLine();
        in.flush();

代码示例来源:origin: org.glassfish.main.common/amx-core

out = new AttributeChangeNotification(
    source,
    a.getSequenceNumber(),
    a.getTimeStamp(),
    a.getMessage(),
    a.getAttributeName(),
    a.getAttributeType(),
    a.getOldValue(),
    a.getNewValue());

代码示例来源:origin: org.glassfish.common/amx-core

public String stringify(Object o)
{
  final AttributeChangeNotification notif = (AttributeChangeNotification) o;
  final StringBuffer b = super._stringify(notif);
  append(b, "");
  final String attrName = notif.getAttributeName();
  final String oldValue = SmartStringifier.toString(notif.getOldValue());
  final String newValue = SmartStringifier.toString(notif.getNewValue());
  final String msg = attrName + ": " + oldValue + " => " + newValue;
  b.append(msg);
  return (b.toString());
}

代码示例来源:origin: commons-modeler/commons-modeler

/**
 * <p>Test whether notification enabled for this event.
 * Return true if:</p>
 * <ul>
 * <li>This is an attribute change notification</li>
 * <li>Either the set of accepted names is empty (implying that all
 *     attribute names are of interest) or the set of accepted names
 *     includes the name of the attribute in this notification</li>
 * </ul>
 */
public boolean isNotificationEnabled(Notification notification) {
  if (notification == null)
    return (false);
  if (!(notification instanceof AttributeChangeNotification))
    return (false);
  AttributeChangeNotification acn =
    (AttributeChangeNotification) notification;
  if (!AttributeChangeNotification.ATTRIBUTE_CHANGE.equals(acn.getType()))
    return (false);
  synchronized (names) {
    if (names.size() < 1)
      return (true);
    else
      return (names.contains(acn.getAttributeName()));
  }
}

相关文章