Search in sources :

Example 66 with Attribute

use of javax.management.Attribute 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 67 with Attribute

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

the class MBeanSupport method setAttributes.

public final AttributeList setAttributes(AttributeList attributes) {
    final AttributeList result = new AttributeList(attributes.size());
    for (Object attrObj : attributes) {
        // We can't use AttributeList.asList because it has side-effects
        Attribute attr = (Attribute) attrObj;
        try {
            setAttribute(attr);
            result.add(new Attribute(attr.getName(), attr.getValue()));
        } catch (Exception e) {
        // OK: attribute is not included in returned list, per spec
        // XXX: log the exception
        }
    }
    return result;
}
Also used : Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) AttributeNotFoundException(javax.management.AttributeNotFoundException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) ReflectionException(javax.management.ReflectionException)

Example 68 with Attribute

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

the class MBeanSupport method getAttributes.

public final AttributeList getAttributes(String[] attributes) {
    final AttributeList result = new AttributeList(attributes.length);
    for (String attrName : attributes) {
        try {
            final Object attrValue = getAttribute(attrName);
            result.add(new Attribute(attrName, attrValue));
        } catch (Exception e) {
        // OK: attribute is not included in returned list, per spec
        // XXX: log the exception
        }
    }
    return result;
}
Also used : Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) AttributeNotFoundException(javax.management.AttributeNotFoundException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) ReflectionException(javax.management.ReflectionException)

Example 69 with Attribute

use of javax.management.Attribute in project tomee by apache.

the class DynamicMBeanWrapper method setAttributes.

@Override
public AttributeList setAttributes(final AttributeList attributes) {
    final AttributeList list = new AttributeList();
    for (final Object o : attributes) {
        final Attribute attr = (Attribute) o;
        try {
            setAttribute(attr);
            list.add(attr);
        } catch (final Exception ignore) {
        // no-op
        }
    }
    return list;
}
Also used : ManagedAttribute(org.apache.openejb.api.jmx.ManagedAttribute) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) AttributeNotFoundException(javax.management.AttributeNotFoundException) IntrospectionException(javax.management.IntrospectionException) ReflectionException(javax.management.ReflectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException)

Example 70 with Attribute

use of javax.management.Attribute in project tomee by apache.

the class MBeanDeployerTest method mbeans.

