1 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 ; 10 import java.util.Properties ; 11 import java.util.Vector ; 12 13 19 public class EventSourceManager { 20 private static Vector eventSources = new Vector (0); 21 private static final String PROPERTIES_RESOURCE = "sources.properties"; 22 23 26 public static void start() { 27 Log.info("EventSourceManager: start"); 29 30 Properties properties = null; 31 32 try { 33 properties = Sys.loadPropertiesResource(PROPERTIES_RESOURCE); 34 } catch (Throwable 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 eventSources = new Vector (properties.size()); 42 43 for (Enumeration e = properties.keys(); e.hasMoreElements();) { 45 String nextKey = (String ) e.nextElement(); 46 String 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 ex) { 53 Log.warn("Cannot create EventSource: class=" + nextClass, ex); 54 } 55 } 56 57 activate(); 58 } 59 60 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 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 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 152 | Popular Tags |