KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tctest > spring > bean > EventManagerImpl


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

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 JavaDoc;
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 JavaDoc source, String JavaDoc 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 JavaDoc source, String JavaDoc message) {
36     ctx.publishEvent(new NonDistributedSingletonEvent(source, message));
37   }
38   
39   public void clear() {
40     listener.getEvents().clear();
41   }
42
43   public Date JavaDoc getLastEventTime() {
44     return listener.getLastEventTime();
45   }
46
47 }
48
Popular Tags