01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04:
05: package com.tctest.spring.bean;
06:
07: import org.springframework.context.ApplicationEvent;
08: import org.springframework.context.ApplicationListener;
09:
10: import java.util.ArrayList;
11: import java.util.Date;
12: import java.util.List;
13:
14: public class SimpleListener implements ApplicationListener {
15: private transient List events = new ArrayList();
16: private Date lastEventTime;
17:
18: public int size() {
19: synchronized (events) {
20: return events.size();
21: }
22: }
23:
24: public void clear() {
25: synchronized (events) {
26: events.clear();
27: }
28: }
29:
30: // ApplicationListener
31:
32: public void onApplicationEvent(ApplicationEvent event) {
33: if (event instanceof SingletonEvent) {
34: System.out.println("Got SingletonEvent: " + event);
35: synchronized (events) {
36: this .events.add(event);
37: }
38: this .lastEventTime = new Date();
39: } else {
40: System.out
41: .println("Got some other kind of event: " + event);
42: }
43: }
44:
45: public Date getLastEventTime() {
46: return lastEventTime;
47: }
48: }
|