Search in sources :

Example 11 with AttributeNotFoundException

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

the class RelationService method initializeMissingRoles.

// Initializes roles associated to given role infos to default value (empty
// ArrayList of ObjectNames) in given relation.
// It will succeed for every role except if the role info has a minimum
// cardinality greater than 0. In that case, an InvalidRoleValueException
// will be raised.
//
// -param relationBaseFlag  flag true if the relation is a RelationSupport
//  object, false if it is an MBean
// -param relationObj  RelationSupport object (if relation is internal)
// -param relationObjName  ObjectName of the MBean to be added as a relation
//  (only for the relation MBean)
// -param relationId  relation id
// -param relationTypeName  name of the relation type (has to be created
//  in the Relation Service)
// -param roleInfoList  list of role infos for roles to be defaulted
//
// -exception IllegalArgumentException  if null paramater
// -exception RelationServiceNotRegisteredException  if the Relation
//  Service is not registered in the MBean Server
// -exception InvalidRoleValueException  if role must have a non-empty
//  value
// Revisit [cebro] Handle CIM qualifiers as REQUIRED to detect roles which
//    should have been initialized by the user
private void initializeMissingRoles(boolean relationBaseFlag, RelationSupport relationObj, ObjectName relationObjName, String relationId, String relationTypeName, List<RoleInfo> roleInfoList) throws IllegalArgumentException, RelationServiceNotRegisteredException, InvalidRoleValueException {
    if ((relationBaseFlag && (relationObj == null || relationObjName != null)) || (!relationBaseFlag && (relationObjName == null || relationObj != null)) || relationId == null || relationTypeName == null || roleInfoList == null) {
        String excMsg = "Invalid parameter.";
        throw new IllegalArgumentException(excMsg);
    }
    RELATION_LOGGER.entering(RelationService.class.getName(), "initializeMissingRoles", new Object[] { relationBaseFlag, relationObj, relationObjName, relationId, relationTypeName, roleInfoList });
    // Can throw RelationServiceNotRegisteredException
    isActive();
    // empty value, according to its minimum cardinality
    for (RoleInfo currRoleInfo : roleInfoList) {
        String roleName = currRoleInfo.getName();
        // Creates an empty value
        List<ObjectName> emptyValue = new ArrayList<ObjectName>();
        // Creates a role
        Role role = new Role(roleName, emptyValue);
        if (relationBaseFlag) {
            // RelationTypeNotFoundException
            try {
                relationObj.setRoleInt(role, true, this, false);
            } catch (RoleNotFoundException exc1) {
                throw new RuntimeException(exc1.getMessage());
            } catch (RelationNotFoundException exc2) {
                throw new RuntimeException(exc2.getMessage());
            } catch (RelationTypeNotFoundException exc3) {
                throw new RuntimeException(exc3.getMessage());
            }
        } else {
            // Relation is an MBean
            // Use standard setRole()
            Object[] params = new Object[1];
            params[0] = role;
            String[] signature = new String[1];
            signature[0] = "javax.management.relation.Role";
            // the relation MBeans are registered in the same MBean Server.
            try {
                myMBeanServer.setAttribute(relationObjName, new Attribute("Role", role));
            } catch (InstanceNotFoundException exc1) {
                throw new RuntimeException(exc1.getMessage());
            } catch (ReflectionException exc3) {
                throw new RuntimeException(exc3.getMessage());
            } catch (MBeanException exc2) {
                Exception wrappedExc = exc2.getTargetException();
                if (wrappedExc instanceof InvalidRoleValueException) {
                    throw ((InvalidRoleValueException) wrappedExc);
                } else {
                    throw new RuntimeException(wrappedExc.getMessage());
                }
            } catch (AttributeNotFoundException exc4) {
                throw new RuntimeException(exc4.getMessage());
            } catch (InvalidAttributeValueException exc5) {
                throw new RuntimeException(exc5.getMessage());
            }
        }
    }
    RELATION_LOGGER.exiting(RelationService.class.getName(), "initializeMissingRoles");
    return;
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) Attribute(javax.management.Attribute) InstanceNotFoundException(javax.management.InstanceNotFoundException) ArrayList(java.util.ArrayList) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) AttributeNotFoundException(javax.management.AttributeNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) ObjectName(javax.management.ObjectName) MBeanException(javax.management.MBeanException)

Example 12 with AttributeNotFoundException

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

the class RelationService method setRole.

