KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nl > justobjects > pushlet > core > EventSourceManager


1 // Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>
2
// Distributable under LGPL license. See terms of license at gnu.org.
3

4 package nl.justobjects.pushlet.core;
5
6 import nl.justobjects.pushlet.util.Log;
7 import nl.justobjects.pushlet.util.Sys;
8
9 import java.util.Enumeration JavaDoc;
10 import java.util.Properties JavaDoc;
11 import java.util.Vector JavaDoc;
12
13 /**
14  * Maintains lifecycle of event sources.
15  *
16  * @version $Id: EventSourceManager.java,v 1.13 2005/02/21 11:50:46 justb Exp $
17  * @author Just van den Broecke - Just Objects &copy;
18  **/

19 public class EventSourceManager {
20     private static Vector JavaDoc eventSources = new Vector JavaDoc(0);
21     private static final String JavaDoc PROPERTIES_RESOURCE = "sources.properties";
22
23     /**
24      * Initialize event sources from properties file.
25      */

26     public static void start() {
27         // Load Event sources using properties file.
28
Log.info("EventSourceManager: start");
29
30         Properties JavaDoc properties = null;
31
32         try {
33             properties = Sys.loadPropertiesResource(PROPERTIES_RESOURCE);
34         } catch (Throwable JavaDoc t) {
35             Log.warn("EventSourceManager: cannot find properties file: " + PROPERTIES_RESOURCE, t);
36             Log.warn("EventSourceManager: not starting local event sources (maybe that is what you want)");
37             return;
38         }
39
40         // Create event source collection
41
eventSources = new Vector JavaDoc(properties.size());
42
43         // Add the configured sources
44
for (Enumeration JavaDoc e = properties.keys(); e.hasMoreElements();) {
45             String JavaDoc nextKey = (String JavaDoc) e.nextElement();
46             String JavaDoc nextClass = properties.getProperty(nextKey);
47             EventSource nextEventSource = null;
48             try {
49                 nextEventSource = (EventSource) Class.forName(nextClass).newInstance();
50                 Log.info("created EventSource: key=" + nextKey + " class=" + nextClass);
51                 eventSources.addElement(nextEventSource);
52             } catch (Exception JavaDoc ex) {
53                 Log.warn("Cannot create EventSource: class=" + nextClass, ex);
54             }
55         }
56
57         activate();
58     }
59
60     /** Activate all event sources. */
61     public static void activate() {
62         Log.info("Activating " + eventSources.size() + " EventSources");
63         for (int i = 0; i < eventSources.size(); i++) {
64             ((EventSource) eventSources.elementAt(i)).activate();
65         }
66         Log.info("EventSources activated");
67     }
68
69     /** Deactivate all event sources. */
70     public static void passivate() {
71         Log.info("Passivating " + eventSources.size() + " EventSources");
72         for (int i = 0; i < eventSources.size(); i++) {
73             ((EventSource) eventSources.elementAt(i)).passivate();
74         }
75         Log.info("EventSources passivated");
76     }
77
78     /**
79      * Halt event sources.
80      */

81     public static void stop() {
82         Log.info("Stopping " + eventSources.size() + " EventSources...");
83         for (int i = 0; i < eventSources.size(); i++) {
84             ((EventSource) eventSources.elementAt(i)).stop();
85         }
86         Log.info("EventSources stopped");
87     }
88
89 }
90
91 /*
92  * $Log: EventSourceManager.java,v $
93  * Revision 1.13 2005/02/21 11:50:46 justb
94  * ohase1 of refactoring Subscriber into Session/Controller/Subscriber
95  *
96  * Revision 1.12 2005/02/18 12:36:47 justb
97  * changes for renaming and configurability
98  *
99  * Revision 1.11 2005/02/18 10:07:23 justb
100  * many renamings of classes (make names compact)
101  *
102  * Revision 1.10 2005/02/15 13:29:49 justb
103  * use Sys.loadPropertiesResource()
104  *
105  * Revision 1.9 2004/09/20 22:01:38 justb
106  * more changes for new protocol
107  *
108  * Revision 1.8 2004/09/03 22:35:37 justb
109  * Almost complete rewrite, just checking in now
110  *
111  * Revision 1.7 2004/08/15 16:00:15 justb
112  * enhancements to pull mode
113  *
114  * Revision 1.6 2004/08/13 23:36:05 justb
115  * rewrite of Pullet into Pushlet "pull" mode
116  *
117  * Revision 1.5 2004/08/12 13:18:54 justb
118  * cosmetic changes
119  *
120  * Revision 1.4 2003/08/15 08:37:40 justb
121  * fix/add Copyright+LGPL file headers and footers
122  *
123  * Revision 1.3 2003/08/12 09:41:35 justb
124  * replace static initalizer with explicit init()
125  *
126  * Revision 1.2 2003/05/18 16:15:08 justb
127  * support for XML encoded Events
128  *
129  * Revision 1.1.1.1 2002/09/24 21:02:31 justb
130  * import to sourceforge
131  *
132  * Revision 1.1.1.1 2002/09/20 22:48:17 justb
133  * import to SF
134  *
135  * Revision 1.1.1.1 2002/09/20 14:19:03 justb
136  * first import into SF
137  *
138  * Revision 1.5 2002/04/15 20:42:41 just
139  * reformatting and renaming GuardedQueue to EventQueue
140  *
141  * Revision 1.4 2000/10/30 14:15:47 just
142  * no message
143  *
144  * Revision 1.3 2000/08/31 08:26:54 just
145  * Changed classloader that loads eventsources.properties to use EventSourceManager's classloader
146  *
147  * Revision 1.2 2000/08/21 20:48:29 just
148  * added CVS log and id tags plus copyrights
149  *
150  *
151  */

152
Popular Tags