Search in sources :

Example 31 with MBeanException

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

the class MBeanJMXAdapter method isAttributeAvailable.

public static boolean isAttributeAvailable(String attributeName, String objectName) {
    try {
        ObjectName objName = new ObjectName(objectName);
        mbeanServer.getAttribute(objName, attributeName);
    } catch (MalformedObjectNameException e) {
        return false;
    } catch (NullPointerException e) {
        return false;
    } catch (AttributeNotFoundException e) {
        return false;
    } catch (InstanceNotFoundException e) {
        return false;
    } catch (MBeanException e) {
        return false;
    } catch (ReflectionException e) {
        return false;
    }
    return true;
}
Also used : ReflectionException(javax.management.ReflectionException) MalformedObjectNameException(javax.management.MalformedObjectNameException) AttributeNotFoundException(javax.management.AttributeNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) ObjectName(javax.management.ObjectName)

Example 32 with MBeanException

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

the class ManagementFunction method execute.

/**
   * Actual function execution. It delegates task at managed node according to the request received.
   * 
   * If any exception is encountered it will set the result to UNDEFINED
   */
public void execute(FunctionContext fc) {
    boolean executedSuccessfully = false;
    InternalCache cache = GemFireCacheImpl.getInstance();
    Object[] functionArguments = (Object[]) fc.getArguments();
    ObjectName objectName = (ObjectName) functionArguments[0];
    String methodName = (String) functionArguments[1];
    String[] signature = (String[]) functionArguments[2];
    Object[] args = (Object[]) functionArguments[3];
    String memberName = (String) functionArguments[4];
    Object returnObj = null;
    try {
        final int nargs = (args == null) ? 0 : args.length;
        if (methodName.startsWith("set") && methodName.length() > 3 && nargs == 1) {
            Attribute attr = new Attribute(methodName.substring(3), args[0]);
            mbeanServer.setAttribute(objectName, attr);
            fc.getResultSender().lastResult((Serializable) null);
        } else if (methodName.equals("addNotificationListener")) {
            notificationHub.addHubNotificationListener(memberName, objectName);
            fc.getResultSender().lastResult((Serializable) ManagementConstants.UNDEFINED);
        } else if (methodName.equals("removeNotificationListener")) {
            notificationHub.removeHubNotificationListener(memberName, objectName);
            fc.getResultSender().lastResult((Serializable) ManagementConstants.UNDEFINED);
        } else if (methodName.equals("getNotificationInfo")) {
            fc.getResultSender().lastResult(mbeanServer.getMBeanInfo(objectName));
        } else {
            returnObj = mbeanServer.invoke(objectName, methodName, args, signature);
            fc.getResultSender().lastResult((Serializable) returnObj);
        }
        executedSuccessfully = true;
    } catch (InstanceNotFoundException e) {
        if (cache != null && !cache.isClosed()) {
            sendException(e, fc);
        }
    } catch (ReflectionException e) {
        sendException(e, fc);
    } catch (MBeanException e) {
        sendException(e, fc);
    } catch (NullPointerException e) {
        sendException(e, fc);
    } catch (Exception e) {
        sendException(e, fc);
    } finally {
        if (!executedSuccessfully) {
            if (cache == null || (cache != null && cache.isClosed())) {
                Exception e = new Exception(ManagementStrings.MEMBER_IS_SHUTTING_DOWN.toLocalizedString());
                sendException(e, fc);
                // member is closing or invalid member
                return;
            }
        }
    }
}
Also used : ReflectionException(javax.management.ReflectionException) Serializable(java.io.Serializable) Attribute(javax.management.Attribute) InstanceNotFoundException(javax.management.InstanceNotFoundException) InternalCache(org.apache.geode.internal.cache.InternalCache) MBeanException(javax.management.MBeanException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) ObjectName(javax.management.ObjectName) MBeanException(javax.management.MBeanException)

Example 33 with MBeanException

use of javax.management.MBeanException in project deltaspike by apache.

the class DynamicMBeanWrapper method invoke.

@Override
public Object invoke(final String actionName, final Object[] params, final String[] signature) throws MBeanException, ReflectionException {
    if (operations.containsKey(actionName)) {
        final ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(classloader);
        try {
            final Operation operation = operations.get(actionName);
            final Object result = operation.getOperation().invoke(instance(), params);
            return operation.isPresentAsTabularIfPossible() ? toResult(actionName, result) : result;
        } catch (InvocationTargetException e) {
            final Throwable cause = e.getCause();
            if (cause instanceof Error) {
                throw (Error) cause;
            }
            if (cause instanceof MBeanException) {
                throw (MBeanException) cause;
            }
            throw new MBeanException((Exception) cause, actionName + " failed with exception");
        } catch (IllegalAccessException e) {
            throw new ReflectionException(e, actionName + " could not be invoked");
        } catch (IllegalArgumentException e) {
            throw new ReflectionException(e, actionName + " could not be invoked");
        } finally {
            Thread.currentThread().setContextClassLoader(oldCl);
        }
    }
    throw new ReflectionException(new NoSuchMethodException(actionName + " doesn't exist"));
}
Also used : ReflectionException(javax.management.ReflectionException) MBeanException(javax.management.MBeanException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ReflectionException(javax.management.ReflectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) OpenDataException(javax.management.openmbean.OpenDataException) AttributeNotFoundException(javax.management.AttributeNotFoundException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException)

Example 34 with MBeanException

use of javax.management.MBeanException 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 35 with MBeanException

use of javax.management.MBeanException 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)

Aggregations

MBeanException (javax.management.MBeanException)105 ReflectionException (javax.management.ReflectionException)50 InstanceNotFoundException (javax.management.InstanceNotFoundException)41 AttributeNotFoundException (javax.management.AttributeNotFoundException)35 ObjectName (javax.management.ObjectName)32 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)31 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)26 MalformedObjectNameException (javax.management.MalformedObjectNameException)19 InvocationTargetException (java.lang.reflect.InvocationTargetException)18 RuntimeOperationsException (javax.management.RuntimeOperationsException)18 ServiceNotFoundException (javax.management.ServiceNotFoundException)17 Attribute (javax.management.Attribute)14 RuntimeErrorException (javax.management.RuntimeErrorException)14 Method (java.lang.reflect.Method)10 DynamicMBean (javax.management.DynamicMBean)10 ListenerNotFoundException (javax.management.ListenerNotFoundException)10 Descriptor (javax.management.Descriptor)9 InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)8 MalformedURLException (java.net.MalformedURLException)7 MBeanRegistrationException (javax.management.MBeanRegistrationException)7