/**
     * Sets the given role in given relation.
     * <P>Will check the role according to its corresponding role definition
     * provided in relation's relation type
     * <P>The Relation Service will keep track of the change to keep the
     * consistency of relations by handling referenced MBean deregistrations.
     *
     * @param relationId  relation id
     * @param role  role to be set (name and new value)
     *
     * @exception RelationServiceNotRegisteredException  if the Relation
     * Service is not registered in the MBean Server
     * @exception IllegalArgumentException  if null parameter
     * @exception RelationNotFoundException  if no relation with given id
     * @exception RoleNotFoundException  if the role does not exist or is not
     * writable
     * @exception InvalidRoleValueException  if value provided for role is not
     * valid:
     * <P>- the number of referenced MBeans in given value is less than
     * expected minimum degree
     * <P>or
     * <P>- the number of referenced MBeans in provided value exceeds expected
     * maximum degree
     * <P>or
     * <P>- one referenced MBean in the value is not an Object of the MBean
     * class expected for that role
     * <P>or
     * <P>- an MBean provided for that role does not exist
     *
     * @see #getRole
     */
public void setRole(String relationId, Role role) throws RelationServiceNotRegisteredException, IllegalArgumentException, RelationNotFoundException, RoleNotFoundException, InvalidRoleValueException {
    if (relationId == null || role == null) {
        String excMsg = "Invalid parameter.";
        throw new IllegalArgumentException(excMsg);
    }
    RELATION_LOGGER.entering(RelationService.class.getName(), "setRole", new Object[] { relationId, role });
    // Can throw RelationServiceNotRegisteredException
    isActive();
    // Can throw a RelationNotFoundException
    Object relObj = getRelation(relationId);
    if (relObj instanceof RelationSupport) {
        // (as relation exists in the RS, its relation type is known)
        try {
            ((RelationSupport) relObj).setRoleInt(role, true, this, false);
        } catch (RelationTypeNotFoundException exc) {
            throw new RuntimeException(exc.getMessage());
        }
    } else {
        // Relation MBean
        Object[] params = new Object[1];
        params[0] = role;
        String[] signature = new String[1];
        signature[0] = "javax.management.relation.Role";
        // InstanceNotFoundException
        try {
            myMBeanServer.setAttribute(((ObjectName) relObj), new Attribute("Role", role));
        } catch (InstanceNotFoundException exc1) {
            throw new RuntimeException(exc1.getMessage());
        } catch (ReflectionException exc3) {
            throw new RuntimeException(exc3.getMessage());
        } catch (MBeanException exc2) {
            Exception wrappedExc = exc2.getTargetException();
            if (wrappedExc instanceof RoleNotFoundException) {
                throw ((RoleNotFoundException) wrappedExc);
            } else if (wrappedExc instanceof InvalidRoleValueException) {
                throw ((InvalidRoleValueException) wrappedExc);
            } else {
                throw new RuntimeException(wrappedExc.getMessage());
            }
        } catch (AttributeNotFoundException exc4) {
            throw new RuntimeException(exc4.getMessage());
        } catch (InvalidAttributeValueException exc5) {
            throw new RuntimeException(exc5.getMessage());
        }
    }
    RELATION_LOGGER.exiting(RelationService.class.getName(), "setRole");
    return;
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) Attribute(javax.management.Attribute) InstanceNotFoundException(javax.management.InstanceNotFoundException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) AttributeNotFoundException(javax.management.AttributeNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) ObjectName(javax.management.ObjectName) MBeanException(javax.management.MBeanException)

Example 13 with AttributeNotFoundException

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

the class DefaultMBeanServerInterceptor method setAttribute.

