Author: abelevich
Date: 2009-07-29 14:11:06 -0400 (Wed, 29 Jul 2009)
New Revision: 15047
Added:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/event/CacheInitializationListener.java
root/framework/trunk/impl/src/main/java/org/ajax4jsf/event/InitializationListener.java
Log:
Added:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/event/CacheInitializationListener.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/ajax4jsf/event/CacheInitializationListener.java
(rev 0)
+++
root/framework/trunk/impl/src/main/java/org/ajax4jsf/event/CacheInitializationListener.java 2009-07-29
18:11:06 UTC (rev 15047)
@@ -0,0 +1,59 @@
+package org.ajax4jsf.event;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import javax.faces.context.FacesContext;
+import javax.faces.event.SystemEvent;
+
+import org.ajax4jsf.cache.Cache;
+import org.ajax4jsf.cache.CacheFactory;
+import org.ajax4jsf.cache.CacheManager;
+
+/**
+ * @author Anton Belevich
+ *
+ */
+public class CacheInitializationListener extends InitializationListener {
+
+ @Override
+ public void init(SystemEvent event) {
+
+// CacheManager cacheManager = CacheManager.getInstance();
+// FacesContext facesContext = FacesContext.getCurrentInstance();
+//
+// Map<?,?> envMap = facesContext.getExternalContext().getInitParameterMap();
+// CacheFactory cacheFactory = cacheManager.getCacheFactory(envMap);
+// Cache cache = cacheFactory.createCache(envMap);
+//
+// if(cache != null) {
+// String cacheName = cache.getClass().getName();
+// cacheManager.registerCache(cacheName, cache);
+// cache.start();
+// }
+//
+ }
+
+ //stop and remove all caches instances
+ @Override
+ public void destroy(SystemEvent event) {
+
+ CacheManager cacheManager = CacheManager.getInstance();
+ Map <String, Cache> caches = cacheManager.getCaches();
+ System.out.println("CacheInitializationListener.destroy()");
+ if(!caches.isEmpty()) {
+
+ Iterator <Map.Entry<String, Cache>> iterator =
caches.entrySet().iterator();
+ while(iterator.hasNext()) {
+ Entry <String, Cache> entry = iterator.next();
+ Cache cache = entry.getValue();
+ cache.stop();
+ iterator.remove();
+ }
+
+ }
+
+ }
+}
Added:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/event/InitializationListener.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/ajax4jsf/event/InitializationListener.java
(rev 0)
+++
root/framework/trunk/impl/src/main/java/org/ajax4jsf/event/InitializationListener.java 2009-07-29
18:11:06 UTC (rev 15047)
@@ -0,0 +1,34 @@
+package org.ajax4jsf.event;
+
+import javax.faces.application.Application;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.PostConstructApplicationEvent;
+import javax.faces.event.PreDestroyApplicationEvent;
+import javax.faces.event.SystemEvent;
+import javax.faces.event.SystemEventListener;
+
+/**
+ * framework initialization listener
+ * @author Anton Belevich
+ *
+ */
+public abstract class InitializationListener implements SystemEventListener {
+
+
+ public boolean isListenerForSource(Object source) {
+ return source instanceof Application ? true : false;
+ }
+
+ public void processEvent(SystemEvent event) throws AbortProcessingException {
+ if(event instanceof PostConstructApplicationEvent) {
+ init(event);
+ } else if(event instanceof PreDestroyApplicationEvent) {
+ destroy(event);
+ }
+ }
+
+ public abstract void init(SystemEvent event);
+
+ public abstract void destroy(SystemEvent event);
+
+}
Show replies by date