KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > daemon > messageservice > MessageStoreImpl


1 /*
2  * MessageService: The message service daemon
3  * Copyright (C) 2007 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * MessageStoreImpl.java
20  */

21
22 // package path
23
package com.rift.coad.daemon.messageservice;
24
25 // java imports
26
import java.rmi.Remote JavaDoc;
27 import java.rmi.RemoteException JavaDoc;
28 import java.util.Date JavaDoc;
29
30 // logging import
31
import org.apache.log4j.Logger;
32
33 // coadunation imports
34
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 /**
41  * This class is responsible for implementing the message store interface.
42  *
43  * @author Brett Chaldecott
44  */

45 public class MessageStoreImpl implements MessageStore {
46     
47     // the logger reference
48
protected static Logger log =
49             Logger.getLogger(MessageStoreImpl.class.getName());
50     
51     /**
52      * Creates a new instance of MessageStoreImpl
53      */

54     public MessageStoreImpl() {
55     }
56     
57     
58     /**
59      * This method adds a message to the message store of a message service.
60      *
61      * @param message The message to add to the store.
62      * @exception MessageServiceException
63      * @exception RemoteException
64      */

65     public void addMessage(Message newMessage) throws MessageServiceException,
66             RemoteException JavaDoc {
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 JavaDoc());
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 JavaDoc 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