public void setAttribute(ObjectName name, Attribute attribute) throws InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    if (name == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException("ObjectName name cannot be null"), "Exception occurred trying to invoke the setter on the MBean");
    }
    if (attribute == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException("Attribute cannot be null"), "Exception occurred trying to invoke the setter on the MBean");
    }
    name = nonDefaultDomain(name);
    if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
        MBEANSERVER_LOGGER.logp(Level.FINER, DefaultMBeanServerInterceptor.class.getName(), "setAttribute", "ObjectName = " + name + ", Attribute = " + attribute.getName());
    }
    DynamicMBean instance = getMBean(name);
    checkMBeanPermission(instance, attribute.getName(), name, "setAttribute");
    try {
        instance.setAttribute(attribute);
    } catch (AttributeNotFoundException e) {
        throw e;
    } catch (InvalidAttributeValueException e) {
        throw e;
    } catch (Throwable t) {
        rethrowMaybeMBeanException(t);
        throw new AssertionError();
    }
}
Also used : DynamicMBean(javax.management.DynamicMBean) AttributeNotFoundException(javax.management.AttributeNotFoundException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 14 with AttributeNotFoundException

use of javax.management.AttributeNotFoundException in project bamboobsc by billchen198318.

the class HostUtils method getHttpPort.

public static int getHttpPort() {
    int port = 8080;
    MBeanServer mBeanServer = MBeanServerFactory.findMBeanServer(null).get(0);
    ObjectName name;
    try {
        name = new ObjectName("Catalina", "type", "Server");
        try {
            Server server = (Server) mBeanServer.getAttribute(name, "managedResource");
            Service[] services = server.findServices();
            for (Service service : services) {
                for (Connector connector : service.findConnectors()) {
                    ProtocolHandler protocolHandler = connector.getProtocolHandler();
                    if (protocolHandler instanceof Http11Protocol || protocolHandler instanceof Http11AprProtocol || protocolHandler instanceof Http11NioProtocol) {
                        port = connector.getPort();
                    }
                }
            }
        } catch (AttributeNotFoundException e) {
            e.printStackTrace();
        } catch (InstanceNotFoundException e) {
            e.printStackTrace();
        } catch (MBeanException e) {
            e.printStackTrace();
        } catch (ReflectionException e) {
            e.printStackTrace();
        }
    } catch (MalformedObjectNameException e) {
        e.printStackTrace();
    }
    return port;
}
Also used : Connector(org.apache.catalina.connector.Connector) ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) MalformedObjectNameException(javax.management.MalformedObjectNameException) Http11NioProtocol(org.apache.coyote.http11.Http11NioProtocol) MBeanServer(javax.management.MBeanServer) Server(org.apache.catalina.Server) InstanceNotFoundException(javax.management.InstanceNotFoundException) Service(org.apache.catalina.Service) Http11AprProtocol(org.apache.coyote.http11.Http11AprProtocol) ObjectName(javax.management.ObjectName) ProtocolHandler(org.apache.coyote.ProtocolHandler) Http11Protocol(org.apache.coyote.http11.Http11Protocol) MBeanException(javax.management.MBeanException) MBeanServer(javax.management.MBeanServer)

Example 15 with AttributeNotFoundException

use of javax.management.AttributeNotFoundException in project geode by apache.

the class MX4JModelMBean method setAttribute.

