Author: borges
Date: 2012-01-12 07:11:22 -0500 (Thu, 12 Jan 2012)
New Revision: 12018
Modified:
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/ClusterTopologyChangeMessage.java
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/ClusterTopologyChangeMessage_V2.java
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/MessagePacket.java
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/NodeAnnounceMessage.java
trunk/hornetq-core/src/main/java/org/hornetq/core/server/impl/LastValueQueue.java
Log:
Add hashCode/equals to classes w/ new fields that extend classes w/ equals/hashCode
Modified:
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/ClusterTopologyChangeMessage.java
===================================================================
---
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/ClusterTopologyChangeMessage.java 2012-01-12
12:10:54 UTC (rev 12017)
+++
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/ClusterTopologyChangeMessage.java 2012-01-12
12:11:22 UTC (rev 12018)
@@ -16,7 +16,6 @@
import org.hornetq.api.core.HornetQBuffer;
import org.hornetq.api.core.Pair;
import org.hornetq.api.core.TransportConfiguration;
-import org.hornetq.core.logging.Logger;
import org.hornetq.core.protocol.core.impl.PacketImpl;
/**
@@ -25,18 +24,12 @@
*/
public class ClusterTopologyChangeMessage extends PacketImpl
{
- // Constants -----------------------------------------------------
+ private boolean exit;
- private static final Logger log =
Logger.getLogger(ClusterTopologyChangeMessage.class);
+ private String nodeID;
- // Attributes ----------------------------------------------------
+ private Pair<TransportConfiguration, TransportConfiguration> pair;
- private boolean exit;
-
- private String nodeID;
-
- private Pair<TransportConfiguration, TransportConfiguration> pair;
-
private boolean last;
// Static --------------------------------------------------------
@@ -48,20 +41,20 @@
super(PacketImpl.CLUSTER_TOPOLOGY);
this.nodeID = nodeID;
-
+
this.pair = pair;
-
+
this.last = last;
-
+
this.exit = false;
}
-
+
public ClusterTopologyChangeMessage(final String nodeID)
{
super(PacketImpl.CLUSTER_TOPOLOGY);
-
+
this.exit = true;
-
+
this.nodeID = nodeID;
}
@@ -81,12 +74,12 @@
{
return pair;
}
-
+
public boolean isLast()
{
return last;
}
-
+
public boolean isExit()
{
return exit;
@@ -155,13 +148,64 @@
}
}
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + (exit ? 1231 : 1237);
+ result = prime * result + (last ? 1231 : 1237);
+ result = prime * result + ((nodeID == null) ? 0 : nodeID.hashCode());
+ result = prime * result + ((pair == null) ? 0 : pair.hashCode());
+ return result;
+ }
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (!super.equals(obj))
+ {
+ return false;
+ }
+ if (!(obj instanceof ClusterTopologyChangeMessage))
+ {
+ return false;
+ }
+ ClusterTopologyChangeMessage other = (ClusterTopologyChangeMessage)obj;
+ if (exit != other.exit)
+ {
+ return false;
+ }
+ if (last != other.last)
+ {
+ return false;
+ }
+ if (nodeID == null)
+ {
+ if (other.nodeID != null)
+ {
+ return false;
+ }
+ }
+ else if (!nodeID.equals(other.nodeID))
+ {
+ return false;
+ }
+ if (pair == null)
+ {
+ if (other.pair != null)
+ {
+ return false;
+ }
+ }
+ else if (!pair.equals(other.pair))
+ {
+ return false;
+ }
+ return true;
+ }
}
Modified:
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/ClusterTopologyChangeMessage_V2.java
===================================================================
---
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/ClusterTopologyChangeMessage_V2.java 2012-01-12
12:10:54 UTC (rev 12017)
+++
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/ClusterTopologyChangeMessage_V2.java 2012-01-12
12:11:22 UTC (rev 12018)
@@ -24,16 +24,12 @@
*/
public class ClusterTopologyChangeMessage_V2 extends PacketImpl
{
- // Constants -----------------------------------------------------
+ private boolean exit;
- // Attributes ----------------------------------------------------
+ private String nodeID;
- private boolean exit;
-
- private String nodeID;
-
private Pair<TransportConfiguration, TransportConfiguration> pair;
-
+
private long uniqueEventID;
private boolean last;
@@ -47,24 +43,24 @@
super(PacketImpl.CLUSTER_TOPOLOGY_V2);
this.nodeID = nodeID;
-
+
this.pair = pair;
-
+
this.last = last;
-
+
this.exit = false;
-
+
this.uniqueEventID = uniqueEventID;
}
-
+
public ClusterTopologyChangeMessage_V2(final long uniqueEventID, final String nodeID)
{
super(PacketImpl.CLUSTER_TOPOLOGY_V2);
-
+
this.exit = true;
-
+
this.nodeID = nodeID;
-
+
this.uniqueEventID = uniqueEventID;
}
@@ -84,12 +80,12 @@
{
return pair;
}
-
+
public boolean isLast()
{
return last;
}
-
+
/**
* @return the uniqueEventID
*/
@@ -97,14 +93,14 @@
{
return uniqueEventID;
}
-
+
public boolean isExit()
{
return exit;
}
-
-
+
+
@Override
public void encodeRest(final HornetQBuffer buffer)
{
@@ -170,13 +166,69 @@
}
}
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + (exit ? 1231 : 1237);
+ result = prime * result + (last ? 1231 : 1237);
+ result = prime * result + ((nodeID == null) ? 0 : nodeID.hashCode());
+ result = prime * result + ((pair == null) ? 0 : pair.hashCode());
+ result = prime * result + (int)(uniqueEventID ^ (uniqueEventID >>> 32));
+ return result;
+ }
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (!super.equals(obj))
+ {
+ return false;
+ }
+ if (!(obj instanceof ClusterTopologyChangeMessage_V2))
+ {
+ return false;
+ }
+ ClusterTopologyChangeMessage_V2 other = (ClusterTopologyChangeMessage_V2)obj;
+ if (exit != other.exit)
+ {
+ return false;
+ }
+ if (last != other.last)
+ {
+ return false;
+ }
+ if (nodeID == null)
+ {
+ if (other.nodeID != null)
+ {
+ return false;
+ }
+ }
+ else if (!nodeID.equals(other.nodeID))
+ {
+ return false;
+ }
+ if (pair == null)
+ {
+ if (other.pair != null)
+ {
+ return false;
+ }
+ }
+ else if (!pair.equals(other.pair))
+ {
+ return false;
+ }
+ if (uniqueEventID != other.uniqueEventID)
+ {
+ return false;
+ }
+ return true;
+ }
}
Modified:
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/MessagePacket.java
===================================================================
---
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/MessagePacket.java 2012-01-12
12:10:54 UTC (rev 12017)
+++
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/MessagePacket.java 2012-01-12
12:11:22 UTC (rev 12018)
@@ -14,7 +14,6 @@
package org.hornetq.core.protocol.core.impl.wireformat;
import org.hornetq.api.core.Message;
-import org.hornetq.core.logging.Logger;
import org.hornetq.core.message.impl.MessageInternal;
import org.hornetq.core.protocol.core.impl.PacketImpl;
@@ -27,8 +26,6 @@
*/
public abstract class MessagePacket extends PacketImpl
{
- private static final Logger log = Logger.getLogger(MessagePacket.class);
-
protected MessageInternal message;
public MessagePacket(final byte type, final MessageInternal message)
Modified:
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/NodeAnnounceMessage.java
===================================================================
---
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/NodeAnnounceMessage.java 2012-01-12
12:10:54 UTC (rev 12017)
+++
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/NodeAnnounceMessage.java 2012-01-12
12:11:22 UTC (rev 12018)
@@ -15,7 +15,6 @@
import org.hornetq.api.core.HornetQBuffer;
import org.hornetq.api.core.TransportConfiguration;
-import org.hornetq.core.logging.Logger;
import org.hornetq.core.protocol.core.impl.PacketImpl;
/**
@@ -24,18 +23,12 @@
*/
public class NodeAnnounceMessage extends PacketImpl
{
- // Constants -----------------------------------------------------
+ private String nodeID;
- private static final Logger log = Logger.getLogger(NodeAnnounceMessage.class);
+ private boolean backup;
- // Attributes ----------------------------------------------------
+ private long currentEventID;
- private String nodeID;
-
- private boolean backup;
-
- private long currentEventID;
-
private TransportConfiguration connector;
private TransportConfiguration backupConnector;
@@ -49,16 +42,16 @@
super(PacketImpl.NODE_ANNOUNCE);
this.currentEventID = currentEventID;
-
+
this.nodeID = nodeID;
-
+
this.backup = backup;
-
+
this.connector = tc;
-
+
this.backupConnector = backupConnector;
}
-
+
public NodeAnnounceMessage()
{
super(PacketImpl.NODE_ANNOUNCE);
@@ -71,17 +64,17 @@
{
return nodeID;
}
-
+
public boolean isBackup()
{
return backup;
}
-
+
public TransportConfiguration getConnector()
{
return connector;
}
-
+
public TransportConfiguration getBackupConnector()
{
return backupConnector;
@@ -139,9 +132,6 @@
}
}
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
@Override
public String toString()
{
@@ -155,13 +145,76 @@
"]";
}
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + (backup ? 1231 : 1237);
+ result = prime * result + ((backupConnector == null) ? 0 :
backupConnector.hashCode());
+ result = prime * result + ((connector == null) ? 0 : connector.hashCode());
+ result = prime * result + (int)(currentEventID ^ (currentEventID >>>
32));
+ result = prime * result + ((nodeID == null) ? 0 : nodeID.hashCode());
+ return result;
+ }
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (!super.equals(obj))
+ {
+ return false;
+ }
+ if (!(obj instanceof NodeAnnounceMessage))
+ {
+ return false;
+ }
+ NodeAnnounceMessage other = (NodeAnnounceMessage)obj;
+ if (backup != other.backup)
+ {
+ return false;
+ }
+ if (backupConnector == null)
+ {
+ if (other.backupConnector != null)
+ {
+ return false;
+ }
+ }
+ else if (!backupConnector.equals(other.backupConnector))
+ {
+ return false;
+ }
+ if (connector == null)
+ {
+ if (other.connector != null)
+ {
+ return false;
+ }
+ }
+ else if (!connector.equals(other.connector))
+ {
+ return false;
+ }
+ if (currentEventID != other.currentEventID)
+ {
+ return false;
+ }
+ if (nodeID == null)
+ {
+ if (other.nodeID != null)
+ {
+ return false;
+ }
+ }
+ else if (!nodeID.equals(other.nodeID))
+ {
+ return false;
+ }
+ return true;
+ }
}
Modified:
trunk/hornetq-core/src/main/java/org/hornetq/core/server/impl/LastValueQueue.java
===================================================================
---
trunk/hornetq-core/src/main/java/org/hornetq/core/server/impl/LastValueQueue.java 2012-01-12
12:10:54 UTC (rev 12017)
+++
trunk/hornetq-core/src/main/java/org/hornetq/core/server/impl/LastValueQueue.java 2012-01-12
12:11:22 UTC (rev 12018)
@@ -21,6 +21,7 @@
import org.hornetq.api.core.SimpleString;
import org.hornetq.core.filter.Filter;
import org.hornetq.core.logging.Logger;
+import org.hornetq.core.message.impl.MessageImpl;
import org.hornetq.core.paging.cursor.PageSubscription;
import org.hornetq.core.persistence.StorageManager;
import org.hornetq.core.postoffice.PostOffice;
@@ -32,12 +33,12 @@
import org.hornetq.core.transaction.Transaction;
/**
- * A queue that will discard messages if a newer message with the same
MessageImpl.HDR_LAST_VALUE_NAME property value.
- * In other words it only retains the last value
- *
+ * A queue that will discard messages if a newer message with the same
+ * {@link MessageImpl#HDR_LAST_VALUE_NAME} property value. In other words it only retains
the last
+ * value
+ * <p>
* This is useful for example, for stock prices, where you're only interested in the
latest value
* for a particular stock
- *
* @author <a href="mailto:andy.taylor@jboss.org">Andy Taylor</a>
* @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a> rewrite
*/
@@ -229,17 +230,17 @@
{
ref.setScheduledDeliveryTime(scheduledDeliveryTime);
}
-
+
public void setPersistedCount(int count)
{
ref.setPersistedCount(count);
}
-
+
public int getPersistedCount()
{
return ref.getPersistedCount();
}
-
+
public boolean isPaged()
{
return false;
@@ -269,4 +270,43 @@
return ref.getMessage().getMemoryEstimate();
}
}
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + ((map == null) ? 0 : map.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (!super.equals(obj))
+ {
+ return false;
+ }
+ if (!(obj instanceof LastValueQueue))
+ {
+ return false;
+ }
+ LastValueQueue other = (LastValueQueue)obj;
+ if (map == null)
+ {
+ if (other.map != null)
+ {
+ return false;
+ }
+ }
+ else if (!map.equals(other.map))
+ {
+ return false;
+ }
+ return true;
+ }
}