01: package example;
02:
03: import java.io.*;
04: import java.util.*;
05: import javax.jms.*;
06: import javax.ejb.*;
07: import javax.servlet.*;
08: import javax.servlet.http.*;
09:
10: /**
11: * Custom singleton service to store messages
12: */
13: public class MessageStoreService {
14: private LinkedList<String> _messageLog = new LinkedList<String>();
15:
16: public void addMessage(String message) {
17: synchronized (_messageLog) {
18: if (_messageLog.size() > 10)
19: _messageLog.remove(0);
20:
21: _messageLog.add(message);
22: }
23: }
24:
25: public ArrayList<String> getMessages() {
26: synchronized (_messageLog) {
27: return new ArrayList<String>(_messageLog);
28: }
29: }
30: }
|