Search in sources :

Example 16 with Logger

use of mx4j.log.Logger in project geode by apache.

the class MX4JModelMBean method checkAssignability.

private void checkAssignability(Class parameter, Class declared) throws MBeanException {
    Logger logger = getLogger();
    if (logger.isEnabledFor(Logger.DEBUG)) {
        logger.debug("The class of the parameter is: " + parameter);
        if (parameter != null)
            logger.debug("The classloder of the parameter's class is: " + parameter.getClassLoader());
        logger.debug("The class declared as type of the attribute is: " + declared);
        if (declared != null)
            logger.debug("The classloader of the declared parameter's class is: " + declared.getClassLoader());
    }
    boolean assignable = false;
    if (declared == null || parameter == null)
        assignable = false;
    else if (declared == boolean.class && parameter == Boolean.class)
        assignable = true;
    else if (declared == byte.class && parameter == Byte.class)
        assignable = true;
    else if (declared == char.class && parameter == Character.class)
        assignable = true;
    else if (declared == short.class && parameter == Short.class)
        assignable = true;
    else if (declared == int.class && parameter == Integer.class)
        assignable = true;
    else if (declared == long.class && parameter == Long.class)
        assignable = true;
    else if (declared == float.class && parameter == Float.class)
        assignable = true;
    else if (declared == double.class && parameter == Double.class)
        assignable = true;
    else
        assignable = declared.isAssignableFrom(parameter);
    if (!assignable) {
        if (logger.isEnabledFor(Logger.TRACE))
            logger.trace("Parameter value's class and attribute's declared return class are not assignable");
        throw new MBeanException(new InvalidAttributeValueException(LocalizedStrings.MX4JModelMBean_RETURNED_TYPE_AND_DECLARED_TYPE_ARE_NOT_ASSIGNABLE.toLocalizedString()));
    }
}
Also used : MBeanException(javax.management.MBeanException) Logger(mx4j.log.Logger) FileLogger(mx4j.log.FileLogger) MBeanLogger(mx4j.log.MBeanLogger) InvalidAttributeValueException(javax.management.InvalidAttributeValueException)

Example 17 with Logger

use of mx4j.log.Logger in project geode by apache.

the class MX4JModelMBean method addAttributeChangeNotificationListener.

public void addAttributeChangeNotificationListener(NotificationListener listener, String attributeName, Object handback) throws MBeanException, RuntimeOperationsException, IllegalArgumentException {
    if (listener == null)
        throw new RuntimeOperationsException(new IllegalArgumentException(LocalizedStrings.MX4JModelMBean_LISTENER_CANNOT_BE_NULL.toLocalizedString()));
    AttributeChangeNotificationFilter filter = new AttributeChangeNotificationFilter();
    if (attributeName != null) {
        filter.enableAttribute(attributeName);
    } else {
        MBeanAttributeInfo[] ai = m_modelMBeanInfo.getAttributes();
        for (int i = 0; i < ai.length; i++) {
            Descriptor d = ((ModelMBeanAttributeInfo) ai[i]).getDescriptor();
            filter.enableAttribute((String) d.getFieldValue("name"));
        }
    }
    getAttributeChangeBroadcaster().addNotificationListener(listener, filter, handback);
    Logger logger = getLogger();
    if (logger.isEnabledFor(Logger.DEBUG))
        logger.debug("Listener " + listener + " for attribute " + attributeName + " added successfully, handback is " + handback);
}
Also used : ModelMBeanAttributeInfo(javax.management.modelmbean.ModelMBeanAttributeInfo) AttributeChangeNotificationFilter(javax.management.AttributeChangeNotificationFilter) Descriptor(javax.management.Descriptor) Logger(mx4j.log.Logger) FileLogger(mx4j.log.FileLogger) MBeanLogger(mx4j.log.MBeanLogger) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ModelMBeanAttributeInfo(javax.management.modelmbean.ModelMBeanAttributeInfo) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 18 with Logger

use of mx4j.log.Logger in project geode by apache.

the class MX4JModelMBean method getModelMBeanLogger.

