Search in sources :

Example 26 with RuntimeOperationsException

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

the class RequiredModelMBean method sendNotification.

public void sendNotification(Notification ntfyObj) throws MBeanException, RuntimeOperationsException {
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), "sendNotification(Notification)", "Entry");
    }
    if (ntfyObj == null)
        throw new RuntimeOperationsException(new IllegalArgumentException("notification object must not be " + "null"), "Exception occurred trying to send a notification from a " + "RequiredModelMBean");
    // log notification if specified in descriptor
    Descriptor ntfyDesc = modelMBeanInfo.getDescriptor(ntfyObj.getType(), "notification");
    Descriptor mmbDesc = modelMBeanInfo.getMBeanDescriptor();
    if (ntfyDesc != null) {
        String logging = (String) ntfyDesc.getFieldValue("log");
        if (logging == null) {
            if (mmbDesc != null)
                logging = (String) mmbDesc.getFieldValue("log");
        }
        if ((logging != null) && (logging.equalsIgnoreCase("t") || logging.equalsIgnoreCase("true"))) {
            String logfile = (String) ntfyDesc.getFieldValue("logfile");
            if (logfile == null) {
                if (mmbDesc != null)
                    logfile = (String) mmbDesc.getFieldValue("logfile");
            }
            if (logfile != null) {
                try {
                    writeToLog(logfile, "LogMsg: " + ((new Date(ntfyObj.getTimeStamp())).toString()) + " " + ntfyObj.getType() + " " + ntfyObj.getMessage() + " Severity = " + (String) ntfyDesc.getFieldValue("severity"));
                } catch (Exception e) {
                    if (MODELMBEAN_LOGGER.isLoggable(Level.FINE)) {
                        MODELMBEAN_LOGGER.logp(Level.FINE, RequiredModelMBean.class.getName(), "sendNotification(Notification)", "Failed to log " + ntfyObj.getType() + " notification: ", e);
                    }
                }
            }
        }
    }
    if (generalBroadcaster != null) {
        generalBroadcaster.sendNotification(ntfyObj);
    }
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), "sendNotification(Notification)", "sendNotification sent provided notification object");
        MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), "sendNotification(Notification)", " Exit");
    }
}
Also used : Descriptor(javax.management.Descriptor) Date(java.util.Date) AttributeNotFoundException(javax.management.AttributeNotFoundException) ServiceNotFoundException(javax.management.ServiceNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) RuntimeErrorException(javax.management.RuntimeErrorException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) ListenerNotFoundException(javax.management.ListenerNotFoundException) RuntimeOperationsException(javax.management.RuntimeOperationsException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 27 with RuntimeOperationsException

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

the class RequiredModelMBean method addAttributeChangeNotificationListener.

public void addAttributeChangeNotificationListener(NotificationListener inlistener, String inAttributeName, Object inhandback) throws MBeanException, RuntimeOperationsException, IllegalArgumentException {
    final String mth = "addAttributeChangeNotificationListener(" + "NotificationListener, String, Object)";
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), mth, "Entry");
    }
    if (inlistener == null)
        throw new IllegalArgumentException("Listener to be registered must not be null");
    if (attributeBroadcaster == null)
        attributeBroadcaster = new NotificationBroadcasterSupport();
    AttributeChangeNotificationFilter currFilter = new AttributeChangeNotificationFilter();
    MBeanAttributeInfo[] attrInfo = modelMBeanInfo.getAttributes();
    boolean found = false;
    if (inAttributeName == null) {
        if ((attrInfo != null) && (attrInfo.length > 0)) {
            for (int i = 0; i < attrInfo.length; i++) {
                currFilter.enableAttribute(attrInfo[i].getName());
            }
        }
    } else {
        if ((attrInfo != null) && (attrInfo.length > 0)) {
            for (int i = 0; i < attrInfo.length; i++) {
                if (inAttributeName.equals(attrInfo[i].getName())) {
                    found = true;
                    currFilter.enableAttribute(inAttributeName);
                    break;
                }
            }
        }
        if (!found) {
            throw new RuntimeOperationsException(new IllegalArgumentException("The attribute name does not exist"), "Exception occurred trying to add an " + "AttributeChangeNotification listener");
        }
    }
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        Vector<String> enabledAttrs = currFilter.getEnabledAttributes();
        String s = (enabledAttrs.size() > 1) ? "[" + enabledAttrs.firstElement() + ", ...]" : enabledAttrs.toString();
        MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), mth, "Set attribute change filter to " + s);
    }
    attributeBroadcaster.addNotificationListener(inlistener, currFilter, inhandback);
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), mth, "Notification listener added for " + inAttributeName);
        MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), mth, "Exit");
    }
}
Also used : AttributeChangeNotificationFilter(javax.management.AttributeChangeNotificationFilter) NotificationBroadcasterSupport(javax.management.NotificationBroadcasterSupport) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 28 with RuntimeOperationsException

