1 /*** 2 * 3 * Copyright 2004 Protique Ltd 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 **/ 18 package org.codehaus.activemq.service; 19 20 import java.io.Serializable; 21 22 /*** 23 * Represents a message identity, either by using a unique 24 * message number, which is ordered and must not be zero or 25 * by specifying the String messageID. 26 * <p/> 27 * Typically a client accessing the MessageStore may have 28 * one or the other. Depending on which one is specified the 29 * other value may be filled in by operations on the MessageStore 30 * 31 * @version $Revision: 1.10 $ 32 */ 33 public class MessageIdentity implements Comparable, Serializable { 34 private static final long serialVersionUID = -5754338187296859149L; 35 36 private String messageID; 37 private Object sequenceNumber; 38 39 public MessageIdentity() { 40 } 41 42 public MessageIdentity(String messageID) { 43 this.messageID = messageID; 44 } 45 46 public MessageIdentity(String messageID, Object sequenceNumber) { 47 this.messageID = messageID; 48 this.sequenceNumber = sequenceNumber; 49 } 50 51 public int hashCode() { 52 return messageID != null ? messageID.hashCode() ^ 0xcafebabe : -1; 53 } 54 55 public boolean equals(Object that) { 56 return that instanceof MessageIdentity && equals((MessageIdentity) that); 57 } 58 59 public boolean equals(MessageIdentity that) { 60 return messageID.equals(that.messageID); 61 } 62 63 public int compareTo(Object object) { 64 if (this == object) { 65 return 0; 66 } 67 else { 68 if (object instanceof MessageIdentity) { 69 MessageIdentity that = (MessageIdentity) object; 70 return messageID.compareTo(that.messageID); 71 } 72 else { 73 return -1; 74 } 75 } 76 } 77 78 public String toString() { 79 return super.toString() + "[id=" + messageID + "; sequenceNo=" + sequenceNumber + "]"; 80 } 81 82 public String getMessageID() { 83 return messageID; 84 } 85 86 public void setMessageID(String messageID) { 87 this.messageID = messageID; 88 } 89 90 /*** 91 * @return the sequence number which may be a number or some database specific type 92 */ 93 public Object getSequenceNumber() { 94 return sequenceNumber; 95 } 96 97 public void setSequenceNumber(Object sequenceNumber) { 98 this.sequenceNumber = sequenceNumber; 99 } 100 101 }