User: ejort Date: 02/03/16 04:38:51 Modified: src/main/javax/management/relation Tag: BranchMX_1_0 RelationService.java RelationServiceMBean.java RelationTypeSupport.java Role.java RoleList.java RoleUnresolved.java RoleUnresolvedList.java RoleValidator.java Log: Relations, Queries and MBeanRegistry synched with head Revision Changes Path No revision No revision 1.4.2.1 +110 -14 jmx/src/main/javax/management/relation/RelationService.java Index: RelationService.java =================================================================== RCS file: /cvsroot/jboss/jmx/src/main/javax/management/relation/RelationService.java,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -u -r1.4 -r1.4.2.1 --- RelationService.java 1 Mar 2002 19:25:57 -0000 1.4 +++ RelationService.java 16 Mar 2002 12:38:51 -0000 1.4.2.1 @@ -15,7 +15,9 @@ import java.util.Stack; import javax.management.Attribute; +import javax.management.AttributeNotFoundException; import javax.management.InstanceNotFoundException; +import javax.management.InvalidAttributeValueException; import javax.management.MBeanException; import javax.management.MBeanNotificationInfo; import javax.management.MBeanRegistration; @@ -32,10 +34,24 @@ /** * Implements the management interface for a relation service.<p> * + * <p><b>Revisions:</b> + * <p><b>20020311 Adrian Brock:</b> + * <ul> + * <li>Fixed setRole for external MBean and exception handling + * <li>EmptyStack exception in purging + * <li>Unregistered mbeans should only contain relation mbeans + * <li>Unregister notifications not working after change to MBean Filter + * </ul> + * <p><b>20020312 Adrian Brock:</b> + * <ul> + * <li>Fixed wrong exception types thrown and missing exceptions + * <li>Allow null role list in createRelation + * </ul> + * * @see RelationServiceMBean * * @author <a href="mailto:[EMAIL PROTECTED]">Adrian Brock</a>. - * @version $Revision: 1.4 $ + * @version $Revision: 1.4.2.1 $ */ public class RelationService extends NotificationBroadcasterSupport @@ -130,12 +146,13 @@ throws IllegalArgumentException, NoSuchMethodException, RelationServiceNotRegisteredException, InvalidRelationIdException, InvalidRelationServiceException, RelationTypeNotFoundException, - InvalidRoleValueException, RoleNotFoundException + InvalidRoleValueException, RoleNotFoundException, + InstanceNotFoundException { // Check we have a relation - isActive(); if (relation == null) throw new IllegalArgumentException("null relation"); + isActive(); // Get the information we need from the relation ObjectName otherService = null; @@ -153,6 +170,10 @@ roleList = (RoleList) server.invoke(relation, "retrieveAllRoles", new Object[0], new String[0]); } + catch (InstanceNotFoundException e) + { + throw e; + } catch (Exception e) { throw new NoSuchMethodException("Not a relation or not registered"); @@ -189,7 +210,7 @@ { String name = relationType.getRelationTypeName(); if (typesByName.containsKey(name)) - throw new IllegalArgumentException("duplicate relation id"); + throw new InvalidRelationTypeException("duplicate relation id: " + name); validateRelationType(relationType); typesByName.put(name, relationType); } @@ -198,6 +219,9 @@ public Integer checkRoleReading(String roleName, String relationTypeName) throws IllegalArgumentException, RelationTypeNotFoundException { + if (roleName == null) + throw new IllegalArgumentException("Null role name"); + // Get the relation type RelationType relationType = retrieveRelationTypeForName(relationTypeName); @@ -224,6 +248,11 @@ Boolean initFlag) throws IllegalArgumentException, RelationTypeNotFoundException { + if (role == null) + throw new IllegalArgumentException("Null role name"); + if (initFlag == null) + throw new IllegalArgumentException("Null init flag"); + // Get the relation type RelationType relationType = retrieveRelationTypeForName(relationTypeName); @@ -254,7 +283,11 @@ RoleNotFoundException { // Take a copy of the role list - RoleList copy = new RoleList(roleList); + RoleList copy = null; + if (roleList != null) + copy = new RoleList(roleList); + else + copy = new RoleList(); // Create a relation isActive(); @@ -284,7 +317,8 @@ synchronized (typesByName) { if (typesByName.containsKey(relationTypeName)) - throw new IllegalArgumentException("duplicate relation id"); + throw new InvalidRelationTypeException("duplicate relation id: " + + relationTypeName); RelationType relationType = new RelationTypeSupport(relationTypeName, roleInfos); typesByName.put(relationTypeName, relationType); @@ -625,6 +659,46 @@ return relationType.getRoleInfos(); } + public RoleResult getRoles(String relationId, String[] roleNames) + throws IllegalArgumentException, RelationNotFoundException, + RelationServiceNotRegisteredException + { + // Get the relation object name + if (roleNames == null) + throw new IllegalArgumentException("null role names"); + isActive(); + Object relation = retrieveRelationForId(relationId); + + // Ask the relation for the role value + if (relation instanceof RelationSupport) + { + return ((RelationSupport) relation).getRoles(roleNames); + } + else + { + ObjectName objectName = (ObjectName) relation; + try + { + RoleResult result = (RoleResult) server.invoke(objectName, "getRoles", + new Object[] { roleNames }, + new String[] { new String[0].getClass().getName() }); + return result; + } + catch (InstanceNotFoundException e) + { + throw new RelationNotFoundException(objectName.toString()); + } + catch (MBeanException e) + { + throw new RuntimeException(e.toString()); + } + catch (ReflectionException e) + { + throw new RuntimeException(e.toString()); + } + } + } + public Boolean hasRelation(String relationId) throws IllegalArgumentException { @@ -654,6 +728,8 @@ if (relationId == null) throw new IllegalArgumentException("null relation id"); Object result = relationsById.get(relationId); + if (result == null) + throw new RelationNotFoundException(relationId); if (result instanceof ObjectName) return (ObjectName) result; else @@ -665,12 +741,10 @@ { isActive(); // Keep going until they are all done - while (true) + while (unregistered.empty() == false) { // Get the next object ObjectName mbean = (ObjectName) unregistered.pop(); - if (mbean == null) - break; // Keep track of the remain relations/roles HashMap relationRoles = new HashMap(); @@ -772,6 +846,7 @@ // Check to see whether this will remove the MBean Iterator iterator = unregMBeans.iterator(); + while (iterator.hasNext()) { // Remove the MBeans relation role map ObjectName mbean = (ObjectName) iterator.next(); @@ -781,8 +856,9 @@ // We were the last? if (idRolesMap.size() == 0) idRolesMapByMBean.remove(mbean); - else - // Not the last, we aren't unregistering it + + // Is this an MBean a relation? + if (idsByRelation.containsKey(mbean) == false) iterator.remove(); } @@ -904,6 +980,12 @@ type = RelationNotification.RELATION_MBEAN_UPDATE; description = "Update of external relation."; } + if (newRole == null) + throw new IllegalArgumentException("null role"); + + if (oldRoleValue == null) + throw new IllegalArgumentException("null old role value"); + // Send the notification sendNotification(type, description, relationId, null, newRole, oldRoleValue); } @@ -934,8 +1016,7 @@ ObjectName objectName = (ObjectName) relation; try { - server.invoke(objectName, "setRole", new Object[] { role }, - new String[] { "javax.management.relation.Role" }); + server.setAttribute(objectName, new Attribute("Role", role)); } catch (InstanceNotFoundException e) { @@ -946,9 +1027,19 @@ Exception e = mbe.getTargetException(); if (e instanceof RoleNotFoundException) throw (RoleNotFoundException) e; + else if (e instanceof InvalidRoleValueException) + throw (InvalidRoleValueException) e; else throw new RuntimeException(e.toString()); } + catch (AttributeNotFoundException e) + { + throw new RuntimeException(e.toString()); + } + catch (InvalidAttributeValueException e) + { + throw new RuntimeException(e.toString()); + } catch (ReflectionException e) { throw new RuntimeException(e.toString()); @@ -1017,6 +1108,9 @@ throw new IllegalArgumentException("null old role value"); isActive(); + if (relationsById.containsKey(relationId) == false) + throw new RelationNotFoundException("Invalid relation id: " + relationId); + // Get the role name and new Value String roleName = newRole.getRoleName(); ArrayList newRoleValue = (ArrayList) newRole.getRoleValue(); @@ -1079,7 +1173,7 @@ // Install our notification listener we aren't interested in registration // We aren't monitoring anything at start-up filter = new MBeanServerNotificationFilter(); - filter.disableType(MBeanServerNotification.REGISTRATION_NOTIFICATION); + filter.enableType(MBeanServerNotification.UNREGISTRATION_NOTIFICATION); filter.disableAllObjectNames(); delegate = new ObjectName(MBeanServerImpl.MBEAN_SERVER_DELEGATE); server.addNotificationListener(delegate, this, filter, null); @@ -1258,6 +1352,8 @@ private RelationType retrieveRelationTypeForName(String relationTypeName) throws IllegalArgumentException, RelationTypeNotFoundException { + if (relationTypeName == null) + throw new IllegalArgumentException("Null relation type name"); // Get the relation type RelationType result = (RelationType) typesByName.get(relationTypeName); if (result == null) 1.4.2.1 +29 -2 jmx/src/main/javax/management/relation/RelationServiceMBean.java Index: RelationServiceMBean.java =================================================================== RCS file: /cvsroot/jboss/jmx/src/main/javax/management/relation/RelationServiceMBean.java,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -u -r1.4 -r1.4.2.1 --- RelationServiceMBean.java 1 Mar 2002 19:25:57 -0000 1.4 +++ RelationServiceMBean.java 16 Mar 2002 12:38:51 -0000 1.4.2.1 @@ -9,6 +9,7 @@ import java.util.List; import java.util.Map; +import javax.management.InstanceNotFoundException; import javax.management.ObjectName; /** @@ -21,8 +22,15 @@ * in their relation types/roles.<br> * Allowing relations to be queried. * + * <p><b>Revisions:</b> + * <p><b>20020312 Adrian Brock:</b> + * <ul> + * <li>Fixed wrong exception types thrown + * <li>Add missing method getRoles(String, String[]) + * </ul> + * * @author <a href="mailto:[EMAIL PROTECTED]">Adrian Brock</a>. - * @version $Revision: 1.4 $ + * @version $Revision: 1.4.2.1 $ */ public interface RelationServiceMBean { @@ -42,6 +50,8 @@ * Relation interface. * @exception RelationServiceNotRegisteredException when the relation * service is not registered with the MBeanServer. + * @exception InstanceNotFoundException when the relation is not + * registered in the MBeanServer. * @exception InvalidRelationIdException if the relation id * is already used by another relation. * @exception InvalidRelationServiceException if the relation service in @@ -61,7 +71,8 @@ throws IllegalArgumentException, NoSuchMethodException, RelationServiceNotRegisteredException, InvalidRelationIdException, InvalidRelationServiceException, RelationTypeNotFoundException, - InvalidRoleValueException, RoleNotFoundException; + InvalidRoleValueException, RoleNotFoundException, + InstanceNotFoundException; /** * Add a relation type to the relation service. @@ -329,6 +340,22 @@ */ public List getRoleInfos(String relationTypeName) throws IllegalArgumentException, RelationTypeNotFoundException; + + /** + * Retrieves selected roles for a relation. + * + * @param relationId the relation id + * @param roleNames an array of role name + * @return a RoleResult containing resolved and unresolved roles. + * @exception IllegalArgumentException for a null parameter. + * @exception RelationNotFoundException when the relation id does not + * exist. + * @exception RelationServiceNotRegisteredException when the relation + * service is not registered with an MBeanServer. + */ + public RoleResult getRoles(String relationId, String[] roleNames) + throws IllegalArgumentException, RelationNotFoundException, + RelationServiceNotRegisteredException; /** * Checks whether the relation service has the passed relation id. 1.3.2.1 +9 -2 jmx/src/main/javax/management/relation/RelationTypeSupport.java Index: RelationTypeSupport.java =================================================================== RCS file: /cvsroot/jboss/jmx/src/main/javax/management/relation/RelationTypeSupport.java,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -u -r1.3 -r1.3.2.1 --- RelationTypeSupport.java 8 Feb 2002 21:17:54 -0000 1.3 +++ RelationTypeSupport.java 16 Mar 2002 12:38:51 -0000 1.3.2.1 @@ -15,10 +15,15 @@ * This class can be used to implement relation types.<p> * * It holds RoleInfo objects for all roles in the relation. + * + * <p><b>Revisions:</b> + * <p><b>20020312 Adrian Brock:</b> + * <ul> + * <li>Fixed error handling for getRoleInfo + * </ul> * * @author <a href="mailto:[EMAIL PROTECTED]">Adrian Brock</a>. - * @version $Revision: 1.3 $ - * + * @version $Revision: 1.3.2.1 $ */ public class RelationTypeSupport implements RelationType @@ -108,6 +113,8 @@ public RoleInfo getRoleInfo(String roleInfoName) throws RoleInfoNotFoundException { + if (roleInfoName == null) + throw new IllegalArgumentException("Null role info name"); RoleInfo result = null; ArrayList temp = new ArrayList(roleInfos); Iterator iterator = temp.iterator(); 1.3.2.1 +3 -1 jmx/src/main/javax/management/relation/Role.java Index: Role.java =================================================================== RCS file: /cvsroot/jboss/jmx/src/main/javax/management/relation/Role.java,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -u -r1.3 -r1.3.2.1 --- Role.java 8 Feb 2002 21:17:54 -0000 1.3 +++ Role.java 16 Mar 2002 12:38:51 -0000 1.3.2.1 @@ -17,7 +17,7 @@ * the MBeans in the role. * * @author <a href="mailto:[EMAIL PROTECTED]">Adrian Brock</a> - * @version $Revision: 1.3 $ + * @version $Revision: 1.3.2.1 $ */ public class Role implements Serializable @@ -139,6 +139,8 @@ /** * Clones the object. + * + * @info.todo shouldn't use the copy constructor? * * @return a copy of the role */ 1.3.2.1 +8 -2 jmx/src/main/javax/management/relation/RoleList.java Index: RoleList.java =================================================================== RCS file: /cvsroot/jboss/jmx/src/main/javax/management/relation/RoleList.java,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -u -r1.3 -r1.3.2.1 --- RoleList.java 8 Feb 2002 21:17:54 -0000 1.3 +++ RoleList.java 16 Mar 2002 12:38:51 -0000 1.3.2.1 @@ -16,8 +16,14 @@ * I think the idea is supposed to be that only roles should be in the * list. But this isn't true. * + * <p><b>Revisions:</b> + * <p><b>20020313 Adrian Brock:</b> + * <ul> + * <li>Fix the cloning + * </ul> + * * @author <a href="mailto:[EMAIL PROTECTED]">Adrian Brock</a> - * @version $Revision: 1.3 $ + * @version $Revision: 1.3.2.1 $ */ public class RoleList extends ArrayList @@ -172,7 +178,7 @@ */ public Object clone() { - return new RoleList(this); + return super.clone(); } } 1.3.2.1 +3 -1 jmx/src/main/javax/management/relation/RoleUnresolved.java Index: RoleUnresolved.java =================================================================== RCS file: /cvsroot/jboss/jmx/src/main/javax/management/relation/RoleUnresolved.java,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -u -r1.3 -r1.3.2.1 --- RoleUnresolved.java 8 Feb 2002 21:17:54 -0000 1.3 +++ RoleUnresolved.java 16 Mar 2002 12:38:51 -0000 1.3.2.1 @@ -18,7 +18,7 @@ * was passed and the problem type. * * @author <a href="mailto:[EMAIL PROTECTED]">Adrian Brock</a> - * @version $Revision: 1.3 $ + * @version $Revision: 1.3.2.1 $ */ public class RoleUnresolved implements Serializable @@ -145,6 +145,8 @@ /** * Clones the object. + * + * @info.todo shouldn't use the copy constructor? */ public Object clone() { 1.3.2.1 +8 -2 jmx/src/main/javax/management/relation/RoleUnresolvedList.java Index: RoleUnresolvedList.java =================================================================== RCS file: /cvsroot/jboss/jmx/src/main/javax/management/relation/RoleUnresolvedList.java,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -u -r1.3 -r1.3.2.1 --- RoleUnresolvedList.java 8 Feb 2002 21:17:54 -0000 1.3 +++ RoleUnresolvedList.java 16 Mar 2002 12:38:51 -0000 1.3.2.1 @@ -13,8 +13,14 @@ /** * A list of unresolved roles. * + * <p><b>Revisions:</b> + * <p><b>20020313 Adrian Brock:</b> + * <ul> + * <li>Fix the cloning + * </ul> + * * @author <a href="mailto:[EMAIL PROTECTED]">Adrian Brock</a> - * @version $Revision: 1.3 $ + * @version $Revision: 1.3.2.1 $ */ public class RoleUnresolvedList extends ArrayList @@ -171,7 +177,7 @@ */ public Object clone() { - return new RoleUnresolvedList(this); + return super.clone(); } } 1.1.2.1 +14 -2 jmx/src/main/javax/management/relation/RoleValidator.java Index: RoleValidator.java =================================================================== RCS file: /cvsroot/jboss/jmx/src/main/javax/management/relation/RoleValidator.java,v retrieving revision 1.1 retrieving revision 1.1.2.1 diff -u -r1.1 -r1.1.2.1 --- RoleValidator.java 26 Jan 2002 15:13:24 -0000 1.1 +++ RoleValidator.java 16 Mar 2002 12:38:51 -0000 1.1.2.1 @@ -20,8 +20,15 @@ * * It is package private and NOT part of the specification. * + * <p><b>Revisions:</b> + * <p><b>20020311 Adrian Brock:</b> + * <ul> + * <li>ValidateRole always failed + * <li>Throws wrong exception when not writable + * </ul> + * * @author <a href="mailto:[EMAIL PROTECTED]">Adrian Brock</a>. - * @version $Revision: 1.1 $ + * @version $Revision: 1.1.2.1 $ * */ class RoleValidator @@ -163,9 +170,12 @@ { int status = checkRole(relationService, server, relationTypeName, role, write); + if (status == RoleStatus.NO_ROLE_WITH_NAME) throw new RoleNotFoundException(role.getRoleName()); - else + if (status == RoleStatus.ROLE_NOT_WRITABLE) + throw new RoleNotFoundException(role.getRoleName() + " not writable"); + else if (status != 0) throw new InvalidRoleValueException(role.getRoleName()); } @@ -215,6 +225,8 @@ int status = unresolved.getProblemType(); if (status == RoleStatus.NO_ROLE_WITH_NAME) throw new RoleNotFoundException(unresolved.getRoleName()); + if (status == RoleStatus.ROLE_NOT_WRITABLE) + throw new RoleNotFoundException(unresolved.getRoleName() + " not writable"); else throw new InvalidRoleValueException(unresolved.getRoleName()); }
_______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development