Package javax.management

Examples of javax.management.AttributeChangeNotification


      }
   }

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


      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(),
View Full Code Here

                propertiesHistory.signalPossibleNotificationLoss();
            }
        }
        lastNotificationSequenceNumber = notificationSequenceNumber;

        AttributeChangeNotification attributeChangeNotification = (AttributeChangeNotification) notification;
        if (!(attributeChangeNotification.getSource() instanceof String)) {
            logger.error("JMX notification source from " + componentName + " is not of type String (" + attributeChangeNotification.getSource().getClass().getName() + ")");
            return;
        }

        String message = (String) attributeChangeNotification.getMessage();
        int separatorIndex = message.indexOf(':');
        String subComponent = ((separatorIndex != -1) ? message.substring(0, separatorIndex) : "");
        String subComponentName = subComponentsMap.get(subComponent);
        if (subComponentName == null) {
            logger.error("Received JMX notification from " + componentName + " from unknown sub-component " + subComponent + " - message: " + attributeChangeNotification.getMessage());
            return;
        }

        String attributeName = attributeChangeNotification.getAttributeName();
        // remove "prefix." or "prefix:" if any
        int dotIndex = attributeName.lastIndexOf('.');
        if (dotIndex < 0) {
            dotIndex = attributeName.lastIndexOf(':');
        }
        if (dotIndex > 0) {
            if (dotIndex == attributeName.length() - 1) {
                logger.error("Received JMX notification from " + componentName + " for empty attribute name: " + attributeName);
                return;
            }
            attributeName = attributeName.substring(dotIndex + 1);
        }
        // rename "StateProperty" into "state"
        if (attributeName.equals("StateProperty")) {
            attributeName = "state";
        }

        String propertyName = (subComponentName.isEmpty() ? "" : subComponentName.toLowerCase() + ".") + attributeName.toLowerCase();
        String oldValue = String.valueOf(attributeChangeNotification.getOldValue()).toLowerCase();
        String newValue = String.valueOf(attributeChangeNotification.getNewValue()).toLowerCase();

        // hack to get "null" string if the String is empty ("")
        if (oldValue.isEmpty()) {
            oldValue = "null";
        }
        if (newValue.isEmpty()) {
            newValue = "null";
        }
       
        boolean checkOldValue = (attributeChangeNotification.getOldValue() != null);

        propertiesHistory.addChange(propertyName, oldValue, newValue, notificationSequenceNumber, checkOldValue);
    }
View Full Code Here

    public synchronized void sendNotification(PropertyChangeEvent pEvt) {
        String oldValue = pEvt.getOldValue() == null ? "null" : pEvt.getOldValue().toString();
        String newValue = pEvt.getNewValue() == null ? "null" : pEvt.getNewValue().toString();
        String sourceName = pEvt.getSource().getClass().getCanonicalName();
        String message = sourceName + ":" + pEvt.getPropertyName() + " changed from " + oldValue + " to " + newValue;
        Notification n = new AttributeChangeNotification(sourceName, notifSequenceNumber++, System.currentTimeMillis(),
                message, pEvt.getPropertyName(), "java.lang.String", oldValue, newValue);
        sendNotification(n);
        logger.trace("Sent notification: " + message);
    }
View Full Code Here

       
        state = STARTING;
       
        // Notifying the MBEan server that we're starting
       
        notification = new AttributeChangeNotification
            (this, sequenceNumber++, System.currentTimeMillis(),
             "Starting " + NAME, "State", "java.lang.Integer",
             new Integer(STOPPED), new Integer(STARTING));
        sendNotification(notification);
       
        try {
           
            String value = "org.apache.naming";
            String oldValue = System.getProperty(Context.URL_PKG_PREFIXES);
            if (oldValue != null) {
                oldUrlValue = oldValue;
                value = oldValue + ":" + value;
            }
            System.setProperty(Context.URL_PKG_PREFIXES, value);
           
            oldValue = System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
            if ((oldValue != null) && (oldValue.length() > 0)) {
                oldIcValue = oldValue;
            } else {
                System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
                                   Constants.Package
                                   + ".java.javaURLContextFactory");
            }
           
        } catch (Throwable t) {
            state = STOPPED;
            notification = new AttributeChangeNotification
                (this, sequenceNumber++, System.currentTimeMillis(),
                 "Stopped " + NAME, "State", "java.lang.Integer",
                 new Integer(STARTING), new Integer(STOPPED));
            sendNotification(notification);
        }
       
        state = STARTED;
        notification = new AttributeChangeNotification
            (this, sequenceNumber++, System.currentTimeMillis(),
             "Started " + NAME, "State", "java.lang.Integer",
             new Integer(STARTING), new Integer(STARTED));
        sendNotification(notification);
       
View Full Code Here

        if (state != STARTED)
            return;
       
        state = STOPPING;
       
        notification = new AttributeChangeNotification
            (this, sequenceNumber++, System.currentTimeMillis(),
             "Stopping " + NAME, "State", "java.lang.Integer",
             new Integer(STARTED), new Integer(STOPPING));
        sendNotification(notification);
       
        try {
           
            System.setProperty(Context.URL_PKG_PREFIXES, oldUrlValue);
            System.setProperty(Context.INITIAL_CONTEXT_FACTORY, oldIcValue);
           
        } catch (Throwable t) {
           
            // FIXME
            t.printStackTrace();
           
        }
       
        state = STOPPED;
       
        notification = new AttributeChangeNotification
            (this, sequenceNumber++, System.currentTimeMillis(),
             "Stopped " + NAME, "State", "java.lang.Integer",
             new Integer(STOPPING), new Integer(STOPPED));
        sendNotification(notification);
       
View Full Code Here

      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(),
View Full Code Here

      return new Attribute("attr-name", "attr-value");
   }

   public AttributeChangeNotification createAttributeChangeNotification()
   {
      AttributeChangeNotification notification = new AttributeChangeNotification("notif-source", 13L, System.currentTimeMillis(), "notif-message", "attr-name", "attr-type", "old", "new");
      notification.setUserData("notif-user");
      return notification;
   }
View Full Code Here

        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(),
View Full Code Here

      }
      else if(notification instanceof AttributeChangeNotification)
      {
         // we want state changes directly
         AttributeChangeNotification ch = (AttributeChangeNotification) notification;
         if(ch.getAttributeName().equals("State") &&
            (ch.getAttributeType().equals(Integer.TYPE.getName()) || ch.getAttributeType().equals(Integer.class.getName())))
         {
            return true;
         }
      }
      if(wantNotifications)
View Full Code Here

TOP

Related Classes of javax.management.AttributeChangeNotification

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.