1 21 22 package com.rift.coad.daemon.messageservice; 24 25 import java.rmi.Remote ; 27 import java.rmi.RemoteException ; 28 import java.util.Date ; 29 30 import org.apache.log4j.Logger; 32 33 import com.rift.coad.daemon.messageservice.message.MessageImpl; 35 import com.rift.coad.daemon.messageservice.message.RPCMessageImpl; 36 import com.rift.coad.daemon.messageservice.message.TextMessageImpl; 37 import com.rift.coad.daemon.messageservice.message.MessageManagerFactory; 38 import com.rift.coad.daemon.messageservice.message.MessageManagerImpl; 39 40 45 public class MessageStoreImpl implements MessageStore { 46 47 protected static Logger log = 49 Logger.getLogger(MessageStoreImpl.class.getName()); 50 51 54 public MessageStoreImpl() { 55 } 56 57 58 65 public void addMessage(Message newMessage) throws MessageServiceException, 66 RemoteException { 67 if ((newMessage instanceof RPCMessage) && 68 (((RPCMessage)newMessage).getMethodBodyXML() == null)) { 69 throw new MessageServiceException("The xml body is not set"); 70 } else if ((newMessage instanceof TextMessage) && 71 (((TextMessage)newMessage).getTextBody() == null)) { 72 throw new MessageServiceException("The text body is not set"); 73 } 74 try { 75 log.debug("Receive message : " + newMessage.getMessageId()); 76 IDLock.getInstance().lock(newMessage.getMessageId()); 77 ((MessageImpl)newMessage).setNextProcessDate(new Date ()); 78 MessageManager messageManager = MessageManagerFactory.getInstance(). 79 getMessageManager(newMessage); 80 MessageQueue messageQueue = MessageQueueManager.getInstance(). 81 getQueue(MessageQueueManager.UNSORTED); 82 ((MessageManagerImpl)messageManager).assignToQueue( 83 MessageQueueManager.UNSORTED); 84 messageQueue.addMessage(messageManager); 85 log.debug("Message added : " + newMessage.getMessageId()); 86 } catch (Exception ex) { 87 log.error("Failed to add the message : " + 88 ex.getMessage(),ex); 89 throw new MessageServiceException("Failed to add the message : " + 90 ex.getMessage(),ex); 91 } 92 } 93 } 94 | Popular Tags |