[Mc4j-cvs] SF.net SVN: mc4j:[592] trunk/mc4j/modules/ems
Brought to you by:
ghinkl
From: <gh...@us...> - 2008-09-16 09:33:16
|
Revision: 592 http://mc4j.svn.sourceforge.net/mc4j/?rev=592&view=rev Author: ghinkl Date: 2008-09-16 16:32:53 +0000 (Tue, 16 Sep 2008) Log Message: ----------- EMS fixes for overloaded operations Modified Paths: -------------- trunk/mc4j/modules/ems/build.xml trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/bean/EmsBean.java trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/bean/parameter/EmsParameter.java trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/bean/DMBean.java trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/bean/attribute/DAttribute.java trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/bean/operation/DOperation.java trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/bean/parameter/DParameter.java Modified: trunk/mc4j/modules/ems/build.xml =================================================================== --- trunk/mc4j/modules/ems/build.xml 2008-09-15 19:15:02 UTC (rev 591) +++ trunk/mc4j/modules/ems/build.xml 2008-09-16 16:32:53 UTC (rev 592) @@ -30,7 +30,7 @@ <property name="module.jar" value="org-mc4j-ems.jar"/> - <property name="release.version" value="1.2.2"/> + <property name="release.version" value="1.2.4"/> <target Modified: trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/bean/EmsBean.java =================================================================== --- trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/bean/EmsBean.java 2008-09-15 19:15:02 UTC (rev 591) +++ trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/bean/EmsBean.java 2008-09-16 16:32:53 UTC (rev 592) @@ -84,4 +84,6 @@ boolean isNotificationEmiter(); boolean isHasUnsupportedType(); + + EmsOperation getOperation(String operationName, Class... parameterTypes); } Modified: trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/bean/parameter/EmsParameter.java =================================================================== --- trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/bean/parameter/EmsParameter.java 2008-09-15 19:15:02 UTC (rev 591) +++ trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/bean/parameter/EmsParameter.java 2008-09-16 16:32:53 UTC (rev 592) @@ -6,7 +6,7 @@ * @author Greg Hinkle (gh...@us...) * @version $Revision$($Author$ / $Date$) */ -public interface EmsParameter { +public interface EmsParameter extends Comparable { String getName(); String getDescription(); Modified: trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/bean/DMBean.java =================================================================== --- trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/bean/DMBean.java 2008-09-15 19:15:02 UTC (rev 591) +++ trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/bean/DMBean.java 2008-09-16 16:32:53 UTC (rev 592) @@ -22,6 +22,7 @@ import org.mc4j.ems.connection.EmsUnsupportedTypeException; import org.mc4j.ems.connection.bean.EmsBean; import org.mc4j.ems.connection.bean.EmsBeanName; +import org.mc4j.ems.connection.bean.parameter.EmsParameter; import org.mc4j.ems.connection.bean.attribute.EmsAttribute; import org.mc4j.ems.connection.bean.notification.EmsNotification; import org.mc4j.ems.connection.bean.operation.EmsOperation; @@ -41,17 +42,9 @@ import javax.management.MBeanRegistrationException; import javax.management.MBeanServer; import javax.management.ObjectName; -import javax.management.modelmbean.ModelMBeanInfo; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.SortedSet; -import java.util.TreeMap; -import java.util.TreeSet; +import java.util.*; + /** * @author Greg Hinkle (gh...@us...), Apr 4, 2005 * @version $Revision$($Author$ / $Date$) @@ -74,6 +67,7 @@ private Map<String, EmsAttribute> attributes = new TreeMap<String, EmsAttribute>(String.CASE_INSENSITIVE_ORDER); private Map<String, EmsOperation> operations = new TreeMap<String, EmsOperation>(String.CASE_INSENSITIVE_ORDER); + private Set<EmsOperation> allOperations = new TreeSet<EmsOperation>(); private Map<String, EmsNotification> notifications = new TreeMap<String, EmsNotification>(String.CASE_INSENSITIVE_ORDER); protected List<Throwable> failures; @@ -148,6 +142,7 @@ for (MBeanOperationInfo operationInfo : info.getOperations()) { DOperation operation = new DOperation(operationInfo, this); this.operations.put(operationInfo.getName(), operation); + this.allOperations.add(operation); } for (MBeanNotificationInfo notificationInfo : info.getNotifications()) { @@ -322,9 +317,53 @@ return this.operations.get(name); } + /** + * Retrieves an operation from an mbean which matches the specified name + * and signature. The method is modeled after Class.getMethod() + * The order of parameterTypes must much the order of arguments returned + * for the operation by EMS. + * + * If not matching operation is found on the EmsBean then null is returned + */ + public EmsOperation getOperation(String operationName, Class... parameterTypes) { + getOperations(); + if (allOperations == null || allOperations.isEmpty()) { + return null; + } + + String[] parameterTypeNames = new String[parameterTypes.length]; + for (int i = 0; i < parameterTypes.length; i++) { + // TODO check whether this should be getName,getCanonicalName, + // getSimpleName + // just needs to match what EMS returns + parameterTypeNames[i] = parameterTypes[i].getName(); + } + EmsOperation selectedOperation = null; + for (EmsOperation operation : allOperations) { + List<EmsParameter> operationParameters = operation.getParameters(); + if (parameterTypeNames.length != operationParameters.size()) { + // different number of parameters to what we are looking for + continue; + } + String[] operationParameterTypeNames = new String[operationParameters.size()]; + int i = 0; + for (EmsParameter operationParameter : operationParameters) { + operationParameterTypeNames[i] = operationParameter.getType(); + i++; + } + + if (Arrays.equals(parameterTypeNames, operationParameterTypeNames)) { + selectedOperation = operation; + break; + } + } + return selectedOperation; + } + + public SortedSet<EmsOperation> getOperations() { if (info == null) loadSynchronous(); - return new TreeSet<EmsOperation>(this.operations.values()); + return new TreeSet<EmsOperation>(this.allOperations); } public EmsNotification getNotification(String name) { Modified: trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/bean/attribute/DAttribute.java =================================================================== --- trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/bean/attribute/DAttribute.java 2008-09-15 19:15:02 UTC (rev 591) +++ trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/bean/attribute/DAttribute.java 2008-09-16 16:32:53 UTC (rev 592) @@ -265,7 +265,7 @@ if (failures.size() > 2) failures.removeFirst(); - log.warn("Attribute access failure " + t.getLocalizedMessage(),t); + log.debug("Attribute access failure " + t.getLocalizedMessage(),t); } public org.mc4j.ems.store.ValueHistory getValueHistory() { Modified: trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/bean/operation/DOperation.java =================================================================== --- trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/bean/operation/DOperation.java 2008-09-15 19:15:02 UTC (rev 591) +++ trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/bean/operation/DOperation.java 2008-09-16 16:32:53 UTC (rev 592) @@ -27,6 +27,8 @@ import javax.management.ReflectionException; import java.util.List; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; /** * @author Greg Hinkle (gh...@us...), Apr 4, 2005 @@ -183,9 +185,40 @@ public int compareTo(Object o) { DOperation otherOperation = (DOperation) o; - return this.getName().compareTo( + int i = this.getName().compareTo( otherOperation.getName()); + if (i == 0) { + + i = ((Integer)parameters.size()).compareTo(otherOperation.getParameters().size()); + if (i == 0) { + for (int j = 0; j < parameters.size();j++) { + i = parameters.get(j).compareTo(otherOperation.getParameters().get(j)); + if (i != 0) { + break; + } + } + } + } + return i; } + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof DOperation)) return false; + + DOperation that = (DOperation) o; + + if (info != null ? !info.getName().equals(that.info.getName()) : that.info.getName() != null) return false; + if (parameters != null ? !parameters.equals(that.parameters) : that.parameters != null) return false; + + return true; + } + + public int hashCode() { + int result; + result = (info != null ? info.hashCode() : 0); + result = 31 * result + (parameters != null ? parameters.hashCode() : 0); + return result; + } } Modified: trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/bean/parameter/DParameter.java =================================================================== --- trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/bean/parameter/DParameter.java 2008-09-15 19:15:02 UTC (rev 591) +++ trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/bean/parameter/DParameter.java 2008-09-16 16:32:53 UTC (rev 592) @@ -26,7 +26,7 @@ * @author Greg Hinkle (gh...@us...) * @version $Revision$($Author$ / $Date$) */ -public class DParameter implements EmsParameter { +public class DParameter implements EmsParameter, Comparable { private String name; private String description; @@ -50,4 +50,33 @@ public String getType() { return type; } + + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof DParameter)) return false; + + DParameter that = (DParameter) o; + + if (name != null ? !name.equals(that.name) : that.name != null) return false; + + if (type != null ? !type.equals(that.type) : that.type != null) return false; + + return true; + } + + public int hashCode() { + int result; + result = (name != null ? name.hashCode() : 0); + result = 31 * result + (description != null ? description.hashCode() : 0); + result = 31 * result + (type != null ? type.hashCode() : 0); + return result; + } + + public int compareTo(Object o) { + int i = this.name.compareTo(((DParameter)o).getName()); + if (i == 0) { + i = this.getType().compareTo(((DParameter)o).getType()); + } + return i; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |