KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > demo > events > EventProcessor


1 /*
2 @COPYRIGHT@
3 */

4 package demo.events;
5
6 import java.util.ArrayList JavaDoc;
7 import java.util.List JavaDoc;
8 import org.springframework.context.ApplicationEvent;
9 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
16    implements ApplicationListener
17 {
18    private static final int MAX_EVENTS = 15;
19    private transient List JavaDoc events = new ArrayList JavaDoc();
20
21    public void onApplicationEvent(ApplicationEvent event)
22    {
23       if (event instanceof MessageEvent)
24       {
25          synchronized (events)
26          {
27             events.add(0, event);
28             if (events.size() > MAX_EVENTS) events.remove(events.size() - 1);
29          }
30       }
31    }
32
33    public List JavaDoc getEvents()
34    {
35       synchronized(events)
36       {
37          return new ArrayList JavaDoc(events);
38       }
39    }
40 }
41
Popular Tags