1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ksb.testclient1;
17
18 import java.util.HashMap;
19 import java.util.Map;
20
21 import org.kuali.rice.ksb.messaging.remotedservices.Inbox;
22 import org.kuali.rice.ksb.messaging.remotedservices.Message;
23
24
25
26
27
28
29
30 public class Storage {
31
32 public Map<String, Inbox> inboxes;
33 public Map<String, Message> messages;
34
35 private int lastInboxId;
36 private int lastMessageId;
37
38 public Storage() {
39 inboxes = new HashMap<String, Inbox>();
40 messages = new HashMap<String, Message>();
41 lastInboxId = 0;
42 lastMessageId = 0;
43 }
44
45 public synchronized Inbox storeInbox(Inbox inbox) {
46 String id = inbox.getId();
47 if (id == null) {
48 lastInboxId++;
49 id = String.valueOf(lastInboxId);
50 inbox.setId(id);
51 }
52 inboxes.put(id, inbox);
53 return inbox;
54 }
55
56 public synchronized Message storeMessage(Message message) {
57 String id = message.getId();
58 if (id == null) {
59 lastMessageId++;
60 id = String.valueOf(lastMessageId);
61 message.setId(id);
62 }
63 messages.put(id, message);
64 return message;
65 }
66
67 public Inbox retrieveInbox(String id) {
68 return inboxes.get(id);
69 }
70
71 public Message retrieveMessage(String id) {
72 return messages.get(id);
73 }
74
75 public synchronized Inbox deleteInbox(String id) {
76 return inboxes.remove(id);
77 }
78
79 public synchronized Message deleteMessage(String id) {
80 return messages.remove(id);
81 }
82 }