下面列出了javax.management.InstanceNotFoundException#getMessage ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Retrieves role value for given role name in given relation.
*
* @param relationId relation id
* @param roleName name of role
*
* @return the ArrayList of ObjectName objects being the role value
*
* @exception RelationServiceNotRegisteredException if the Relation
* Service is not registered
* @exception IllegalArgumentException if null parameter
* @exception RelationNotFoundException if no relation with given id
* @exception RoleNotFoundException if:
* <P>- there is no role with given name
* <P>or
* <P>- the role is not readable.
*
* @see #setRole
*/
public List<ObjectName> getRole(String relationId,
String roleName)
throws RelationServiceNotRegisteredException,
IllegalArgumentException,
RelationNotFoundException,
RoleNotFoundException {
if (relationId == null || roleName == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"getRole", new Object[] {relationId, roleName});
// Can throw RelationServiceNotRegisteredException
isActive();
// Can throw a RelationNotFoundException
Object relObj = getRelation(relationId);
List<ObjectName> result;
if (relObj instanceof RelationSupport) {
// Internal relation
// Can throw RoleNotFoundException
result = cast(
((RelationSupport)relObj).getRoleInt(roleName,
true,
this,
false));
} else {
// Relation MBean
Object[] params = new Object[1];
params[0] = roleName;
String[] signature = new String[1];
signature[0] = "java.lang.String";
// Can throw MBeanException wrapping a RoleNotFoundException:
// throw wrapped exception
//
// Shall not throw InstanceNotFoundException or ReflectionException
try {
List<ObjectName> invokeResult = cast(
myMBeanServer.invoke(((ObjectName)relObj),
"getRole",
params,
signature));
if (invokeResult == null || invokeResult instanceof ArrayList<?>)
result = invokeResult;
else
result = new ArrayList<ObjectName>(invokeResult);
} catch (InstanceNotFoundException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (ReflectionException exc2) {
throw new RuntimeException(exc2.getMessage());
} catch (MBeanException exc3) {
Exception wrappedExc = exc3.getTargetException();
if (wrappedExc instanceof RoleNotFoundException) {
throw ((RoleNotFoundException)wrappedExc);
} else {
throw new RuntimeException(wrappedExc.getMessage());
}
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(), "getRole");
return result;
}
/**
* Retrieves values of roles with given names in given relation.
*
* @param relationId relation id
* @param roleNameArray array of names of roles to be retrieved
*
* @return a RoleResult object, including a RoleList (for roles
* successfully retrieved) and a RoleUnresolvedList (for roles not
* retrieved).
*
* @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
*
* @see #setRoles
*/
public RoleResult getRoles(String relationId,
String[] roleNameArray)
throws RelationServiceNotRegisteredException,
IllegalArgumentException,
RelationNotFoundException {
if (relationId == null || roleNameArray == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"getRoles", relationId);
// Can throw RelationServiceNotRegisteredException
isActive();
// Can throw a RelationNotFoundException
Object relObj = getRelation(relationId);
RoleResult result;
if (relObj instanceof RelationSupport) {
// Internal relation
result = ((RelationSupport)relObj).getRolesInt(roleNameArray,
true,
this);
} else {
// Relation MBean
Object[] params = new Object[1];
params[0] = roleNameArray;
String[] signature = new String[1];
try {
signature[0] = (roleNameArray.getClass()).getName();
} catch (Exception exc) {
// OK : This is an array of java.lang.String
// so this should never happen...
}
// Shall not throw InstanceNotFoundException, ReflectionException
// or MBeanException
try {
result = (RoleResult)
(myMBeanServer.invoke(((ObjectName)relObj),
"getRoles",
params,
signature));
} catch (InstanceNotFoundException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (ReflectionException exc2) {
throw new RuntimeException(exc2.getMessage());
} catch (MBeanException exc3) {
throw new
RuntimeException((exc3.getTargetException()).getMessage());
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(), "getRoles");
return result;
}
/**
* Retrieves the number of MBeans currently referenced in the given role.
*
* @param relationId relation id
* @param roleName name of role
*
* @return the number of currently referenced MBeans in that role
*
* @exception IllegalArgumentException if null parameter
* @exception RelationNotFoundException if no relation with given id
* @exception RoleNotFoundException if there is no role with given name
*/
public Integer getRoleCardinality(String relationId,
String roleName)
throws IllegalArgumentException,
RelationNotFoundException,
RoleNotFoundException {
if (relationId == null || roleName == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"getRoleCardinality", new Object[] {relationId, roleName});
// Can throw a RelationNotFoundException
Object relObj = getRelation(relationId);
Integer result;
if (relObj instanceof RelationSupport) {
// Internal relation
// Can throw RoleNotFoundException
result = ((RelationSupport)relObj).getRoleCardinality(roleName);
} else {
// Relation MBean
Object[] params = new Object[1];
params[0] = roleName;
String[] signature = new String[1];
signature[0] = "java.lang.String";
// Can throw MBeanException wrapping RoleNotFoundException:
// throw wrapped exception
//
// Shall not throw InstanceNotFoundException or ReflectionException
try {
result = (Integer)
(myMBeanServer.invoke(((ObjectName)relObj),
"getRoleCardinality",
params,
signature));
} catch (InstanceNotFoundException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (ReflectionException exc2) {
throw new RuntimeException(exc2.getMessage());
} catch (MBeanException exc3) {
Exception wrappedExc = exc3.getTargetException();
if (wrappedExc instanceof RoleNotFoundException) {
throw ((RoleNotFoundException)wrappedExc);
} else {
throw new RuntimeException(wrappedExc.getMessage());
}
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(),
"getRoleCardinality");
return result;
}
/**
* Sets the given roles in given relation.
* <P>Will check the role according to its corresponding role definition
* provided in relation's relation type
* <P>The Relation Service keeps track of the changes to keep the
* consistency of relations by handling referenced MBean deregistrations.
*
* @param relationId relation id
* @param roleList list of roles to be set
*
* @return a RoleResult object, including a RoleList (for roles
* successfully set) and a RoleUnresolvedList (for roles not
* set).
*
* @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
*
* @see #getRoles
*/
public RoleResult setRoles(String relationId,
RoleList roleList)
throws RelationServiceNotRegisteredException,
IllegalArgumentException,
RelationNotFoundException {
if (relationId == null || roleList == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"setRoles", new Object[] {relationId, roleList});
// Can throw RelationServiceNotRegisteredException
isActive();
// Can throw a RelationNotFoundException
Object relObj = getRelation(relationId);
RoleResult result;
if (relObj instanceof RelationSupport) {
// Internal relation
// Can throw RelationServiceNotRegisteredException
//
// Shall not throw RelationTypeNotFoundException (as relation is
// known, its relation type exists)
try {
result = ((RelationSupport)relObj).setRolesInt(roleList,
true,
this);
} catch (RelationTypeNotFoundException exc) {
throw new RuntimeException(exc.getMessage());
}
} else {
// Relation MBean
Object[] params = new Object[1];
params[0] = roleList;
String[] signature = new String[1];
signature[0] = "javax.management.relation.RoleList";
// Shall not throw InstanceNotFoundException or an MBeanException
// or ReflectionException
try {
result = (RoleResult)
(myMBeanServer.invoke(((ObjectName)relObj),
"setRoles",
params,
signature));
} catch (InstanceNotFoundException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (ReflectionException exc3) {
throw new RuntimeException(exc3.getMessage());
} catch (MBeanException exc2) {
throw new
RuntimeException((exc2.getTargetException()).getMessage());
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(), "setRoles");
return result;
}
private void updateUnregistrationListener(List<ObjectName> newRefList,
List<ObjectName> obsoleteRefList)
throws RelationServiceNotRegisteredException {
if (newRefList != null && obsoleteRefList != null) {
if (newRefList.isEmpty() && obsoleteRefList.isEmpty()) {
// Nothing to do :)
return;
}
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"updateUnregistrationListener",
new Object[] {newRefList, obsoleteRefList});
// Can throw RelationServiceNotRegisteredException
isActive();
if (newRefList != null || obsoleteRefList != null) {
boolean newListenerFlag = false;
if (myUnregNtfFilter == null) {
// Initialize it to be able to synchronise it :)
myUnregNtfFilter = new MBeanServerNotificationFilter();
newListenerFlag = true;
}
synchronized(myUnregNtfFilter) {
// Enables ObjectNames in newRefList
if (newRefList != null) {
for (ObjectName newObjName : newRefList)
myUnregNtfFilter.enableObjectName(newObjName);
}
if (obsoleteRefList != null) {
// Disables ObjectNames in obsoleteRefList
for (ObjectName obsObjName : obsoleteRefList)
myUnregNtfFilter.disableObjectName(obsObjName);
}
// Under test
if (newListenerFlag) {
try {
myMBeanServer.addNotificationListener(
MBeanServerDelegate.DELEGATE_NAME,
this,
myUnregNtfFilter,
null);
} catch (InstanceNotFoundException exc) {
throw new
RelationServiceNotRegisteredException(exc.getMessage());
}
}
// End test
// if (!newListenerFlag) {
// The Relation Service was already registered as a
// listener:
// removes it
// Shall not throw InstanceNotFoundException (as the
// MBean Server Delegate is expected to exist) or
// ListenerNotFoundException (as it has been checked above
// that the Relation Service is registered)
// try {
// myMBeanServer.removeNotificationListener(
// MBeanServerDelegate.DELEGATE_NAME,
// this);
// } catch (InstanceNotFoundException exc1) {
// throw new RuntimeException(exc1.getMessage());
// } catch (ListenerNotFoundException exc2) {
// throw new
// RelationServiceNotRegisteredException(exc2.getMessage());
// }
// }
// Adds Relation Service with current filter
// Can throw InstanceNotFoundException if the Relation
// Service is not registered, to be transformed into
// RelationServiceNotRegisteredException
//
// Assume that there will not be any InstanceNotFoundException
// for the MBean Server Delegate :)
// try {
// myMBeanServer.addNotificationListener(
// MBeanServerDelegate.DELEGATE_NAME,
// this,
// myUnregNtfFilter,
// null);
// } catch (InstanceNotFoundException exc) {
// throw new
// RelationServiceNotRegisteredException(exc.getMessage());
// }
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(),
"updateUnregistrationListener");
return;
}
private void sendRoleUpdateNotification(Role newRole,
List<ObjectName> oldRoleValue,
boolean relationServCallFlg,
RelationService relationServ)
throws IllegalArgumentException,
RelationServiceNotRegisteredException,
RelationNotFoundException {
if (newRole == null ||
oldRoleValue == null ||
(relationServCallFlg && relationServ == null)) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationSupport.class.getName(),
"sendRoleUpdateNotification", new Object[] {newRole,
oldRoleValue, relationServCallFlg, relationServ});
if (relationServCallFlg) {
// Direct call to the Relation Service
// Shall not throw a RelationNotFoundException for an internal
// relation
try {
relationServ.sendRoleUpdateNotification(myRelId,
newRole,
oldRoleValue);
} catch (RelationNotFoundException exc) {
throw new RuntimeException(exc.getMessage());
}
} else {
Object[] params = new Object[3];
params[0] = myRelId;
params[1] = newRole;
params[2] = oldRoleValue;
String[] signature = new String[3];
signature[0] = "java.lang.String";
signature[1] = "javax.management.relation.Role";
signature[2] = "java.util.List";
// Can throw InstanceNotFoundException if the Relation Service
// is not registered (to be transformed).
//
// Can throw a MBeanException wrapping a
// RelationNotFoundException (to be raised in any case): wrapped
// exception to be thrown
//
// Shall not throw a ReflectionException
try {
myRelServiceMBeanServer.invoke(myRelServiceName,
"sendRoleUpdateNotification",
params,
signature);
} catch (ReflectionException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (InstanceNotFoundException exc2) {
throw new RelationServiceNotRegisteredException(
exc2.getMessage());
} catch (MBeanException exc3) {
Exception wrappedExc = exc3.getTargetException();
if (wrappedExc instanceof RelationNotFoundException) {
throw ((RelationNotFoundException)wrappedExc);
} else {
throw new RuntimeException(wrappedExc.getMessage());
}
}
}
RELATION_LOGGER.exiting(RelationSupport.class.getName(),
"sendRoleUpdateNotification");
return;
}
private void updateRelationServiceMap(Role newRole,
List<ObjectName> oldRoleValue,
boolean relationServCallFlg,
RelationService relationServ)
throws IllegalArgumentException,
RelationServiceNotRegisteredException,
RelationNotFoundException {
if (newRole == null ||
oldRoleValue == null ||
(relationServCallFlg && relationServ == null)) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationSupport.class.getName(),
"updateRelationServiceMap", new Object[] {newRole,
oldRoleValue, relationServCallFlg, relationServ});
if (relationServCallFlg) {
// Direct call to the Relation Service
// Shall not throw a RelationNotFoundException
try {
relationServ.updateRoleMap(myRelId,
newRole,
oldRoleValue);
} catch (RelationNotFoundException exc) {
throw new RuntimeException(exc.getMessage());
}
} else {
Object[] params = new Object[3];
params[0] = myRelId;
params[1] = newRole;
params[2] = oldRoleValue;
String[] signature = new String[3];
signature[0] = "java.lang.String";
signature[1] = "javax.management.relation.Role";
signature[2] = "java.util.List";
// Can throw InstanceNotFoundException if the Relation Service
// is not registered (to be transformed).
// Can throw a MBeanException wrapping a RelationNotFoundException:
// wrapped exception to be thrown
//
// Shall not throw a ReflectionException
try {
myRelServiceMBeanServer.invoke(myRelServiceName,
"updateRoleMap",
params,
signature);
} catch (ReflectionException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (InstanceNotFoundException exc2) {
throw new
RelationServiceNotRegisteredException(exc2.getMessage());
} catch (MBeanException exc3) {
Exception wrappedExc = exc3.getTargetException();
if (wrappedExc instanceof RelationNotFoundException) {
throw ((RelationNotFoundException)wrappedExc);
} else {
throw new RuntimeException(wrappedExc.getMessage());
}
}
}
RELATION_LOGGER.exiting(RelationSupport.class.getName(),
"updateRelationServiceMap");
return;
}
/**
* Retrieves role value for given role name in given relation.
*
* @param relationId relation id
* @param roleName name of role
*
* @return the ArrayList of ObjectName objects being the role value
*
* @exception RelationServiceNotRegisteredException if the Relation
* Service is not registered
* @exception IllegalArgumentException if null parameter
* @exception RelationNotFoundException if no relation with given id
* @exception RoleNotFoundException if:
* <P>- there is no role with given name
* <P>or
* <P>- the role is not readable.
*
* @see #setRole
*/
public List<ObjectName> getRole(String relationId,
String roleName)
throws RelationServiceNotRegisteredException,
IllegalArgumentException,
RelationNotFoundException,
RoleNotFoundException {
if (relationId == null || roleName == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"getRole", new Object[] {relationId, roleName});
// Can throw RelationServiceNotRegisteredException
isActive();
// Can throw a RelationNotFoundException
Object relObj = getRelation(relationId);
List<ObjectName> result;
if (relObj instanceof RelationSupport) {
// Internal relation
// Can throw RoleNotFoundException
result = cast(
((RelationSupport)relObj).getRoleInt(roleName,
true,
this,
false));
} else {
// Relation MBean
Object[] params = new Object[1];
params[0] = roleName;
String[] signature = new String[1];
signature[0] = "java.lang.String";
// Can throw MBeanException wrapping a RoleNotFoundException:
// throw wrapped exception
//
// Shall not throw InstanceNotFoundException or ReflectionException
try {
List<ObjectName> invokeResult = cast(
myMBeanServer.invoke(((ObjectName)relObj),
"getRole",
params,
signature));
if (invokeResult == null || invokeResult instanceof ArrayList<?>)
result = invokeResult;
else
result = new ArrayList<ObjectName>(invokeResult);
} catch (InstanceNotFoundException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (ReflectionException exc2) {
throw new RuntimeException(exc2.getMessage());
} catch (MBeanException exc3) {
Exception wrappedExc = exc3.getTargetException();
if (wrappedExc instanceof RoleNotFoundException) {
throw ((RoleNotFoundException)wrappedExc);
} else {
throw new RuntimeException(wrappedExc.getMessage());
}
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(), "getRole");
return result;
}
/**
* Retrieves values of roles with given names in given relation.
*
* @param relationId relation id
* @param roleNameArray array of names of roles to be retrieved
*
* @return a RoleResult object, including a RoleList (for roles
* successfully retrieved) and a RoleUnresolvedList (for roles not
* retrieved).
*
* @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
*
* @see #setRoles
*/
public RoleResult getRoles(String relationId,
String[] roleNameArray)
throws RelationServiceNotRegisteredException,
IllegalArgumentException,
RelationNotFoundException {
if (relationId == null || roleNameArray == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"getRoles", relationId);
// Can throw RelationServiceNotRegisteredException
isActive();
// Can throw a RelationNotFoundException
Object relObj = getRelation(relationId);
RoleResult result;
if (relObj instanceof RelationSupport) {
// Internal relation
result = ((RelationSupport)relObj).getRolesInt(roleNameArray,
true,
this);
} else {
// Relation MBean
Object[] params = new Object[1];
params[0] = roleNameArray;
String[] signature = new String[1];
try {
signature[0] = (roleNameArray.getClass()).getName();
} catch (Exception exc) {
// OK : This is an array of java.lang.String
// so this should never happen...
}
// Shall not throw InstanceNotFoundException, ReflectionException
// or MBeanException
try {
result = (RoleResult)
(myMBeanServer.invoke(((ObjectName)relObj),
"getRoles",
params,
signature));
} catch (InstanceNotFoundException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (ReflectionException exc2) {
throw new RuntimeException(exc2.getMessage());
} catch (MBeanException exc3) {
throw new
RuntimeException((exc3.getTargetException()).getMessage());
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(), "getRoles");
return result;
}
/**
* Retrieves the number of MBeans currently referenced in the given role.
*
* @param relationId relation id
* @param roleName name of role
*
* @return the number of currently referenced MBeans in that role
*
* @exception IllegalArgumentException if null parameter
* @exception RelationNotFoundException if no relation with given id
* @exception RoleNotFoundException if there is no role with given name
*/
public Integer getRoleCardinality(String relationId,
String roleName)
throws IllegalArgumentException,
RelationNotFoundException,
RoleNotFoundException {
if (relationId == null || roleName == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"getRoleCardinality", new Object[] {relationId, roleName});
// Can throw a RelationNotFoundException
Object relObj = getRelation(relationId);
Integer result;
if (relObj instanceof RelationSupport) {
// Internal relation
// Can throw RoleNotFoundException
result = ((RelationSupport)relObj).getRoleCardinality(roleName);
} else {
// Relation MBean
Object[] params = new Object[1];
params[0] = roleName;
String[] signature = new String[1];
signature[0] = "java.lang.String";
// Can throw MBeanException wrapping RoleNotFoundException:
// throw wrapped exception
//
// Shall not throw InstanceNotFoundException or ReflectionException
try {
result = (Integer)
(myMBeanServer.invoke(((ObjectName)relObj),
"getRoleCardinality",
params,
signature));
} catch (InstanceNotFoundException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (ReflectionException exc2) {
throw new RuntimeException(exc2.getMessage());
} catch (MBeanException exc3) {
Exception wrappedExc = exc3.getTargetException();
if (wrappedExc instanceof RoleNotFoundException) {
throw ((RoleNotFoundException)wrappedExc);
} else {
throw new RuntimeException(wrappedExc.getMessage());
}
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(),
"getRoleCardinality");
return result;
}
/**
* Sets the given roles in given relation.
* <P>Will check the role according to its corresponding role definition
* provided in relation's relation type
* <P>The Relation Service keeps track of the changes to keep the
* consistency of relations by handling referenced MBean deregistrations.
*
* @param relationId relation id
* @param roleList list of roles to be set
*
* @return a RoleResult object, including a RoleList (for roles
* successfully set) and a RoleUnresolvedList (for roles not
* set).
*
* @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
*
* @see #getRoles
*/
public RoleResult setRoles(String relationId,
RoleList roleList)
throws RelationServiceNotRegisteredException,
IllegalArgumentException,
RelationNotFoundException {
if (relationId == null || roleList == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"setRoles", new Object[] {relationId, roleList});
// Can throw RelationServiceNotRegisteredException
isActive();
// Can throw a RelationNotFoundException
Object relObj = getRelation(relationId);
RoleResult result;
if (relObj instanceof RelationSupport) {
// Internal relation
// Can throw RelationServiceNotRegisteredException
//
// Shall not throw RelationTypeNotFoundException (as relation is
// known, its relation type exists)
try {
result = ((RelationSupport)relObj).setRolesInt(roleList,
true,
this);
} catch (RelationTypeNotFoundException exc) {
throw new RuntimeException(exc.getMessage());
}
} else {
// Relation MBean
Object[] params = new Object[1];
params[0] = roleList;
String[] signature = new String[1];
signature[0] = "javax.management.relation.RoleList";
// Shall not throw InstanceNotFoundException or an MBeanException
// or ReflectionException
try {
result = (RoleResult)
(myMBeanServer.invoke(((ObjectName)relObj),
"setRoles",
params,
signature));
} catch (InstanceNotFoundException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (ReflectionException exc3) {
throw new RuntimeException(exc3.getMessage());
} catch (MBeanException exc2) {
throw new
RuntimeException((exc2.getTargetException()).getMessage());
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(), "setRoles");
return result;
}
private void updateUnregistrationListener(List<ObjectName> newRefList,
List<ObjectName> obsoleteRefList)
throws RelationServiceNotRegisteredException {
if (newRefList != null && obsoleteRefList != null) {
if (newRefList.isEmpty() && obsoleteRefList.isEmpty()) {
// Nothing to do :)
return;
}
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"updateUnregistrationListener",
new Object[] {newRefList, obsoleteRefList});
// Can throw RelationServiceNotRegisteredException
isActive();
if (newRefList != null || obsoleteRefList != null) {
boolean newListenerFlag = false;
if (myUnregNtfFilter == null) {
// Initialize it to be able to synchronise it :)
myUnregNtfFilter = new MBeanServerNotificationFilter();
newListenerFlag = true;
}
synchronized(myUnregNtfFilter) {
// Enables ObjectNames in newRefList
if (newRefList != null) {
for (ObjectName newObjName : newRefList)
myUnregNtfFilter.enableObjectName(newObjName);
}
if (obsoleteRefList != null) {
// Disables ObjectNames in obsoleteRefList
for (ObjectName obsObjName : obsoleteRefList)
myUnregNtfFilter.disableObjectName(obsObjName);
}
// Under test
if (newListenerFlag) {
try {
myMBeanServer.addNotificationListener(
MBeanServerDelegate.DELEGATE_NAME,
this,
myUnregNtfFilter,
null);
} catch (InstanceNotFoundException exc) {
throw new
RelationServiceNotRegisteredException(exc.getMessage());
}
}
// End test
// if (!newListenerFlag) {
// The Relation Service was already registered as a
// listener:
// removes it
// Shall not throw InstanceNotFoundException (as the
// MBean Server Delegate is expected to exist) or
// ListenerNotFoundException (as it has been checked above
// that the Relation Service is registered)
// try {
// myMBeanServer.removeNotificationListener(
// MBeanServerDelegate.DELEGATE_NAME,
// this);
// } catch (InstanceNotFoundException exc1) {
// throw new RuntimeException(exc1.getMessage());
// } catch (ListenerNotFoundException exc2) {
// throw new
// RelationServiceNotRegisteredException(exc2.getMessage());
// }
// }
// Adds Relation Service with current filter
// Can throw InstanceNotFoundException if the Relation
// Service is not registered, to be transformed into
// RelationServiceNotRegisteredException
//
// Assume that there will not be any InstanceNotFoundException
// for the MBean Server Delegate :)
// try {
// myMBeanServer.addNotificationListener(
// MBeanServerDelegate.DELEGATE_NAME,
// this,
// myUnregNtfFilter,
// null);
// } catch (InstanceNotFoundException exc) {
// throw new
// RelationServiceNotRegisteredException(exc.getMessage());
// }
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(),
"updateUnregistrationListener");
return;
}
private void sendRoleUpdateNotification(Role newRole,
List<ObjectName> oldRoleValue,
boolean relationServCallFlg,
RelationService relationServ)
throws IllegalArgumentException,
RelationServiceNotRegisteredException,
RelationNotFoundException {
if (newRole == null ||
oldRoleValue == null ||
(relationServCallFlg && relationServ == null)) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationSupport.class.getName(),
"sendRoleUpdateNotification", new Object[] {newRole,
oldRoleValue, relationServCallFlg, relationServ});
if (relationServCallFlg) {
// Direct call to the Relation Service
// Shall not throw a RelationNotFoundException for an internal
// relation
try {
relationServ.sendRoleUpdateNotification(myRelId,
newRole,
oldRoleValue);
} catch (RelationNotFoundException exc) {
throw new RuntimeException(exc.getMessage());
}
} else {
Object[] params = new Object[3];
params[0] = myRelId;
params[1] = newRole;
params[2] = oldRoleValue;
String[] signature = new String[3];
signature[0] = "java.lang.String";
signature[1] = "javax.management.relation.Role";
signature[2] = "java.util.List";
// Can throw InstanceNotFoundException if the Relation Service
// is not registered (to be transformed).
//
// Can throw a MBeanException wrapping a
// RelationNotFoundException (to be raised in any case): wrapped
// exception to be thrown
//
// Shall not throw a ReflectionException
try {
myRelServiceMBeanServer.invoke(myRelServiceName,
"sendRoleUpdateNotification",
params,
signature);
} catch (ReflectionException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (InstanceNotFoundException exc2) {
throw new RelationServiceNotRegisteredException(
exc2.getMessage());
} catch (MBeanException exc3) {
Exception wrappedExc = exc3.getTargetException();
if (wrappedExc instanceof RelationNotFoundException) {
throw ((RelationNotFoundException)wrappedExc);
} else {
throw new RuntimeException(wrappedExc.getMessage());
}
}
}
RELATION_LOGGER.exiting(RelationSupport.class.getName(),
"sendRoleUpdateNotification");
return;
}
private void updateRelationServiceMap(Role newRole,
List<ObjectName> oldRoleValue,
boolean relationServCallFlg,
RelationService relationServ)
throws IllegalArgumentException,
RelationServiceNotRegisteredException,
RelationNotFoundException {
if (newRole == null ||
oldRoleValue == null ||
(relationServCallFlg && relationServ == null)) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationSupport.class.getName(),
"updateRelationServiceMap", new Object[] {newRole,
oldRoleValue, relationServCallFlg, relationServ});
if (relationServCallFlg) {
// Direct call to the Relation Service
// Shall not throw a RelationNotFoundException
try {
relationServ.updateRoleMap(myRelId,
newRole,
oldRoleValue);
} catch (RelationNotFoundException exc) {
throw new RuntimeException(exc.getMessage());
}
} else {
Object[] params = new Object[3];
params[0] = myRelId;
params[1] = newRole;
params[2] = oldRoleValue;
String[] signature = new String[3];
signature[0] = "java.lang.String";
signature[1] = "javax.management.relation.Role";
signature[2] = "java.util.List";
// Can throw InstanceNotFoundException if the Relation Service
// is not registered (to be transformed).
// Can throw a MBeanException wrapping a RelationNotFoundException:
// wrapped exception to be thrown
//
// Shall not throw a ReflectionException
try {
myRelServiceMBeanServer.invoke(myRelServiceName,
"updateRoleMap",
params,
signature);
} catch (ReflectionException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (InstanceNotFoundException exc2) {
throw new
RelationServiceNotRegisteredException(exc2.getMessage());
} catch (MBeanException exc3) {
Exception wrappedExc = exc3.getTargetException();
if (wrappedExc instanceof RelationNotFoundException) {
throw ((RelationNotFoundException)wrappedExc);
} else {
throw new RuntimeException(wrappedExc.getMessage());
}
}
}
RELATION_LOGGER.exiting(RelationSupport.class.getName(),
"updateRelationServiceMap");
return;
}
/**
* Retrieves role value for given role name in given relation.
*
* @param relationId relation id
* @param roleName name of role
*
* @return the ArrayList of ObjectName objects being the role value
*
* @exception RelationServiceNotRegisteredException if the Relation
* Service is not registered
* @exception IllegalArgumentException if null parameter
* @exception RelationNotFoundException if no relation with given id
* @exception RoleNotFoundException if:
* <P>- there is no role with given name
* <P>or
* <P>- the role is not readable.
*
* @see #setRole
*/
public List<ObjectName> getRole(String relationId,
String roleName)
throws RelationServiceNotRegisteredException,
IllegalArgumentException,
RelationNotFoundException,
RoleNotFoundException {
if (relationId == null || roleName == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"getRole", new Object[] {relationId, roleName});
// Can throw RelationServiceNotRegisteredException
isActive();
// Can throw a RelationNotFoundException
Object relObj = getRelation(relationId);
List<ObjectName> result;
if (relObj instanceof RelationSupport) {
// Internal relation
// Can throw RoleNotFoundException
result = cast(
((RelationSupport)relObj).getRoleInt(roleName,
true,
this,
false));
} else {
// Relation MBean
Object[] params = new Object[1];
params[0] = roleName;
String[] signature = new String[1];
signature[0] = "java.lang.String";
// Can throw MBeanException wrapping a RoleNotFoundException:
// throw wrapped exception
//
// Shall not throw InstanceNotFoundException or ReflectionException
try {
List<ObjectName> invokeResult = cast(
myMBeanServer.invoke(((ObjectName)relObj),
"getRole",
params,
signature));
if (invokeResult == null || invokeResult instanceof ArrayList<?>)
result = invokeResult;
else
result = new ArrayList<ObjectName>(invokeResult);
} catch (InstanceNotFoundException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (ReflectionException exc2) {
throw new RuntimeException(exc2.getMessage());
} catch (MBeanException exc3) {
Exception wrappedExc = exc3.getTargetException();
if (wrappedExc instanceof RoleNotFoundException) {
throw ((RoleNotFoundException)wrappedExc);
} else {
throw new RuntimeException(wrappedExc.getMessage());
}
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(), "getRole");
return result;
}
/**
* Retrieves values of roles with given names in given relation.
*
* @param relationId relation id
* @param roleNameArray array of names of roles to be retrieved
*
* @return a RoleResult object, including a RoleList (for roles
* successfully retrieved) and a RoleUnresolvedList (for roles not
* retrieved).
*
* @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
*
* @see #setRoles
*/
public RoleResult getRoles(String relationId,
String[] roleNameArray)
throws RelationServiceNotRegisteredException,
IllegalArgumentException,
RelationNotFoundException {
if (relationId == null || roleNameArray == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"getRoles", relationId);
// Can throw RelationServiceNotRegisteredException
isActive();
// Can throw a RelationNotFoundException
Object relObj = getRelation(relationId);
RoleResult result;
if (relObj instanceof RelationSupport) {
// Internal relation
result = ((RelationSupport)relObj).getRolesInt(roleNameArray,
true,
this);
} else {
// Relation MBean
Object[] params = new Object[1];
params[0] = roleNameArray;
String[] signature = new String[1];
try {
signature[0] = (roleNameArray.getClass()).getName();
} catch (Exception exc) {
// OK : This is an array of java.lang.String
// so this should never happen...
}
// Shall not throw InstanceNotFoundException, ReflectionException
// or MBeanException
try {
result = (RoleResult)
(myMBeanServer.invoke(((ObjectName)relObj),
"getRoles",
params,
signature));
} catch (InstanceNotFoundException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (ReflectionException exc2) {
throw new RuntimeException(exc2.getMessage());
} catch (MBeanException exc3) {
throw new
RuntimeException((exc3.getTargetException()).getMessage());
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(), "getRoles");
return result;
}
/**
* Retrieves the number of MBeans currently referenced in the given role.
*
* @param relationId relation id
* @param roleName name of role
*
* @return the number of currently referenced MBeans in that role
*
* @exception IllegalArgumentException if null parameter
* @exception RelationNotFoundException if no relation with given id
* @exception RoleNotFoundException if there is no role with given name
*/
public Integer getRoleCardinality(String relationId,
String roleName)
throws IllegalArgumentException,
RelationNotFoundException,
RoleNotFoundException {
if (relationId == null || roleName == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"getRoleCardinality", new Object[] {relationId, roleName});
// Can throw a RelationNotFoundException
Object relObj = getRelation(relationId);
Integer result;
if (relObj instanceof RelationSupport) {
// Internal relation
// Can throw RoleNotFoundException
result = ((RelationSupport)relObj).getRoleCardinality(roleName);
} else {
// Relation MBean
Object[] params = new Object[1];
params[0] = roleName;
String[] signature = new String[1];
signature[0] = "java.lang.String";
// Can throw MBeanException wrapping RoleNotFoundException:
// throw wrapped exception
//
// Shall not throw InstanceNotFoundException or ReflectionException
try {
result = (Integer)
(myMBeanServer.invoke(((ObjectName)relObj),
"getRoleCardinality",
params,
signature));
} catch (InstanceNotFoundException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (ReflectionException exc2) {
throw new RuntimeException(exc2.getMessage());
} catch (MBeanException exc3) {
Exception wrappedExc = exc3.getTargetException();
if (wrappedExc instanceof RoleNotFoundException) {
throw ((RoleNotFoundException)wrappedExc);
} else {
throw new RuntimeException(wrappedExc.getMessage());
}
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(),
"getRoleCardinality");
return result;
}
/**
* Sets the given roles in given relation.
* <P>Will check the role according to its corresponding role definition
* provided in relation's relation type
* <P>The Relation Service keeps track of the changes to keep the
* consistency of relations by handling referenced MBean deregistrations.
*
* @param relationId relation id
* @param roleList list of roles to be set
*
* @return a RoleResult object, including a RoleList (for roles
* successfully set) and a RoleUnresolvedList (for roles not
* set).
*
* @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
*
* @see #getRoles
*/
public RoleResult setRoles(String relationId,
RoleList roleList)
throws RelationServiceNotRegisteredException,
IllegalArgumentException,
RelationNotFoundException {
if (relationId == null || roleList == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"setRoles", new Object[] {relationId, roleList});
// Can throw RelationServiceNotRegisteredException
isActive();
// Can throw a RelationNotFoundException
Object relObj = getRelation(relationId);
RoleResult result;
if (relObj instanceof RelationSupport) {
// Internal relation
// Can throw RelationServiceNotRegisteredException
//
// Shall not throw RelationTypeNotFoundException (as relation is
// known, its relation type exists)
try {
result = ((RelationSupport)relObj).setRolesInt(roleList,
true,
this);
} catch (RelationTypeNotFoundException exc) {
throw new RuntimeException(exc.getMessage());
}
} else {
// Relation MBean
Object[] params = new Object[1];
params[0] = roleList;
String[] signature = new String[1];
signature[0] = "javax.management.relation.RoleList";
// Shall not throw InstanceNotFoundException or an MBeanException
// or ReflectionException
try {
result = (RoleResult)
(myMBeanServer.invoke(((ObjectName)relObj),
"setRoles",
params,
signature));
} catch (InstanceNotFoundException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (ReflectionException exc3) {
throw new RuntimeException(exc3.getMessage());
} catch (MBeanException exc2) {
throw new
RuntimeException((exc2.getTargetException()).getMessage());
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(), "setRoles");
return result;
}
private void updateRelationServiceMap(Role newRole,
List<ObjectName> oldRoleValue,
boolean relationServCallFlg,
RelationService relationServ)
throws IllegalArgumentException,
RelationServiceNotRegisteredException,
RelationNotFoundException {
if (newRole == null ||
oldRoleValue == null ||
(relationServCallFlg && relationServ == null)) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationSupport.class.getName(),
"updateRelationServiceMap", new Object[] {newRole,
oldRoleValue, relationServCallFlg, relationServ});
if (relationServCallFlg) {
// Direct call to the Relation Service
// Shall not throw a RelationNotFoundException
try {
relationServ.updateRoleMap(myRelId,
newRole,
oldRoleValue);
} catch (RelationNotFoundException exc) {
throw new RuntimeException(exc.getMessage());
}
} else {
Object[] params = new Object[3];
params[0] = myRelId;
params[1] = newRole;
params[2] = oldRoleValue;
String[] signature = new String[3];
signature[0] = "java.lang.String";
signature[1] = "javax.management.relation.Role";
signature[2] = "java.util.List";
// Can throw InstanceNotFoundException if the Relation Service
// is not registered (to be transformed).
// Can throw a MBeanException wrapping a RelationNotFoundException:
// wrapped exception to be thrown
//
// Shall not throw a ReflectionException
try {
myRelServiceMBeanServer.invoke(myRelServiceName,
"updateRoleMap",
params,
signature);
} catch (ReflectionException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (InstanceNotFoundException exc2) {
throw new
RelationServiceNotRegisteredException(exc2.getMessage());
} catch (MBeanException exc3) {
Exception wrappedExc = exc3.getTargetException();
if (wrappedExc instanceof RelationNotFoundException) {
throw ((RelationNotFoundException)wrappedExc);
} else {
throw new RuntimeException(wrappedExc.getMessage());
}
}
}
RELATION_LOGGER.exiting(RelationSupport.class.getName(),
"updateRelationServiceMap");
return;
}
private void sendRoleUpdateNotification(Role newRole,
List<ObjectName> oldRoleValue,
boolean relationServCallFlg,
RelationService relationServ)
throws IllegalArgumentException,
RelationServiceNotRegisteredException,
RelationNotFoundException {
if (newRole == null ||
oldRoleValue == null ||
(relationServCallFlg && relationServ == null)) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationSupport.class.getName(),
"sendRoleUpdateNotification", new Object[] {newRole,
oldRoleValue, relationServCallFlg, relationServ});
if (relationServCallFlg) {
// Direct call to the Relation Service
// Shall not throw a RelationNotFoundException for an internal
// relation
try {
relationServ.sendRoleUpdateNotification(myRelId,
newRole,
oldRoleValue);
} catch (RelationNotFoundException exc) {
throw new RuntimeException(exc.getMessage());
}
} else {
Object[] params = new Object[3];
params[0] = myRelId;
params[1] = newRole;
params[2] = oldRoleValue;
String[] signature = new String[3];
signature[0] = "java.lang.String";
signature[1] = "javax.management.relation.Role";
signature[2] = "java.util.List";
// Can throw InstanceNotFoundException if the Relation Service
// is not registered (to be transformed).
//
// Can throw a MBeanException wrapping a
// RelationNotFoundException (to be raised in any case): wrapped
// exception to be thrown
//
// Shall not throw a ReflectionException
try {
myRelServiceMBeanServer.invoke(myRelServiceName,
"sendRoleUpdateNotification",
params,
signature);
} catch (ReflectionException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (InstanceNotFoundException exc2) {
throw new RelationServiceNotRegisteredException(
exc2.getMessage());
} catch (MBeanException exc3) {
Exception wrappedExc = exc3.getTargetException();
if (wrappedExc instanceof RelationNotFoundException) {
throw ((RelationNotFoundException)wrappedExc);
} else {
throw new RuntimeException(wrappedExc.getMessage());
}
}
}
RELATION_LOGGER.exiting(RelationSupport.class.getName(),
"sendRoleUpdateNotification");
return;
}