public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    if (attribute == null)
        throw new RuntimeOperationsException(new IllegalArgumentException(LocalizedStrings.MX4JModelMBean_ATTRIBUTE_CANNOT_BE_NULL.toLocalizedString()));
    Logger logger = getLogger();
    // No need to synchronize: I work mostly on clones
    // I want the real info, not its clone
    ModelMBeanInfo info = getModelMBeanInfo();
    if (info == null)
        throw new AttributeNotFoundException(LocalizedStrings.MX4JModelMBean_MODELMBEANINFO_IS_NULL.toLocalizedString());
    if (logger.isEnabledFor(Logger.DEBUG))
        logger.debug("ModelMBeanInfo is: " + info);
    String attrName = attribute.getName();
    Object attrValue = attribute.getValue();
    // This is a clone, we use it read only
    ModelMBeanAttributeInfo attrInfo = info.getAttribute(attrName);
    if (attrInfo == null)
        throw new AttributeNotFoundException(LocalizedStrings.MX4JModelMBean_CANNOT_FIND_MODELMBEANATTRIBUTEINFO_FOR_ATTRIBUTE_0.toLocalizedString(attrName));
    if (logger.isEnabledFor(Logger.DEBUG))
        logger.debug("Attribute info is: " + attrInfo);
    if (!attrInfo.isWritable())
        throw new AttributeNotFoundException(LocalizedStrings.MX4JModelMBean_ATTRIBUTE_0_IS_NOT_WRITABLE.toLocalizedString(attrName));
    // This returns a clone of the mbean descriptor, we use it read only
    Descriptor mbeanDescriptor = info.getMBeanDescriptor();
    if (mbeanDescriptor == null)
        throw new AttributeNotFoundException(LocalizedStrings.MX4JModelMBean_MBEAN_DESCRIPTOR_CANNOT_BE_NULL.toLocalizedString());
    if (logger.isEnabledFor(Logger.DEBUG))
        logger.debug("MBean descriptor is: " + mbeanDescriptor);
    // This descriptor is a clone
    Descriptor attributeDescriptor = attrInfo.getDescriptor();
    if (attributeDescriptor == null)
        throw new AttributeNotFoundException(LocalizedStrings.MX4JModelMBean_ATTRIBUTE_DESCRIPTOR_FOR_ATTRIBUTE_0_CANNOT_BE_NULL.toLocalizedString(attrName));
    if (logger.isEnabledFor(Logger.DEBUG))
        logger.debug("Attribute descriptor is: " + attributeDescriptor);
    String lastUpdateField = "lastUpdatedTimeStamp";
    Object oldValue = null;
    try {
        oldValue = getAttribute(attrName);
        if (logger.isEnabledFor(Logger.DEBUG))
            logger.debug("Previous value of attribute " + attrName + ": " + oldValue);
    } catch (Exception x) {
        if (logger.isEnabledFor(Logger.DEBUG))
            logger.debug("Cannot get previous value of attribute " + attrName, x);
    }
    // Check if setMethod is present
    String method = (String) attributeDescriptor.getFieldValue("setMethod");
    if (logger.isEnabledFor(Logger.DEBUG))
        logger.debug("setMethod field is: " + method);
    if (method != null) {
        Class declared = loadClassWithContextClassLoader(attrInfo.getType());
        if (attrValue != null) {
            Class parameter = attrValue.getClass();
            checkAssignability(parameter, declared);
        }
        // As an extension, allow attributes to be called on target objects also
        Object target = resolveTargetObject(attributeDescriptor);
        invokeMethod(target, method, new Class[] { declared }, new Object[] { attrValue });
        // Cache the value only if currencyTimeLimit is not 0, ie it is not always stale
        int staleness = getStaleness(attributeDescriptor, mbeanDescriptor, lastUpdateField);
        if (staleness != ALWAYS_STALE) {
            attributeDescriptor.setField("value", attrValue);
            attributeDescriptor.setField(lastUpdateField, Long.valueOf(System.currentTimeMillis()));
            if (logger.isEnabledFor(Logger.TRACE))
                logger.trace("Attribute's value has been cached");
        } else {
            if (logger.isEnabledFor(Logger.TRACE))
                logger.trace("Always stale, avoiding to cache attribute's value");
        }
    } else {
        if (attrValue != null) {
            Class parameter = attrValue.getClass();
            Class declared = loadClassWithContextClassLoader(attrInfo.getType());
            checkAssignability(parameter, declared);
        }
        // Always store the value in the descriptor: no setMethod
        attributeDescriptor.setField("value", attrValue);
    }
    // And now replace the descriptor with the updated clone
    info.setDescriptor(attributeDescriptor, "attribute");
    // Send notifications to listeners
    if (logger.isEnabledFor(Logger.TRACE))
        logger.trace("Sending attribute change notifications");
    sendAttributeChangeNotification(new Attribute(attrName, oldValue), attribute);
    // Persist this ModelMBean
    boolean persistNow = shouldPersistNow(attributeDescriptor, mbeanDescriptor, lastUpdateField);
    if (persistNow) {
        if (logger.isEnabledFor(Logger.TRACE))
            logger.trace("Persisting this ModelMBean...");
        try {
            store();
            if (logger.isEnabledFor(Logger.TRACE))
                logger.trace("ModelMBean persisted successfully");
        } catch (Exception x) {
            logger.error(LocalizedStrings.MX4JModelMBean_CANNOT_STORE_MODELMBEAN_AFTER_SETATTRIBUTE, x);
            if (x instanceof MBeanException)
                throw (MBeanException) x;
            else
                throw new MBeanException(x);
        }
    }
}
Also used : AttributeNotFoundException(javax.management.AttributeNotFoundException) Attribute(javax.management.Attribute) Logger(mx4j.log.Logger) FileLogger(mx4j.log.FileLogger) MBeanLogger(mx4j.log.MBeanLogger) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) AttributeNotFoundException(javax.management.AttributeNotFoundException) ServiceNotFoundException(javax.management.ServiceNotFoundException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) InvalidTargetObjectTypeException(javax.management.modelmbean.InvalidTargetObjectTypeException) RuntimeErrorException(javax.management.RuntimeErrorException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MalformedObjectNameException(javax.management.MalformedObjectNameException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) ListenerNotFoundException(javax.management.ListenerNotFoundException) ImplementationException(mx4j.ImplementationException) RuntimeOperationsException(javax.management.RuntimeOperationsException) ModelMBeanAttributeInfo(javax.management.modelmbean.ModelMBeanAttributeInfo) Descriptor(javax.management.Descriptor) MBeanException(javax.management.MBeanException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Aggregations

AttributeNotFoundException (javax.management.AttributeNotFoundException)78 ReflectionException (javax.management.ReflectionException)57 MBeanException (javax.management.MBeanException)53 InstanceNotFoundException (javax.management.InstanceNotFoundException)40 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)31 Attribute (javax.management.Attribute)25 ObjectName (javax.management.ObjectName)24 RuntimeOperationsException (javax.management.RuntimeOperationsException)16 IntrospectionException (javax.management.IntrospectionException)13 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)13 Method (java.lang.reflect.Method)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)11 AttributeList (javax.management.AttributeList)11 MalformedObjectNameException (javax.management.MalformedObjectNameException)11 Test (org.testng.annotations.Test)9 MBeanInfo (javax.management.MBeanInfo)8 ListenerNotFoundException (javax.management.ListenerNotFoundException)7 RuntimeErrorException (javax.management.RuntimeErrorException)7 RuntimeMBeanException (javax.management.RuntimeMBeanException)7 InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)7