Author: chris.laprun(a)jboss.com
Date: 2010-08-31 16:20:03 -0400 (Tue, 31 Aug 2010)
New Revision: 3987
Added:
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/SessionEventListenerAndBroadcaster.java
Modified:
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/WSRPServiceIntegration.java
Log:
- GTNPORTAL-1452, GTNWSRP-65: Use ListenerService to register
SessionEventListenerAndBroadcaster for session creation and destruction events.
Added:
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/SessionEventListenerAndBroadcaster.java
===================================================================
---
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/SessionEventListenerAndBroadcaster.java
(rev 0)
+++
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/SessionEventListenerAndBroadcaster.java 2010-08-31
20:20:03 UTC (rev 3987)
@@ -0,0 +1,109 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.portal.wsrp;
+
+import org.exoplatform.container.PortalContainer;
+import org.exoplatform.services.listener.Event;
+import org.exoplatform.services.listener.Listener;
+import org.gatein.wsrp.api.SessionEvent;
+import org.gatein.wsrp.api.SessionEventBroadcaster;
+import org.gatein.wsrp.api.SessionEventListener;
+
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionEvent;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class SessionEventListenerAndBroadcaster extends Listener<PortalContainer,
HttpSessionEvent> implements SessionEventBroadcaster
+{
+ private Map<String, SessionEventListener> listeners = new
ConcurrentHashMap<String, SessionEventListener>();
+ private static final String SESSION_CREATED =
"org.exoplatform.web.GenericHttpListener.sessionCreated";
+ private static final String SESSION_DESTROYED =
"org.exoplatform.web.GenericHttpListener.sessionDestroyed";
+
+ public void registerListener(String listenerId, SessionEventListener listener)
+ {
+ listeners.put(listenerId, listener);
+ }
+
+ public void unregisterListener(String listenerId)
+ {
+ listeners.remove(listenerId);
+ }
+
+ public void notifyListenersOf(SessionEvent event)
+ {
+ for (SessionEventListener listener : listeners.values())
+ {
+ listener.onSessionEvent(event);
+ }
+ }
+
+ @Override
+ public void onEvent(Event<PortalContainer, HttpSessionEvent> event) throws
Exception
+ {
+ String eventName = event.getEventName();
+ SessionEvent.SessionEventType eventType;
+ if (SESSION_CREATED.equals(eventName))
+ {
+ eventType = SessionEvent.SessionEventType.SESSION_CREATED;
+ }
+ else if (SESSION_DESTROYED.equals(eventName))
+ {
+ eventType = SessionEvent.SessionEventType.SESSION_DESTROYED;
+ }
+ else
+ {
+ // do nothing
+ return;
+ }
+
+ notifyListenersOf(new SimpleSessionEvent(eventType,
event.getData().getSession()));
+ }
+
+ private static class SimpleSessionEvent implements SessionEvent
+ {
+ private SessionEventType eventType;
+ private HttpSession session;
+
+ private SimpleSessionEvent(SessionEventType eventType, HttpSession session)
+ {
+ this.eventType = eventType;
+ this.session = session;
+ }
+
+ public SessionEventType getType()
+ {
+ return eventType;
+ }
+
+ public HttpSession getSession()
+ {
+ return session;
+ }
+ }
+}
Modified:
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/WSRPServiceIntegration.java
===================================================================
---
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/WSRPServiceIntegration.java 2010-08-31
20:15:12 UTC (rev 3986)
+++
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/WSRPServiceIntegration.java 2010-08-31
20:20:03 UTC (rev 3987)
@@ -28,6 +28,7 @@
import org.exoplatform.container.configuration.ConfigurationManager;
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.services.jcr.ext.hierarchy.NodeHierarchyCreator;
+import org.exoplatform.services.listener.ListenerService;
import org.gatein.common.logging.Logger;
import org.gatein.common.logging.LoggerFactory;
import org.gatein.pc.api.PortletInvoker;
@@ -53,9 +54,6 @@
import org.gatein.wci.WebAppListener;
import org.gatein.wci.impl.DefaultServletContainerFactory;
import org.gatein.wsrp.WSRPConstants;
-import org.gatein.wsrp.api.SessionEvent;
-import org.gatein.wsrp.api.SessionEventBroadcaster;
-import org.gatein.wsrp.api.SessionEventListener;
import org.gatein.wsrp.consumer.registry.ActivatingNullInvokerHandler;
import org.gatein.wsrp.consumer.registry.ConsumerRegistry;
import org.gatein.wsrp.producer.ProducerHolder;
@@ -65,8 +63,6 @@
import javax.servlet.ServletContext;
import java.io.InputStream;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
@@ -218,11 +214,19 @@
FederatingPortletInvoker federatingPortletInvoker =
(FederatingPortletInvoker)container.getComponentInstanceOfType(PortletInvoker.class);
+ // add our Session event listener to the ListenerService for use in
org.exoplatform.web.GenericHttpListener
+ ListenerService listenerService =
(ListenerService)container.getComponentInstanceOfType(ListenerService.class);
+ SessionEventListenerAndBroadcaster sessionEventBroadcaster = new
SessionEventListenerAndBroadcaster();
+
sessionEventBroadcaster.setName("org.exoplatform.web.GenericHttpListener.sessionCreated");
+ listenerService.addListener(sessionEventBroadcaster);
+
sessionEventBroadcaster.setName("org.exoplatform.web.GenericHttpListener.sessionDestroyed");
+ listenerService.addListener(sessionEventBroadcaster);
+
try
{
consumerRegistry = new JCRConsumerRegistry(container);
consumerRegistry.setFederatingPortletInvoker(federatingPortletInvoker);
- consumerRegistry.setSessionEventBroadcaster(new
SimpleSessionEventBroadcaster());
+ consumerRegistry.setSessionEventBroadcaster(sessionEventBroadcaster);
consumerRegistry.start();
// set up a NullInvokerHandler so that when a remote producer is queried, we can
start it if needed
@@ -298,27 +302,4 @@
}
}
- private static class SimpleSessionEventBroadcaster implements SessionEventBroadcaster
- {
- private Map<String, SessionEventListener> listeners = new
ConcurrentHashMap<String, SessionEventListener>();
-
- public void registerListener(String listenerId, SessionEventListener listener)
- {
- listeners.put(listenerId, listener);
- }
-
- public void unregisterListener(String listenerId)
- {
- listeners.remove(listenerId);
- }
-
- public void notifyListenersOf(SessionEvent event)
- {
- for (SessionEventListener listener : listeners.values())
- {
- listener.onSessionEvent(event);
- }
- }
-
- }
-}
+}
\ No newline at end of file