01: /*
02: @COPYRIGHT@
03: */
04: package demo.events;
05:
06: import java.util.ArrayList;
07: import java.util.List;
08: import org.springframework.context.ApplicationEvent;
09: import org.springframework.context.ApplicationListener;
10:
11: /**
12: * Simple event processor, keeps track of the last {@link MAX_EVENTS} Spring application events of type
13: * {@link MessageEvent}.
14: */
15: public class EventProcessor implements ApplicationListener {
16: private static final int MAX_EVENTS = 15;
17: private transient List events = new ArrayList();
18:
19: public void onApplicationEvent(ApplicationEvent event) {
20: if (event instanceof MessageEvent) {
21: synchronized (events) {
22: events.add(0, event);
23: if (events.size() > MAX_EVENTS)
24: events.remove(events.size() - 1);
25: }
26: }
27: }
28:
29: public List getEvents() {
30: synchronized (events) {
31: return new ArrayList(events);
32: }
33: }
34: }
|