@Test
public void mbeans() throws Exception {
    final Set<String> parsed = new HashSet<String>();
    for (final Object name : appInfo.jmx.values()) {
        final ObjectName on = new ObjectName((String) name);
        final String cn = on.getCanonicalName();
        if (cn.contains("name=Empty")) {
            assertTrue(cn.startsWith("openejb.user.mbeans"));
            assertTrue(cn.contains("group=org.apache.openejb.mbeans"));
            assertTrue(cn.contains("application=mbeans") || cn.contains("application=EjbModule"));
            assertTrue(server.isRegistered(on));
            parsed.add(cn);
        } else if (cn.contains("name=Reader")) {
            assertTrue(cn.startsWith("openejb.user.mbeans"));
            assertTrue(cn.contains("group=org.apache.openejb.mbeans"));
            assertTrue(cn.contains("application=mbeans") || cn.contains("application=EjbModule"));
            assertTrue(server.isRegistered(on));
            assertEquals(2, server.getAttribute(on, "value"));
            parsed.add(cn);
        } else if (cn.contains("name=ReaderWriter")) {
            assertTrue(cn.contains("group=org.apache.openejb.mbeans"));
            assertTrue(cn.contains("application=mbeans") || cn.contains("application=EjbModule"));
            assertTrue(server.isRegistered(on));
            assertEquals(2, server.getAttribute(on, "value"));
            server.setAttribute(on, new Attribute("value", 5));
            assertEquals(5, server.getAttribute(on, "value"));
            parsed.add(cn);
        } else if (cn.contains("name=Inheritance")) {
            assertTrue(cn.startsWith("openejb.user.mbeans"));
            assertTrue(cn.contains("group=org.apache.openejb.mbeans"));
            assertTrue(cn.contains("application=mbeans") || cn.contains("application=EjbModule"));
            assertTrue(server.isRegistered(on));
            assertEquals(2, server.getAttribute(on, "value"));
            server.setAttribute(on, new Attribute("value", 5));
            assertEquals(5, server.getAttribute(on, "value"));
            assertEquals("yes - no", server.invoke(on, "returnValue", null, null));
            parsed.add(cn);
        } else if (cn.contains("name=MBeanDescription")) {
            assertTrue(cn.startsWith("openejb.user.mbeans"));
            assertTrue(cn.contains("group=org.apache.openejb.mbeans"));
            assertTrue(cn.contains("application=mbeans") || cn.contains("application=EjbModule"));
            assertTrue(server.isRegistered(on));
            assertEquals("descr ;)", server.getMBeanInfo(on).getDescription());
            parsed.add(cn);
        } else if (cn.contains("name=Operation")) {
            assertTrue(cn.startsWith("openejb.user.mbeans"));
            assertTrue(cn.contains("group=org.apache.openejb.mbeans"));
            assertTrue(cn.contains("application=mbeans") || cn.contains("application=EjbModule"));
            final MBeanInfo info = server.getMBeanInfo(on);
            if ("desc".equals(info.getOperations()[0].getName())) {
                assertEquals("param", info.getOperations()[0].getSignature()[0].getDescription());
            } else {
                assertEquals("param", info.getOperations()[1].getSignature()[0].getDescription());
            }
            assertTrue(server.isRegistered(on));
            assertEquals("yes - no", server.invoke(on, "returnValue", null, null));
            parsed.add(cn);
        } else if (cn.contains("name=ReaderDescription")) {
            assertTrue(cn.startsWith("openejb.user.mbeans"));
            assertTrue(cn.contains("group=org.apache.openejb.mbeans"));
            assertTrue(cn.contains("application=mbeans") || cn.contains("application=EjbModule"));
            assertTrue(cn.contains("name=ReaderDescription"));
            assertTrue(server.isRegistered(on));
            assertEquals(1, server.getMBeanInfo(on).getAttributes().length);
            assertEquals("just a value", server.getMBeanInfo(on).getAttributes()[0].getDescription());
            parsed.add(cn);
        } else if (cn.contains("name=OperationDescription")) {
            assertTrue(cn.startsWith("openejb.user.mbeans"));
            assertTrue(cn.contains("group=org.apache.openejb.mbeans"));
            assertTrue(cn.contains("application=mbeans") || cn.contains("application=EjbModule"));
            assertTrue(server.isRegistered(on));
            assertEquals(1, server.getMBeanInfo(on).getOperations().length);
            assertEquals("just an op", server.getMBeanInfo(on).getOperations()[0].getDescription());
            parsed.add(cn);
        }
    }
    assertEquals(8, parsed.size());
}
Also used : MBeanInfo(javax.management.MBeanInfo) Attribute(javax.management.Attribute) HashSet(java.util.HashSet) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

Attribute (javax.management.Attribute)157 ObjectName (javax.management.ObjectName)94 MBeanServer (javax.management.MBeanServer)56 AttributeList (javax.management.AttributeList)46 Test (org.junit.Test)38 ReflectionException (javax.management.ReflectionException)29 MBeanException (javax.management.MBeanException)25 HashMap (java.util.HashMap)23 InstanceNotFoundException (javax.management.InstanceNotFoundException)22 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)21 AttributeNotFoundException (javax.management.AttributeNotFoundException)20 MBeanServerConnection (javax.management.MBeanServerConnection)15 MBeanInfo (javax.management.MBeanInfo)14 JMXConnector (javax.management.remote.JMXConnector)13 RuntimeOperationsException (javax.management.RuntimeOperationsException)12 List (java.util.List)10 BacklogTracerEventMessage (org.apache.camel.api.management.mbean.BacklogTracerEventMessage)10 IOException (java.io.IOException)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 ArrayList (java.util.ArrayList)9