1 /***************************************************************** 2 * Licensed to the Apache Software Foundation (ASF) under one * 3 * or more contributor license agreements. See the NOTICE file * 4 * distributed with this work for additional information * 5 * regarding copyright ownership. The ASF licenses this file * 6 * to you under the Apache License, Version 2.0 (the * 7 * "License"); you may not use this file except in compliance * 8 * with the License. You may obtain a copy of the License at * 9 * * 10 * http://www.apache.org/licenses/LICENSE-2.0 * 11 * * 12 * Unless required by applicable law or agreed to in writing, * 13 * software distributed under the License is distributed on an * 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * 15 * KIND, either express or implied. See the License for the * 16 * specific language governing permissions and limitations * 17 * under the License. * 18 ****************************************************************/ 19 20 21 package org.apache.james.postage.result; 22 23 import org.apache.james.postage.PostageRunner; 24 25 /*** 26 * contains all gathered data concerning one mail message 27 */ 28 public class MailProcessingRecord { 29 30 private static String SEPARATOR = ","; 31 private static int m_messageId = 1; 32 33 boolean matchedSentAndReceived = false; 34 boolean isReceivedValid = false; 35 36 long timeConnectStart; 37 String mailId; 38 String subject; 39 String sender; 40 String senderMailAddress; 41 String receiver; 42 String receiverMailAddress; 43 long timeSendEnd; 44 long timeSendStart; 45 long byteSendText; 46 long byteSendBinary; 47 int errorNumberSending; 48 String errorTextSending; 49 50 long timeReceived; 51 long timeServerReceived; 52 long timeFetchStart; 53 long timeFetchEnd; 54 long byteReceivedText; 55 long byteReceivedBinary; 56 long byteReceivedTotal; 57 String receivingQueue; 58 59 public synchronized static String getNextId() { 60 return PostageRunner.getMessageIdPrefix() + (m_messageId++); 61 } 62 63 public boolean isMatchedSentAndReceived() { 64 return matchedSentAndReceived; 65 } 66 67 public void setValid() { 68 isReceivedValid = true; 69 } 70 71 public boolean isReceivedValid() { 72 return isReceivedValid; 73 } 74 75 public long getTimeConnectStart() { 76 return timeConnectStart; 77 } 78 79 public void setTimeConnectStart(long timeConnectStart) { 80 this.timeConnectStart = timeConnectStart; 81 } 82 83 public String getMailId() { 84 return mailId; 85 } 86 87 public void setMailId(String mailId) { 88 this.mailId = mailId; 89 } 90 91 public String getSubject() { 92 return subject; 93 } 94 95 public void setSubject(String subject) { 96 this.subject = subject; 97 } 98 99 public String getSender() { 100 return sender; 101 } 102 103 public void setSender(String sender) { 104 this.sender = sender; 105 } 106 107 public String getSenderMailAddress() { 108 return senderMailAddress; 109 } 110 111 public void setSenderMailAddress(String senderMailAddress) { 112 this.senderMailAddress = senderMailAddress; 113 } 114 115 public String getReceiver() { 116 return receiver; 117 } 118 119 public void setReceiver(String receiver) { 120 this.receiver = receiver; 121 } 122 123 public String getReceiverMailAddress() { 124 return receiverMailAddress; 125 } 126 127 public void setReceiverMailAddress(String receiverMailAddress) { 128 this.receiverMailAddress = receiverMailAddress; 129 } 130 131 public long getTimeSendStart() { 132 return timeSendStart; 133 } 134 135 public void setTimeSendStart(long timeSendStart) { 136 this.timeSendStart = timeSendStart; 137 } 138 139 public long getTimeSendEnd() { 140 return timeSendEnd; 141 } 142 143 public void setTimeSendEnd(long timeSendEnd) { 144 this.timeSendEnd = timeSendEnd; 145 } 146 147 public long getByteSendText() { 148 return byteSendText; 149 } 150 151 public void setByteSendText(long byteSendText) { 152 this.byteSendText = byteSendText; 153 } 154 155 public long getByteSendBinary() { 156 return byteSendBinary; 157 } 158 159 public void setByteSendBinary(long byteSendBinary) { 160 this.byteSendBinary = byteSendBinary; 161 } 162 163 public long getByteReceivedText() { 164 return byteReceivedText; 165 } 166 167 public void setByteReceivedText(long byteReceivedText) { 168 this.byteReceivedText = byteReceivedText; 169 } 170 171 public long getByteReceivedBinary() { 172 return byteReceivedBinary; 173 } 174 175 public void setByteReceivedBinary(long byteReceivedBinary) { 176 this.byteReceivedBinary = byteReceivedBinary; 177 } 178 179 public long getByteReceivedTotal() { 180 return byteReceivedTotal; 181 } 182 183 public void setByteReceivedTotal(long byteReceivedTotal) { 184 this.byteReceivedTotal = byteReceivedTotal; 185 } 186 187 public int getErrorNumberSending() { 188 return errorNumberSending; 189 } 190 191 public void setErrorNumberSending(int errorNumberSending) { 192 this.errorNumberSending = errorNumberSending; 193 } 194 195 public String getErrorTextSending() { 196 return errorTextSending; 197 } 198 199 public void setErrorTextSending(String errorTextSending) { 200 this.errorTextSending = errorTextSending; 201 } 202 203 public long getTimeReceived() { 204 return timeReceived; 205 } 206 207 public void setTimeReceived(long timeReceived) { 208 this.timeReceived = timeReceived; 209 } 210 211 public long getTimeFetchStart() { 212 return timeFetchStart; 213 } 214 215 public void setTimeFetchStart(long timeFetchStart) { 216 this.timeFetchStart = timeFetchStart; 217 } 218 219 public long getTimeFetchEnd() { 220 return timeFetchEnd; 221 } 222 223 public void setTimeFetchEnd(long timeFetchEnd) { 224 this.timeFetchEnd = timeFetchEnd; 225 } 226 227 public long getTimeServerReceived() { 228 return timeServerReceived; 229 } 230 231 public void setTimeServerReceived(long timeServerReceived) { 232 this.timeServerReceived = timeServerReceived; 233 } 234 235 public String getReceivingQueue() { 236 return receivingQueue; 237 } 238 239 public void setReceivingQueue(String receivingQueue) { 240 this.receivingQueue = receivingQueue; 241 } 242 243 public void merge(MailProcessingRecord anotherRecord) { 244 if (matchedSentAndReceived) throw new IllegalStateException("already merged"); 245 matchedSentAndReceived = true; 246 247 if (timeConnectStart == 0) timeConnectStart = anotherRecord.timeConnectStart; 248 if (mailId == null) mailId = anotherRecord.mailId; 249 if (subject == null) subject = anotherRecord.subject; 250 if (sender == null) sender = anotherRecord.sender; 251 if (senderMailAddress == null) senderMailAddress = anotherRecord.senderMailAddress; 252 if (receiver == null) receiver = anotherRecord.receiver; 253 if (receiverMailAddress == null) receiverMailAddress = anotherRecord.receiverMailAddress; 254 if (timeSendStart == 0) timeSendStart = anotherRecord.timeSendStart; 255 if (timeSendEnd == 0) timeSendEnd = anotherRecord.timeSendEnd; 256 if (byteSendText == 0) byteSendText = anotherRecord.byteSendText; 257 if (byteSendBinary == 0) byteSendBinary = anotherRecord.byteSendBinary; 258 if (byteReceivedText == 0) byteReceivedText = anotherRecord.byteReceivedText; 259 if (byteReceivedBinary == 0) byteReceivedBinary = anotherRecord.byteReceivedBinary; 260 if (byteReceivedTotal == 0) byteReceivedTotal = anotherRecord.byteReceivedTotal; 261 if (errorNumberSending == 0) errorNumberSending = anotherRecord.errorNumberSending; 262 if (errorTextSending == null) errorTextSending = anotherRecord.errorTextSending; 263 if (timeReceived == 0) timeReceived = anotherRecord.timeReceived; 264 if (timeFetchStart == 0) timeFetchStart = anotherRecord.timeFetchStart; 265 if (timeFetchEnd == 0) timeFetchEnd = anotherRecord.timeFetchEnd; 266 if (timeServerReceived == 0) timeServerReceived = anotherRecord.timeServerReceived; 267 if (receivingQueue == null) receivingQueue = anotherRecord.receivingQueue; 268 if (anotherRecord.isReceivedValid) isReceivedValid = anotherRecord.isReceivedValid; 269 } 270 271 public static StringBuffer writeHeader() { 272 StringBuffer stringBuffer = new StringBuffer(); 273 stringBuffer.append("timeConnectStart").append(SEPARATOR); 274 stringBuffer.append("mailId").append(SEPARATOR); 275 stringBuffer.append("ReceivedMatchedSent").append(SEPARATOR); 276 stringBuffer.append("subject").append(SEPARATOR); 277 stringBuffer.append("sender").append(SEPARATOR); 278 stringBuffer.append("senderMailAddress").append(SEPARATOR); 279 stringBuffer.append("receiver").append(SEPARATOR); 280 stringBuffer.append("receiverMailAddress").append(SEPARATOR); 281 stringBuffer.append("timeSendStart").append(SEPARATOR); 282 stringBuffer.append("timeSendEnd").append(SEPARATOR); 283 stringBuffer.append("byteSendText").append(SEPARATOR); 284 stringBuffer.append("byteSendBinary").append(SEPARATOR); 285 stringBuffer.append("byteReceivedText").append(SEPARATOR); 286 stringBuffer.append("byteReceivedBinary").append(SEPARATOR); 287 stringBuffer.append("byteReceivedTotal").append(SEPARATOR); 288 stringBuffer.append("errorNumberSending").append(SEPARATOR); 289 stringBuffer.append("errorTextSending").append(SEPARATOR); 290 stringBuffer.append("timeReceived").append(SEPARATOR); 291 stringBuffer.append("timeFetchStart").append(SEPARATOR); 292 stringBuffer.append("timeFetchEnd").append(SEPARATOR); 293 stringBuffer.append("timeServerReceived").append(SEPARATOR); 294 stringBuffer.append("receivingQueue").append(SEPARATOR); 295 stringBuffer.append("valid").append(SEPARATOR); 296 stringBuffer.append("\r\n"); 297 298 return stringBuffer; 299 } 300 301 public StringBuffer writeData() { 302 StringBuffer stringBuffer = new StringBuffer(); 303 stringBuffer.append(timeConnectStart).append(SEPARATOR); 304 stringBuffer.append(mailId).append(SEPARATOR); 305 stringBuffer.append(isMatchedSentAndReceived() ? "MATCHED" : "UNMATCHED").append(SEPARATOR); 306 stringBuffer.append(subject).append(SEPARATOR); 307 stringBuffer.append(sender).append(SEPARATOR); 308 stringBuffer.append(senderMailAddress).append(SEPARATOR); 309 stringBuffer.append(receiver).append(SEPARATOR); 310 stringBuffer.append(receiverMailAddress).append(SEPARATOR); 311 stringBuffer.append(timeSendStart).append(SEPARATOR); 312 stringBuffer.append(timeSendEnd).append(SEPARATOR); 313 stringBuffer.append(byteSendText).append(SEPARATOR); 314 stringBuffer.append(byteSendBinary).append(SEPARATOR); 315 stringBuffer.append(byteReceivedText).append(SEPARATOR); 316 stringBuffer.append(byteReceivedBinary).append(SEPARATOR); 317 stringBuffer.append(byteReceivedTotal).append(SEPARATOR); 318 stringBuffer.append(errorNumberSending).append(SEPARATOR); 319 stringBuffer.append(errorTextSending).append(SEPARATOR); 320 stringBuffer.append(timeReceived).append(SEPARATOR); 321 stringBuffer.append(timeFetchStart).append(SEPARATOR); 322 stringBuffer.append(timeFetchEnd).append(SEPARATOR); 323 stringBuffer.append(timeServerReceived).append(SEPARATOR); 324 stringBuffer.append(receivingQueue).append(SEPARATOR); 325 stringBuffer.append(isReceivedValid).append(SEPARATOR); 326 stringBuffer.append("\r\n"); 327 328 return stringBuffer; 329 } 330 331 }