use of javax.management.RuntimeOperationsException 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 29 with RuntimeOperationsException

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

the class ModelMBeanOperationInfo method validDescriptor.

/**
         * Clones the passed in Descriptor, sets default values, and checks for validity.
         * If the Descriptor is invalid (for instance by having the wrong "name"),
         * this indicates programming error and a RuntimeOperationsException will be thrown.
         *
         * The following fields will be defaulted if they are not already set:
         * displayName=this.getName(),name=this.getName(),
         * descriptorType="operation", role="operation"
         *
         *
         * @param in Descriptor to be checked, or null which is equivalent to
         * an empty Descriptor.
         * @exception RuntimeOperationsException if Descriptor is invalid
         */
private Descriptor validDescriptor(final Descriptor in) throws RuntimeOperationsException {
    Descriptor clone;
    boolean defaulted = (in == null);
    if (defaulted) {
        clone = new DescriptorSupport();
        MODELMBEAN_LOGGER.finer("Null Descriptor, creating new.");
    } else {
        clone = (Descriptor) in.clone();
    }
    //Setting defaults.
    if (defaulted && clone.getFieldValue("name") == null) {
        clone.setField("name", this.getName());
        MODELMBEAN_LOGGER.finer("Defaulting Descriptor name to " + this.getName());
    }
    if (defaulted && clone.getFieldValue("descriptorType") == null) {
        clone.setField("descriptorType", "operation");
        MODELMBEAN_LOGGER.finer("Defaulting descriptorType to \"operation\"");
    }
    if (clone.getFieldValue("displayName") == null) {
        clone.setField("displayName", this.getName());
        MODELMBEAN_LOGGER.finer("Defaulting Descriptor displayName to " + this.getName());
    }
    if (clone.getFieldValue("role") == null) {
        clone.setField("role", "operation");
        MODELMBEAN_LOGGER.finer("Defaulting Descriptor role field to \"operation\"");
    }
    //Checking validity
    if (!clone.isValid()) {
        throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"), "The isValid() method of the Descriptor object itself returned false," + "one or more required fields are invalid. Descriptor:" + clone.toString());
    }
    if (!getName().equalsIgnoreCase((String) clone.getFieldValue("name"))) {
        throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"), "The Descriptor \"name\" field does not match the object described. " + " Expected: " + this.getName() + " , was: " + clone.getFieldValue("name"));
    }
    if (!"operation".equalsIgnoreCase((String) clone.getFieldValue("descriptorType"))) {
        throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"), "The Descriptor \"descriptorType\" field does not match the object described. " + " Expected: \"operation\" ," + " was: " + clone.getFieldValue("descriptorType"));
    }
    final String role = (String) clone.getFieldValue("role");
    if (!(role.equalsIgnoreCase("operation") || role.equalsIgnoreCase("setter") || role.equalsIgnoreCase("getter"))) {
        throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"), "The Descriptor \"role\" field does not match the object described. " + " Expected: \"operation\", \"setter\", or \"getter\" ," + " was: " + clone.getFieldValue("role"));
    }
    final Object targetValue = clone.getFieldValue("targetType");
    if (targetValue != null) {
        if (!(targetValue instanceof java.lang.String)) {
            throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"), "The Descriptor field \"targetValue\" is invalid class. " + " Expected: java.lang.String, " + " was: " + targetValue.getClass().getName());
        }
    }
    return clone;
}
Also used : Descriptor(javax.management.Descriptor) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 30 with RuntimeOperationsException

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

the class RequiredModelMBean method sendAttributeChangeNotification.

