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.7 $
32 */
33 public class MessageIdentity implements Comparable, Serializable {
34 private String messageID;
35 private Object sequenceNumber;
36
37 public MessageIdentity() {
38 }
39
40 public MessageIdentity(String messageID) {
41 this.messageID = messageID;
42 }
43
44 public MessageIdentity(String messageID, Object sequenceNumber) {
45 this.messageID = messageID;
46 this.sequenceNumber = sequenceNumber;
47 }
48
49 public int hashCode() {
50 return messageID.hashCode() ^ 0xcafebabe;
51 }
52
53 public boolean equals(Object that) {
54 return that instanceof MessageIdentity && equals((MessageIdentity) that);
55 }
56
57 public boolean equals(MessageIdentity that) {
58 return messageID == that.messageID || messageID.equals(that.messageID);
59 }
60
61 public int compareTo(Object object) {
62 if (this == object) {
63 return 0;
64 }
65 else {
66 if (object instanceof MessageIdentity) {
67 MessageIdentity that = (MessageIdentity) object;
68 return messageID.compareTo(that.messageID);
69 }
70 else {
71 return -1;
72 }
73 }
74 }
75
76 public String toString() {
77 return super.toString() + "[id=" + messageID + "; sequenceNo=" + sequenceNumber + "]";
78 }
79
80 public String getMessageID() {
81 return messageID;
82 }
83
84 public void setMessageID(String messageID) {
85 this.messageID = messageID;
86 }
87
88 /***
89 * @return the sequence number which may be a number or some database specific type
90 */
91 public Object getSequenceNumber() {
92 return sequenceNumber;
93 }
94
95 public void setSequenceNumber(Object sequenceNumber) {
96 this.sequenceNumber = sequenceNumber;
97 }
98
99 }