1 4 package demo.events; 5 6 import java.util.ArrayList ; 7 import java.util.List ; 8 import org.springframework.context.ApplicationEvent; 9 import org.springframework.context.ApplicationListener; 10 11 15 public class EventProcessor 16 implements ApplicationListener 17 { 18 private static final int MAX_EVENTS = 15; 19 private transient List events = new ArrayList (); 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 getEvents() 34 { 35 synchronized(events) 36 { 37 return new ArrayList (events); 38 } 39 } 40 } 41 | Popular Tags |