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);
}
}
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);
}
}
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);
}
}
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);
}
}
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;
}
Aggregations