1 4 package com.tctest.spring.bean; 5 6 import org.springframework.beans.BeansException; 7 import org.springframework.context.ApplicationContext; 8 import org.springframework.context.ApplicationContextAware; 9 10 import java.util.Date ; 11 12 public class EventManagerImpl implements EventManager, ApplicationContextAware { 13 14 private SimpleListener listener; 15 private ApplicationContext ctx; 16 17 public EventManagerImpl(SimpleListener listener) { 18 this.listener = listener; 19 } 20 21 public void setApplicationContext(ApplicationContext ctx) throws BeansException { 22 this.ctx = ctx; 23 } 24 25 public int size() { 26 return listener.getEvents().size(); 27 } 28 29 public void publishEvents(Object source, String message, int count) { 30 for (int i = 0; i < count; i++) { 31 ctx.publishEvent(new DistributedSingletonEvent(source, message + "[" + i + "]")); 32 } 33 } 34 35 public void publishLocalEvent(Object source, String message) { 36 ctx.publishEvent(new NonDistributedSingletonEvent(source, message)); 37 } 38 39 public void clear() { 40 listener.getEvents().clear(); 41 } 42 43 public Date getLastEventTime() { 44 return listener.getLastEventTime(); 45 } 46 47 } 48 | Popular Tags |