private Logger getModelMBeanLogger(String notificationType) throws MBeanException {
    // Get a copy to avoid synchronization
    ModelMBeanInfo info = getModelMBeanInfo();
    // First look if there is a suitable notification descriptor, otherwise use MBean descriptor
    Descriptor descriptor = null;
    Logger modelMBeanLogger = null;
    if (notificationType != null) {
        descriptor = info.getDescriptor(notificationType, "notification");
        modelMBeanLogger = findLogger(descriptor);
    }
    if (modelMBeanLogger == null) {
        descriptor = info.getMBeanDescriptor();
        modelMBeanLogger = findLogger(descriptor);
        if (modelMBeanLogger != null)
            return modelMBeanLogger;
    }
    return null;
}
Also used : Descriptor(javax.management.Descriptor) Logger(mx4j.log.Logger) FileLogger(mx4j.log.FileLogger) MBeanLogger(mx4j.log.MBeanLogger) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo)

Example 19 with Logger

use of mx4j.log.Logger in project geode by apache.

the class MX4JModelMBean method getStaleness.

private int getStaleness(Descriptor attribute, Descriptor mbean, String lastUpdateField) {
    Logger logger = getLogger();
    Long currencyTimeLimit = getFieldTimeValue(attribute, mbean, "currencyTimeLimit");
    if (currencyTimeLimit == null) {
        // No time limit defined
        if (logger.isEnabledFor(Logger.TRACE))
            logger.trace("No currencyTimeLimit defined, assuming always stale");
        return ALWAYS_STALE;
    } else {
        long ctl = currencyTimeLimit.longValue() * 1000;
        if (logger.isEnabledFor(Logger.TRACE))
            logger.trace("currencyTimeLimit is (ms): " + ctl);
        if (ctl == 0) {
            // Never stale
            if (logger.isEnabledFor(Logger.TRACE))
                logger.trace("Never stale");
            return NEVER_STALE;
        } else if (// this should be == -1 but the other cases are in the air
        ctl < 0) {
            // Always stale
            if (logger.isEnabledFor(Logger.TRACE))
                logger.trace("Always stale");
            return ALWAYS_STALE;
        } else {
            Long timestamp = (Long) attribute.getFieldValue(lastUpdateField);
            long luts = 0;
            if (timestamp != null)
                luts = timestamp.longValue();
            if (logger.isEnabledFor(Logger.DEBUG))
                logger.debug(lastUpdateField + " is: " + luts);
            long now = System.currentTimeMillis();
            if (now < luts + ctl) {
                // Seems to be not stale, but has been set at least once ?
                if (timestamp == null) {
                    // Return stale to call it the first time
                    if (logger.isEnabledFor(Logger.TRACE))
                        logger.trace("Stale since was never set");
                    return STALE;
                } else {
                    if (logger.isEnabledFor(Logger.TRACE))
                        logger.trace("Not stale");
                    return NOT_STALE;
                }
            } else {
                // Stale
                if (logger.isEnabledFor(Logger.TRACE))
                    logger.trace("Stale");
                return STALE;
            }
        }
    }
}
Also used : Logger(mx4j.log.Logger) FileLogger(mx4j.log.FileLogger) MBeanLogger(mx4j.log.MBeanLogger)

Aggregations

FileLogger (mx4j.log.FileLogger)19 Logger (mx4j.log.Logger)19 MBeanLogger (mx4j.log.MBeanLogger)19 RuntimeOperationsException (javax.management.RuntimeOperationsException)10 MBeanException (javax.management.MBeanException)9 Descriptor (javax.management.Descriptor)7 MalformedObjectNameException (javax.management.MalformedObjectNameException)6 InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 AttributeNotFoundException (javax.management.AttributeNotFoundException)5 InstanceNotFoundException (javax.management.InstanceNotFoundException)5 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)5 ReflectionException (javax.management.ReflectionException)5 RuntimeErrorException (javax.management.RuntimeErrorException)5 ServiceNotFoundException (javax.management.ServiceNotFoundException)5 ModelMBeanInfo (javax.management.modelmbean.ModelMBeanInfo)5 ListenerNotFoundException (javax.management.ListenerNotFoundException)4 MBeanRegistrationException (javax.management.MBeanRegistrationException)4 ModelMBeanAttributeInfo (javax.management.modelmbean.ModelMBeanAttributeInfo)4 ImplementationException (mx4j.ImplementationException)4