01 /**
02 *
03 * All content copyright (c) 2003-2008 Terracotta, Inc.,
04 * except as may otherwise be noted in a separate copyright notice.
05 * All rights reserved.
06 *
07 */
08 package demo.events;
09
10 import java.util.ArrayList;
11 import java.util.List;
12 import org.springframework.context.ApplicationEvent;
13 import org.springframework.context.ApplicationListener;
14
15 /**
16 * Simple event processor, keeps track of the last {@link MAX_EVENTS} Spring
17 * application events of type {@link MessageEvent}.
18 *
19 *@author Terracotta, Inc.
20 */
21 public class EventProcessor
22 implements ApplicationListener {
23 private transient List events = new ArrayList();
24 private static final int MAX_EVENTS = 15;
25
26 public List getEvents() {
27 synchronized (events) {
28 return new ArrayList(events);
29 }
30 }
31
32 public void onApplicationEvent(ApplicationEvent event) {
33 if (event instanceof MessageEvent) {
34 synchronized (events) {
35 events.add(0, event);
36 if (events.size() > MAX_EVENTS) {
37 events.remove(events.size() - 1);
38 }
39 }
40 }
41 }
42 }
|