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