From: <tk...@hy...> - 2008-06-26 23:29:08
|
Author: tkeeney Date: 2008-06-26 16:29:05 -0700 (Thu, 26 Jun 2008) New Revision: 9892 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=9892 Modified: trunk/src/org/hyperic/hq/transport/util/HQInvokerLocator.java Log: The HQInvokerLocator is the key for the RemoteClientInvoker cache. Thus, equals() and hashCode() should account for differences in the agent token. Fixed NPE in cloneWithNewAgentToken(). Modified: trunk/src/org/hyperic/hq/transport/util/HQInvokerLocator.java =================================================================== --- trunk/src/org/hyperic/hq/transport/util/HQInvokerLocator.java 2008-06-26 23:09:26 UTC (rev 9891) +++ trunk/src/org/hyperic/hq/transport/util/HQInvokerLocator.java 2008-06-26 23:29:05 UTC (rev 9892) @@ -53,6 +53,7 @@ * @param path The invoker locator path or <code>null</code>. * @param parameters The invoker locator parameters or <code>null</code>. * @param agentToken The agent token. + * @throws NullPointerException if the agent token is <code>null</code>. */ public HQInvokerLocator(String protocol, String host, @@ -61,6 +62,11 @@ Map parameters, String agentToken) { super(protocol, host, port, path, parameters); + + if (agentToken == null) { + throw new NullPointerException("agent token is null"); + } + _agentToken = agentToken; } @@ -70,13 +76,20 @@ * * @param agentToken The new agent token value. * @return The cloned instance. + * @throws NullPointerException if the agent token is <code>null</code>. */ public HQInvokerLocator cloneWithNewAgentToken(String agentToken) { + Map parameters = null; + + if (this.getParameters() != null) { + parameters = new HashMap(this.getParameters()); + } + HQInvokerLocator locator = new HQInvokerLocator(this.getProtocol(), this.getHost(), this.getPort(), this.getPath(), - new HashMap(this.getParameters()), + parameters, agentToken); locator._invoker = this._invoker; @@ -152,5 +165,27 @@ public boolean isDeliveryGuaranteed() { return _guaranteed; } + + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + + if (obj instanceof HQInvokerLocator) { + HQInvokerLocator locator = (HQInvokerLocator)obj; + + return super.equals(obj) && locator.getAgentToken().equals(this.getAgentToken()); + } + + return false; + } + + public int hashCode() { + int result = super.hashCode(); + + result = 17*result+this.getAgentToken().hashCode(); + + return result; + } } |