1 21 22 package com.rift.coad.daemon.messageservice.message; 24 25 import java.util.ArrayList ; 27 import java.util.Date ; 28 import java.util.Enumeration ; 29 import java.util.List ; 30 import java.util.Properties ; 31 32 import com.rift.coad.daemon.messageservice.InvalidMessageType; 34 import com.rift.coad.daemon.messageservice.InvalidProperty; 35 import com.rift.coad.daemon.messageservice.Message; 36 import com.rift.coad.daemon.messageservice.MessageError; 37 import com.rift.coad.daemon.messageservice.MessageServiceException; 38 import com.rift.coad.lib.common.ObjectSerializer; 39 40 45 public abstract class MessageImpl implements Message, Cloneable { 46 47 private String messageId = null; 49 private Date created = null; 50 private int retries = 0; 51 private Date processedDate = null; 52 private Date nextProcessDate = null; 53 private String sessionId = null; 54 private String user = null; 55 private List principals = null; 56 private String from = null; 57 private int messageType = 0; 58 private String target = null; 59 private String [] services = null; 60 private String replyTo = null; 61 private String targetNamedQueue = null; 62 private String replyNamedQueue = null; 63 private boolean reply = false; 64 private int priority = 0; 65 private String correlationId = null; 66 private Properties properties = new Properties (); 67 private boolean acknowledged = false; 68 private int status = 0; 69 private List errors = new ArrayList (); 70 71 80 public MessageImpl(String messageId, String user, String sessionId, 81 List principals, int status) { 82 this.messageId = messageId; 83 this.created = new Date (); 84 this.processedDate = new Date (); 85 this.user = user; 86 this.sessionId = sessionId; 87 this.principals = principals; 88 this.status = status; 89 } 90 91 92 105 public MessageImpl(String messageId, Date created, int retries, 106 Date processedDate,String user,String sessionId, List principals, 107 String from, int messageType, int status) { 108 this.messageId = messageId; 109 this.created = created; 110 this.retries = retries; 111 this.processedDate = processedDate; 112 this.user = user; 113 this.sessionId = sessionId; 114 this.principals = principals; 115 this.from = from; 116 this.messageType = messageType; 117 this.status = status; 118 } 119 120 121 126 public String getMessageId() { 127 return messageId; 128 } 129 130 135 public void setMessageId(String messageId) { 136 this.messageId = messageId; 137 } 138 139 140 145 public Date getCreated() { 146 return created; 147 } 148 149 150 155 public int getRetries() { 156 return retries; 157 } 158 159 160 163 public void incrementRetries() { 164 retries++; 165 } 166 167 168 171 public Date getProcessedDate() { 172 return processedDate; 173 } 174 175 176 181 public void setProcessedDate(Date processedDate) { 182 this.processedDate = processedDate; 183 } 184 185 186 189 public Date getNextProcessDate() { 190 return this.nextProcessDate; 191 } 192 193 194 199 public void setNextProcessDate(Date nextProcessDate) { 200 this.nextProcessDate = nextProcessDate; 201 } 202 203 204 207 public String getMessageCreater() { 208 return user; 209 } 210 211 212 218 public String getSessionId() { 219 return sessionId; 220 } 221 222 223 228 public List getMessagePrincipals() { 229 return principals; 230 } 231 232 233 238 public void setMessagePrincipals(List principals) { 239 this.principals = principals; 240 } 241 242 243 248 public int getMessageType() { 249 return messageType; 250 } 251 252 253 258 public void setMessageType(int messageType) { 259 this.messageType = messageType; 260 } 261 262 269 public String getTarget() throws MessageServiceException, 270 InvalidMessageType { 271 return target; 272 } 273 274 281 public void setTarget(String target) throws MessageServiceException, 282 InvalidMessageType { 283 this.target = target; 284 } 285 286 287 294 public String [] getServices() throws MessageServiceException, 295 InvalidMessageType { 296 return services; 297 } 298 299 300 307 public void setServices(String [] services) throws MessageServiceException, 308 InvalidMessageType { 309 this.services = services; 310 } 311 312 313 319 public String getFrom() throws MessageServiceException { 320 return from; 321 } 322 323 324 330 public void setFrom(String from) throws MessageServiceException { 331 this.from = from; 332 } 333 334 335 342 public String getReplyTo() throws MessageServiceException { 343 return replyTo; 344 } 345 346 347 354 public void setReplyTo(String replyTo) throws MessageServiceException { 355 this.replyTo = replyTo; 356 } 357 358 359 366 public String getTargetNamedQueue() throws MessageServiceException { 367 return targetNamedQueue; 368 } 369 370 371 378 public void setTargetNamedQueue(String name) throws MessageServiceException { 379 this.targetNamedQueue = name; 380 } 381 382 383 390 public String getReplyNamedQueue() throws MessageServiceException { 391 return replyNamedQueue; 392 } 393 394 395 402 public void setReplyNamedQueue(String name) throws MessageServiceException { 403 this.replyNamedQueue = name; 404 } 405 406 407 414 public boolean getReply() throws MessageServiceException { 415 return reply; 416 } 417 418 419 425 public void setReply(boolean value) throws MessageServiceException { 426 this.reply = value; 427 } 428 429 430 436 public int getPriority() { 437 return priority; 438 } 439 440 441 447 public void setPriority(int priority) throws MessageServiceException { 448 this.priority = priority; 449 } 450 451 452 459 public void setCorrelationId(String id) throws MessageServiceException { 460 this.correlationId = id; 461 } 462 463 464 470 public String getCorrelationId() throws MessageServiceException { 471 return correlationId; 472 } 473 474 475 480 public abstract void clearBody() throws MessageServiceException; 481 482 483 488 public void clearProperties() throws MessageServiceException { 489 properties.clear(); 490 } 491 492 493 500 public boolean containsProperty(String name) throws MessageServiceException { 501 return properties.containsKey(name); 502 } 503 504 505 513 public boolean getBooleanProperty(String name) throws 514 MessageServiceException, InvalidProperty { 515 if (properties.contains(name)) { 516 throw new InvalidProperty("The property [" + name + "] could not" + 517 "be found."); 518 } 519 Boolean bool = (Boolean )properties.get(name); 520 return bool.booleanValue(); 521 } 522 523 524 532 public byte getByteProperty(String name) throws 533 MessageServiceException, InvalidProperty { 534 if (properties.contains(name)) { 535 throw new InvalidProperty("The property [" + name + "] could not" + 536 "be found."); 537 } 538 Byte byteValue = (Byte )properties.get(name); 539 return byteValue.byteValue(); 540 } 541 542 543 551 public double getDoubleProperty(String name) throws 552 MessageServiceException, InvalidProperty { 553 if (properties.contains(name)) { 554 throw new InvalidProperty("The property [" + name + "] could not" + 555 "be found."); 556 } 557 Double doubleValue = (Double )properties.get(name); 558 return doubleValue.doubleValue(); 559 } 560 561 562 570 public float getFloatProperty(String name) throws 571 MessageServiceException, InvalidProperty { 572 if (properties.contains(name)) { 573 throw new InvalidProperty("The property [" + name + "] could not" + 574 "be found."); 575 } 576 Float floatValue = (Float )properties.get(name); 577 return floatValue.floatValue(); 578 } 579 580 581 589 public int getIntProperty(String name) throws 590 MessageServiceException, InvalidProperty { 591 if (properties.contains(name)) { 592 throw new InvalidProperty("The property [" + name + "] could not" + 593 "be found."); 594 } 595 Integer intValue = (Integer )properties.get(name); 596 return intValue.intValue(); 597 } 598 599 600 608 public long getLongProperty(String name) throws 609 MessageServiceException, InvalidProperty { 610 if (properties.contains(name)) { 611 throw new InvalidProperty("The property [" + name + "] could not" + 612 "be found."); 613 } 614 Long longValue = (Long )properties.get(name); 615 return longValue.longValue(); 616 } 617 618 619 627 public Object getObjectProperty(String name) throws 628 MessageServiceException, InvalidProperty { 629 if (properties.contains(name)) { 630 throw new InvalidProperty("The property [" + name + "] could not" + 631 "be found."); 632 } 633 try { 634 return ObjectSerializer.deserialize((byte[])properties.get(name)); 635 } catch (Exception ex) { 636 throw new MessageServiceException("Failed to retrieve the object " + 637 "value :" + ex.getMessage(),ex); 638 } 639 } 640 641 642 650 public String getStringProperty(String name) throws 651 MessageServiceException, InvalidProperty { 652 if (properties.contains(name)) { 653 throw new InvalidProperty("The property [" + name + "] could not" + 654 "be found."); 655 } 656 return (String )properties.get(name); 657 } 658 659 660 668 public Object getPropertyValue(String name) throws 669 MessageServiceException, InvalidProperty { 670 if (properties.contains(name)) { 671 throw new InvalidProperty("The property [" + name + "] could not" + 672 "be found."); 673 } 674 return properties.get(name); 675 } 676 677 678 684 public Enumeration getPropertyNames() throws MessageServiceException { 685 return properties.propertyNames(); 686 } 687 688 689 696 public boolean propertyExists(String name) throws MessageServiceException { 697 return properties.containsKey(name); 698 } 699 700 701 708 public void setBooleanProperty(String name, boolean value) throws 709 MessageServiceException { 710 properties.put(name, new Boolean (value)); 711 } 712 713 714 721 public void setByteProperty(String name, byte value) throws 722 MessageServiceException { 723 properties.put(name, new Byte (value)); 724 } 725 726 727 734 public void setDoubleProperty(String name, double value) throws 735 MessageServiceException{ 736 properties.put(name, new Double (value)); 737 } 738 739 740 747 public void setFloatProperty(String name, float value) throws 748 MessageServiceException { 749 properties.put(name, new Float (value)); 750 } 751 752 753 760 public void setIntProperty(String name, int value) throws 761 MessageServiceException { 762 properties.put(name, new Integer (value)); 763 } 764 765 766 773 public void setLongProperty(String name, long value) throws 774 MessageServiceException { 775 properties.put(name, new Long (value)); 776 } 777 778 779 787 public void setObjectProperty(String name, Object value) throws 788 MessageServiceException { 789 try { 790 properties.put(name, ObjectSerializer.serialize(value)); 791 } catch (Exception ex) { 792 throw new MessageServiceException("Failed to store the object value :" + 793 ex.getMessage(),ex); 794 } 795 } 796 797 798 805 public void setStringProperty(String name, String value) throws 806 MessageServiceException { 807 properties.put(name, value); 808 } 809 810 811 819 public void setPropertyValue(String name,Object value) throws 820 MessageServiceException, InvalidProperty { 821 properties.put(name, value); 822 } 823 824 830 public void acknowledge() throws MessageServiceException { 831 acknowledged = true; 832 } 833 834 835 841 public boolean isAcknowledged() throws MessageServiceException { 842 return acknowledged; 843 } 844 845 846 852 public int getState() throws MessageServiceException { 853 return status; 854 } 855 856 857 863 public void setState(int status) throws MessageServiceException { 864 this.status = status; 865 } 866 867 868 871 public List getErrors() throws MessageServiceException { 872 return errors; 873 } 874 875 876 882 public void addError(int level, String msg) throws MessageServiceException { 883 errors.add(new MessageError(new Date (),level,msg)); 884 } 885 886 887 892 public void addError(MessageError error) { 893 errors.add(error); 894 } 895 896 897 903 public Object clone() throws CloneNotSupportedException { 904 return super.clone(); 905 } 906 } 907 | Popular Tags |