public void sendAttributeChangeNotification(AttributeChangeNotification ntfyObj) throws MBeanException, RuntimeOperationsException {
    final String mth = "sendAttributeChangeNotification(" + "AttributeChangeNotification)";
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), mth, "Entry");
    }
    if (ntfyObj == null)
        throw new RuntimeOperationsException(new IllegalArgumentException("attribute change notification object must not be null"), "Exception occurred trying to send " + "attribute change notification of a ModelMBean");
    Object oldv = ntfyObj.getOldValue();
    Object newv = ntfyObj.getNewValue();
    if (oldv == null)
        oldv = "null";
    if (newv == null)
        newv = "null";
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), mth, "Sending AttributeChangeNotification with " + ntfyObj.getAttributeName() + ntfyObj.getAttributeType() + ntfyObj.getNewValue() + ntfyObj.getOldValue());
    }
    // log notification if specified in descriptor
    Descriptor ntfyDesc = modelMBeanInfo.getDescriptor(ntfyObj.getType(), "notification");
    Descriptor mmbDesc = modelMBeanInfo.getMBeanDescriptor();
    String logging, logfile;
    if (ntfyDesc != null) {
        logging = (String) ntfyDesc.getFieldValue("log");
        if (logging == null) {
            if (mmbDesc != null)
                logging = (String) mmbDesc.getFieldValue("log");
        }
        if ((logging != null) && (logging.equalsIgnoreCase("t") || logging.equalsIgnoreCase("true"))) {
            logfile = (String) ntfyDesc.getFieldValue("logfile");
            if (logfile == null) {
                if (mmbDesc != null)
                    logfile = (String) mmbDesc.getFieldValue("logfile");
            }
            if (logfile != null) {
                try {
                    writeToLog(logfile, "LogMsg: " + ((new Date(ntfyObj.getTimeStamp())).toString()) + " " + ntfyObj.getType() + " " + ntfyObj.getMessage() + " Name = " + ntfyObj.getAttributeName() + " Old value = " + oldv + " New value = " + newv);
                } catch (Exception e) {
                    if (MODELMBEAN_LOGGER.isLoggable(Level.FINE)) {
                        MODELMBEAN_LOGGER.logp(Level.FINE, RequiredModelMBean.class.getName(), mth, "Failed to log " + ntfyObj.getType() + " notification: ", e);
                    }
                }
            }
        }
    } else if (mmbDesc != null) {
        logging = (String) mmbDesc.getFieldValue("log");
        if ((logging != null) && (logging.equalsIgnoreCase("t") || logging.equalsIgnoreCase("true"))) {
            logfile = (String) mmbDesc.getFieldValue("logfile");
            if (logfile != null) {
                try {
                    writeToLog(logfile, "LogMsg: " + ((new Date(ntfyObj.getTimeStamp())).toString()) + " " + ntfyObj.getType() + " " + ntfyObj.getMessage() + " Name = " + ntfyObj.getAttributeName() + " Old value = " + oldv + " New value = " + newv);
                } catch (Exception e) {
                    if (MODELMBEAN_LOGGER.isLoggable(Level.FINE)) {
                        MODELMBEAN_LOGGER.logp(Level.FINE, RequiredModelMBean.class.getName(), mth, "Failed to log " + ntfyObj.getType() + " notification: ", e);
                    }
                }
            }
        }
    }
    if (attributeBroadcaster != null) {
        attributeBroadcaster.sendNotification(ntfyObj);
    }
    //
    if (generalBroadcaster != null) {
        generalBroadcaster.sendNotification(ntfyObj);
    }
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), mth, "sent notification");
        MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), mth, "Exit");
    }
}
Also used : Descriptor(javax.management.Descriptor) Date(java.util.Date) AttributeNotFoundException(javax.management.AttributeNotFoundException) ServiceNotFoundException(javax.management.ServiceNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) RuntimeErrorException(javax.management.RuntimeErrorException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) ListenerNotFoundException(javax.management.ListenerNotFoundException) RuntimeOperationsException(javax.management.RuntimeOperationsException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Aggregations

RuntimeOperationsException (javax.management.RuntimeOperationsException)67 AttributeNotFoundException (javax.management.AttributeNotFoundException)23 InstanceNotFoundException (javax.management.InstanceNotFoundException)20 ReflectionException (javax.management.ReflectionException)20 MBeanException (javax.management.MBeanException)18 Descriptor (javax.management.Descriptor)17 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)16 ListenerNotFoundException (javax.management.ListenerNotFoundException)16 RuntimeErrorException (javax.management.RuntimeErrorException)14 InvocationTargetException (java.lang.reflect.InvocationTargetException)13 ServiceNotFoundException (javax.management.ServiceNotFoundException)13 DynamicMBean (javax.management.DynamicMBean)10 FileLogger (mx4j.log.FileLogger)10 Logger (mx4j.log.Logger)10 MBeanLogger (mx4j.log.MBeanLogger)10 MBeanRegistrationException (javax.management.MBeanRegistrationException)9 JMRuntimeException (javax.management.JMRuntimeException)8 InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)8 Attribute (javax.management.Attribute)7 Date (java.util.Date)6