Search in sources :

Example 11 with AttributeChangeNotification

use of javax.management.AttributeChangeNotification in project wildfly by wildfly.

the class ServiceMBeanSupport method sendStateChangeNotification.

/**
     * 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);
}
Also used : AttributeChangeNotification(javax.management.AttributeChangeNotification)

Example 12 with AttributeChangeNotification

use of javax.management.AttributeChangeNotification in project wildfly by wildfly.

the class TestResultService method handleNotification.

@Override
public void handleNotification(Notification notification, Object handback) {
    if (notification instanceof AttributeChangeNotification) {
        AttributeChangeNotification attributeChangeNotification = (AttributeChangeNotification) notification;
        int oldValue = (Integer) attributeChangeNotification.getOldValue();
        int newValue = (Integer) attributeChangeNotification.getNewValue();
        logger.trace("Attribute change notification: " + oldValue + "->" + newValue);
        if (oldValue == STOPPED && newValue == STARTING) {
            startingNotificationReceived = true;
        } else if (oldValue == STARTING && newValue == STARTED) {
            startedNotificationReceived = true;
        } else if (oldValue == STARTED && newValue == STOPPING) {
            stoppingNotificationReceived = true;
        } else if (oldValue == STOPPING && newValue == STOPPED) {
            stoppedNotificationReceived = true;
        }
    }
}
Also used : AttributeChangeNotification(javax.management.AttributeChangeNotification)

Example 13 with AttributeChangeNotification

use of javax.management.AttributeChangeNotification in project jdk8u_jdk by JetBrains.

the class RequiredModelMBean method sendAttributeChangeNotification.

public void sendAttributeChangeNotification(Attribute inOldVal, Attribute inNewVal) throws MBeanException, RuntimeOperationsException {
    final String mth = "sendAttributeChangeNotification(Attribute, Attribute)";
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), mth, "Entry");
    }
    // do we really want to do this?
    if ((inOldVal == null) || (inNewVal == null))
        throw new RuntimeOperationsException(new IllegalArgumentException("Attribute object must not be null"), "Exception occurred trying to send " + "attribute change notification of a ModelMBean");
    if (!(inOldVal.getName().equals(inNewVal.getName())))
        throw new RuntimeOperationsException(new IllegalArgumentException("Attribute names are not the same"), "Exception occurred trying to send " + "attribute change notification of a ModelMBean");
    Object newVal = inNewVal.getValue();
    Object oldVal = inOldVal.getValue();
    String className = "unknown";
    if (newVal != null)
        className = newVal.getClass().getName();
    if (oldVal != null)
        className = oldVal.getClass().getName();
    AttributeChangeNotification myNtfyObj = new AttributeChangeNotification(this, 1, ((new Date()).getTime()), "AttributeChangeDetected", inOldVal.getName(), className, inOldVal.getValue(), inNewVal.getValue());
    sendAttributeChangeNotification(myNtfyObj);
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), mth, "Exit");
    }
}
Also used : AttributeChangeNotification(javax.management.AttributeChangeNotification) Date(java.util.Date) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 14 with AttributeChangeNotification

use of javax.management.AttributeChangeNotification in project camel by apache.

the class SimpleBean method tick.

public void tick() throws Exception {
    tick++;
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-dd-MM'T'HH:mm:ss");
    Date date = sdf.parse("2010-07-01T10:30:15");
    long timeStamp = date.getTime();
    AttributeChangeNotification acn = new AttributeChangeNotification(this, sequence++, timeStamp, "attribute changed", "stringValue", "string", tick - 1, tick);
    sendNotification(acn);
}
Also used : AttributeChangeNotification(javax.management.AttributeChangeNotification) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 15 with AttributeChangeNotification

use of javax.management.AttributeChangeNotification in project tomcat by apache.

the class BaseModelMBean method sendAttributeChangeNotification.

/**
     * Send an <code>AttributeChangeNotification</code> to all registered
     * listeners.
     *
     * @param oldValue The original value of the <code>Attribute</code>
     * @param newValue The new value of the <code>Attribute</code>
     *
     * @exception MBeanException if an object initializer throws an
     *  exception
     * @exception RuntimeOperationsException wraps IllegalArgumentException
     *  when the specified notification is <code>null</code> or invalid
     */
@Override
public void sendAttributeChangeNotification(Attribute oldValue, Attribute newValue) throws MBeanException, RuntimeOperationsException {
    // Calculate the class name for the change notification
    String type = null;
    if (newValue.getValue() != null)
        type = newValue.getValue().getClass().getName();
    else if (oldValue.getValue() != null)
        type = oldValue.getValue().getClass().getName();
    else
        // Old and new are both null == no change
        return;
    AttributeChangeNotification notification = new AttributeChangeNotification(this, 1, System.currentTimeMillis(), "Attribute value has changed", oldValue.getName(), type, oldValue.getValue(), newValue.getValue());
    sendAttributeChangeNotification(notification);
}
Also used : AttributeChangeNotification(javax.management.AttributeChangeNotification)

Aggregations

AttributeChangeNotification (javax.management.AttributeChangeNotification)28 Notification (javax.management.Notification)14 NotificationListener (javax.management.NotificationListener)8 Test (org.junit.Test)6 ObjectName (javax.management.ObjectName)5 Bundle (org.osgi.framework.Bundle)4 ScanState (com.sun.jmx.examples.scandir.ScanManagerMXBean.ScanState)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)3 NotificationFilter (javax.management.NotificationFilter)3 LinkedList (java.util.LinkedList)2 ExecutorService (java.util.concurrent.ExecutorService)2 MBeanServer (javax.management.MBeanServer)2 NotificationEmitter (javax.management.NotificationEmitter)2 RuntimeOperationsException (javax.management.RuntimeOperationsException)2 CompositeData (javax.management.openmbean.CompositeData)2 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)2 Call (com.sun.jmx.examples.scandir.ScanManagerTest.Call)1 DirectoryScannerConfig (com.sun.jmx.examples.scandir.config.DirectoryScannerConfig)1