1 package org.csc.phynixx.loggersystem.logrecord;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 class PhynixxDataRecord implements IDataRecord, Comparable<PhynixxDataRecord> {
30
31 private static final byte[][] EMPTY_DATA = new byte[][]{};
32
33 private static final byte[] EMPTY_BYTES = new byte[]{};
34
35 private Integer ordinal = null;
36
37
38
39
40 private long messageSequenceId;
41
42
43
44
45 private byte[][] records = null;
46
47 private XALogRecordType logRecordType = XALogRecordType.UNKNOWN;
48
49
50
51
52
53
54
55
56
57
58 PhynixxDataRecord(long messageSequenceId, int ordinal, XALogRecordType logRecordType, byte[][] data) {
59
60 this.ordinal = ordinal;
61 this.logRecordType = logRecordType;
62 this.messageSequenceId = messageSequenceId;
63 this.setRecords(data);
64 }
65
66
67 public XALogRecordType getLogRecordType() {
68 return logRecordType;
69 }
70
71 public long getXADataRecorderId() {
72 return this.messageSequenceId;
73 }
74
75 public byte[][] getData() {
76 return (records != null) ? records : EMPTY_DATA;
77 }
78
79
80
81
82
83
84
85 private void setRecords(byte[][] data) {
86 if (data == null || data.length==0) {
87 this.records = EMPTY_DATA;
88 return;
89 }
90
91 this.records = new byte[data.length][];
92 for (int i = 0; i < data.length; i++) {
93 if (data[i] != null) {
94 this.records[i] = data[i];
95 } else {
96 this.records[i] = EMPTY_BYTES;
97 }
98 }
99 }
100
101
102
103
104
105
106 public Integer getOrdinal() {
107 return this.ordinal;
108 }
109
110
111 public String toString() {
112 StringBuffer recordLength = new StringBuffer();
113
114 recordLength.append("{");
115 if (this.records != null && this.records.length > 0) {
116 for (int i = 0; i < records.length; i++) {
117 recordLength.append('[').append(records[i].length).append("] ");
118 }
119 }
120 recordLength.append("}");
121 return "LogMessage messageSequence=" + this.getXADataRecorderId() + " ordinal=" + this.getOrdinal() + " logRecordType=" + logRecordType + " records=" + recordLength.toString();
122 }
123
124 public int hashCode() {
125 final int prime = 31;
126 int result = 1;
127 result = prime * result + Long.valueOf(messageSequenceId).intValue();
128 result = prime * result + ((ordinal == null) ? 0 : ordinal.hashCode());
129 return result;
130 }
131
132 public boolean equals(Object obj) {
133 if (this == obj)
134 return true;
135 if (obj == null)
136 return false;
137 if (getClass() != obj.getClass())
138 return false;
139
140 if (obj instanceof PhynixxDataRecord) {
141 return this.compareTo((PhynixxDataRecord) obj) == 0;
142 } else {
143 return false;
144 }
145 }
146
147 public int compareTo(PhynixxDataRecord otherMsg) {
148 if (otherMsg == null) {
149 return 1;
150 }
151
152 int cmp = Long.valueOf(this.getXADataRecorderId() - otherMsg.getXADataRecorderId()).intValue();
153 if (cmp != 0) {
154 return cmp;
155 } else {
156 int diff = this.getOrdinal().intValue() - otherMsg.getOrdinal().intValue();
157 return (diff == 0) ? 0 : (diff < 0) ? -1 : 1;
158 }
159
160 }
161
162
163 }