Search in sources :

Example 56 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project com.revolsys.open by revolsys.

the class JmxService method getAttribute.

/**
 * Get the value for the attribute for an object on a server.
 *
 * @param mapWriter The writer to write the attributes to.
 * @param serverId The name of the server.
 * @param objectId The name of the object.
 * @param attributeId The name of the attribute.
 * @return The attribute value.
 */
public Object getAttribute(final String serverId, final String objectId, final String attributeId) {
    if (hasAttribute(serverId, objectId, attributeId)) {
        final MBeanServerConnection connection = getConnection(serverId);
        try {
            final ObjectName objectName = getObjectName(serverId, objectId);
            final Object object = connection.getAttribute(objectName, attributeId);
            return object;
        } catch (final InstanceNotFoundException e) {
            return "Unavailable";
        } catch (final MalformedObjectNameException e) {
            throw new IllegalArgumentException("MBean name not valid " + serverId + " " + objectId);
        } catch (final AttributeNotFoundException e) {
            throw new IllegalArgumentException("MBean attribute not found " + serverId + " " + objectId + "." + attributeId);
        } catch (final Throwable e) {
            return Exceptions.throwUncheckedException(e);
        }
    } else {
        throw new IllegalArgumentException("Attribute not configured " + serverId + " " + objectId + "." + attributeId);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) AttributeNotFoundException(javax.management.AttributeNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName)

Example 57 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project com.revolsys.open by revolsys.

the class JmxService method getAttributes.

/**
 * Get the values for all attributes for an object on a server.
 *
 * @param serverId The name of the server.
 * @param objectId The name of the object.
 * @return The attribute values.
 */
public List<FieldDefinition> getAttributes(final String serverId, final String objectId) {
    final MBeanServerConnection connection = getConnection(serverId);
    try {
        final String[] attributeNames = getAttributeNames(serverId, objectId).toArray(new String[0]);
        final ObjectName objectName = getObjectName(serverId, objectId);
        final List<FieldDefinition> attributeValues = new ArrayList<>();
        for (final Object attribute : connection.getAttributes(objectName, attributeNames)) {
            attributeValues.add((FieldDefinition) attribute);
        }
        return attributeValues;
    } catch (final InstanceNotFoundException e) {
        throw new IllegalArgumentException("MBean not found " + serverId + " " + objectId);
    } catch (final MalformedObjectNameException e) {
        throw new IllegalArgumentException("MBean name not valid " + serverId + " " + objectId);
    } catch (final Throwable e) {
        return Exceptions.throwUncheckedException(e);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) FieldDefinition(com.revolsys.record.schema.FieldDefinition) InstanceNotFoundException(javax.management.InstanceNotFoundException) ArrayList(java.util.ArrayList) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName)

Example 58 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project com.revolsys.open by revolsys.

the class JmxService method invokeOperation.

/**
 * Invoke the operation with the specified parameters.
 *
 * @param serverId The name of the server.
 * @param objectId The name of the object.
 * @param operationId The name of the operation.
 * @param parameters The parameters to pass to the operation.
 * @return The result of executing the operation.
 */
public Object invokeOperation(final String serverId, final String objectId, final String operationId, final Map<String, String> parameters) {
    try {
        final MBeanOperationInfo operation = getOperation(serverId, objectId, operationId);
        final MBeanServerConnection connection = getConnection(serverId);
        final ObjectName objectName = getObjectName(serverId, objectId);
        final MBeanParameterInfo[] parameterInfos = operation.getSignature();
        final String[] signature = new String[parameterInfos.length];
        final Object[] values = new Object[parameterInfos.length];
        for (int i = 0; i < parameterInfos.length; i++) {
            final MBeanParameterInfo parameterInfo = parameterInfos[i];
            final String name = parameterInfo.getName();
            final String type = parameterInfo.getType();
            signature[i] = type;
            values[i] = parameters.get(name);
        }
        return connection.invoke(objectName, operation.getName(), values, signature);
    } catch (final InstanceNotFoundException e) {
        throw new IllegalArgumentException("MBean not found " + serverId + " " + objectId);
    } catch (final MalformedObjectNameException e) {
        throw new IllegalArgumentException("MBean name not valid " + serverId + " " + objectId);
    } catch (final Throwable e) {
        return Exceptions.throwUncheckedException(e);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanOperationInfo(javax.management.MBeanOperationInfo) InstanceNotFoundException(javax.management.InstanceNotFoundException) ObjectName(javax.management.ObjectName) MBeanServerConnection(javax.management.MBeanServerConnection) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 59 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project com.revolsys.open by revolsys.

the class JmxService method getOperations.

/**
 * Get the description for all operations for an object on a server.
 *
 * @param serverId The name of the server.
 * @param objectId The name of the object.
 * @return The operations values.
 */
public List<MBeanOperationInfo> getOperations(final String serverId, final String objectId) {
    final MBeanServerConnection connection = getConnection(serverId);
    try {
        final ObjectName objectName = getObjectName(serverId, objectId);
        final List<String> operationNames = getOperationNames(serverId, objectId);
        final MBeanInfo beanInfo = connection.getMBeanInfo(objectName);
        final List<MBeanOperationInfo> operations = new ArrayList<>();
        for (final MBeanOperationInfo operation : beanInfo.getOperations()) {
            final String name = operation.getName();
            if (operationNames.contains(name)) {
                operations.add(operation);
            }
        }
        return operations;
    } catch (final InstanceNotFoundException e) {
        throw new IllegalArgumentException("MBean not found " + serverId + " " + objectId);
    } catch (final MalformedObjectNameException e) {
        throw new IllegalArgumentException("MBean name not valid " + serverId + " " + objectId);
    } catch (final Throwable e) {
        return Exceptions.throwUncheckedException(e);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) InstanceNotFoundException(javax.management.InstanceNotFoundException) ArrayList(java.util.ArrayList) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName)

Example 60 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project com.revolsys.open by revolsys.

the class JmxUtil method getMBeanAttribute.

public static MBeanAttributeInfo getMBeanAttribute(final MBeanServerConnection connection, final String nameString, final String attributeName) {
    MBeanAttributeInfo attribute = null;
    ObjectName objectName;
    try {
        objectName = new ObjectName(nameString);
        MBeanInfo mBeanInfo;
        mBeanInfo = connection.getMBeanInfo(objectName);
        final MBeanAttributeInfo[] attributes = mBeanInfo.getAttributes();
        for (final MBeanAttributeInfo thisAttribute : attributes) {
            if (thisAttribute.getName().equals(attributeName)) {
                attribute = thisAttribute;
                break;
            }
        }
    } catch (final InstanceNotFoundException e) {
        e.printStackTrace();
    } catch (final IntrospectionException e) {
        e.printStackTrace();
    } catch (final ReflectionException e) {
        e.printStackTrace();
    } catch (final IOException e) {
        e.printStackTrace();
    } catch (final MalformedObjectNameException e) {
        e.printStackTrace();
    } catch (final NullPointerException e) {
        e.printStackTrace();
    }
    return attribute;
}
Also used : ReflectionException(javax.management.ReflectionException) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanInfo(javax.management.MBeanInfo) InstanceNotFoundException(javax.management.InstanceNotFoundException) IntrospectionException(javax.management.IntrospectionException) IOException(java.io.IOException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName)

Aggregations

MalformedObjectNameException (javax.management.MalformedObjectNameException)309 ObjectName (javax.management.ObjectName)285 InstanceNotFoundException (javax.management.InstanceNotFoundException)88 MBeanServer (javax.management.MBeanServer)80 MBeanRegistrationException (javax.management.MBeanRegistrationException)75 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)63 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)59 IOException (java.io.IOException)53 ArrayList (java.util.ArrayList)45 ReflectionException (javax.management.ReflectionException)30 MBeanException (javax.management.MBeanException)23 Test (org.testng.annotations.Test)23 CompositeData (javax.management.openmbean.CompositeData)18 Notification (javax.management.Notification)15 MBeanInfo (javax.management.MBeanInfo)14 AttributeNotFoundException (javax.management.AttributeNotFoundException)13 HashMap (java.util.HashMap)11 Map (java.util.Map)11 IntrospectionException (javax.management.IntrospectionException)11 MalformedURLException (java.net.MalformedURLException)10