Author: chris.laprun(a)jboss.com
Date: 2007-04-10 17:59:28 -0400 (Tue, 10 Apr 2007)
New Revision: 6968
Removed:
trunk/wsrp/src/main/org/jboss/portal/wsrp/servlet/ReleaseSessionsSessionListener.java
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/support/MockWSRPConsumer.java
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/ProducerSessionInformationTestCase.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPConsumer.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistryService.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerSessionInformation.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/SessionHandler.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/handler/RequestHeaderClientHandler.java
trunk/wsrp/src/resources/portal-wsrp-sar/META-INF/jboss-service.xml
Log:
- JBPORTAL-1252: Moved listener to SessionHandler, which is now un/registered when the
associated consumer is stopped/started by ConsumerRegistryService.
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/support/MockWSRPConsumer.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/support/MockWSRPConsumer.java 2007-04-10
15:07:10 UTC (rev 6967)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/support/MockWSRPConsumer.java 2007-04-10
21:59:28 UTC (rev 6968)
@@ -23,6 +23,7 @@
package org.jboss.portal.test.wsrp.framework.support;
+import org.jboss.portal.api.event.PortalEvent;
import org.jboss.portal.portlet.Portlet;
import org.jboss.portal.portlet.PortletContext;
import org.jboss.portal.portlet.PortletInvokerException;
@@ -158,4 +159,8 @@
public void destroy()
{
}
+
+ public void onEvent(PortalEvent event)
+ {
+ }
}
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/ProducerSessionInformationTestCase.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/ProducerSessionInformationTestCase.java 2007-04-10
15:07:10 UTC (rev 6967)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/ProducerSessionInformationTestCase.java 2007-04-10
21:59:28 UTC (rev 6968)
@@ -187,6 +187,28 @@
}
}
+ public void testSetParentSessionId()
+ {
+ assertNull(info.getParentSessionId());
+
+ String id = "session";
+ info.setParentSessionId(id);
+ assertEquals(id, info.getParentSessionId());
+
+ // trying to set the same id should work
+ info.setParentSessionId(id);
+
+ try
+ {
+ info.setParentSessionId("other");
+ fail("Cannot modify session id once it has been set");
+ }
+ catch (IllegalStateException expected)
+ {
+ // expected
+ }
+ }
+
private Cookie createCookie(String name, String value, int secondsBeforeExpiration)
{
return new Cookie("domain", name, value, "path",
secondsBeforeExpiration, false);
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPConsumer.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPConsumer.java 2007-04-10 15:07:10 UTC
(rev 6967)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPConsumer.java 2007-04-10 21:59:28 UTC
(rev 6968)
@@ -22,6 +22,7 @@
******************************************************************************/
package org.jboss.portal.wsrp;
+import org.jboss.portal.api.event.PortalEventListener;
import org.jboss.portal.portlet.PortletInvoker;
import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.portlet.invocation.PortletInvocation;
@@ -38,7 +39,7 @@
* @version $Revision$
* @since 2.4
*/
-public interface WSRPConsumer extends PortletInvoker, Service
+public interface WSRPConsumer extends PortletInvoker, Service, PortalEventListener
{
/**
* Retrieves the identifier for the producer this consumer is associated with.
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistryService.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistryService.java 2007-04-10
15:07:10 UTC (rev 6967)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistryService.java 2007-04-10
21:59:28 UTC (rev 6968)
@@ -27,6 +27,7 @@
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.jboss.portal.common.util.ParameterValidation;
+import org.jboss.portal.core.event.PortalEventListenerRegistry;
import org.jboss.portal.jems.as.system.AbstractJBossService;
import org.jboss.portal.portlet.PortletInvoker;
import org.jboss.portal.portlet.PortletInvokerException;
@@ -57,13 +58,21 @@
private String sessionFactoryJNDIName;
+ private PortalEventListenerRegistry portalEventListenerRegistry;
+
private static final String CONSUMER_WITH_ID = "Consumer with id '";
+ private static final String RELEASE_SESSIONS_LISTENER =
"release_sessions_listener_";
public FederatingPortletInvoker getFederatingPortletInvoker()
{
return federatingPortletInvoker;
}
+ public void setPortalEventListenerRegistry(PortalEventListenerRegistry
portalEventListenerRegistry)
+ {
+ this.portalEventListenerRegistry = portalEventListenerRegistry;
+ }
+
public WSRPConsumer createConsumer(String id, Integer expirationCacheSeconds)
{
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(id, "Consumer
identifier", "createConsumer");
@@ -307,6 +316,7 @@
}
federatingPortletInvoker.registerInvoker(id, consumer);
+ portalEventListenerRegistry.registerListener(getListenerIdFrom(id),
consumer);
consumer.activate();
}
else
@@ -319,6 +329,7 @@
{
consumer = (WSRPConsumer)invoker;
federatingPortletInvoker.unregisterInvoker(id);
+ portalEventListenerRegistry.unregisterListener(getListenerIdFrom(id));
consumer.deactivate();
}
else
@@ -340,4 +351,9 @@
// update ProducerInfo
updateProducerInfo(consumer.getProducerInfo());
}
+
+ private String getListenerIdFrom(String id)
+ {
+ return RELEASE_SESSIONS_LISTENER + id;
+ }
}
Modified:
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerSessionInformation.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerSessionInformation.java 2007-04-10
15:07:10 UTC (rev 6967)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerSessionInformation.java 2007-04-10
21:59:28 UTC (rev 6968)
@@ -60,9 +60,44 @@
/** session id -> portlet handle */
private Map sessionId2PortletHandle;
+ /** Cookies sent by the remote producer */
private Cookie[] userCookie;
+
+ /** Parent SessionHandler so that session mappings can be updated */
private SessionHandler parent;
+ /** The identifier of the Session containing this ProducerSessionInformation */
+ private String parentSessionId;
+
+ /**
+ * public only for tests
+ *
+ * @return
+ * @since 2.6
+ */
+ public String getParentSessionId()
+ {
+ return parentSessionId;
+ }
+
+ /**
+ * public only for tests
+ *
+ * @param parentSessionId
+ * @throws IllegalStateException if an attempt is made to set the parent session id to
a different one when it has
+ * already been set.
+ * @since 2.6
+ */
+ public void setParentSessionId(String parentSessionId)
+ {
+ if (this.parentSessionId != null &&
!this.parentSessionId.equals(parentSessionId))
+ {
+ throw new IllegalStateException("Cannot modify Parent Session id once it
has been set!");
+ }
+
+ this.parentSessionId = parentSessionId;
+ }
+
public String getUserCookie()
{
if (userCookie == null)
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/SessionHandler.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/SessionHandler.java 2007-04-10
15:07:10 UTC (rev 6967)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/SessionHandler.java 2007-04-10
21:59:28 UTC (rev 6968)
@@ -24,6 +24,9 @@
package org.jboss.portal.wsrp.consumer;
import org.jboss.logging.Logger;
+import org.jboss.portal.api.event.PortalEvent;
+import org.jboss.portal.api.event.PortalEventListener;
+import org.jboss.portal.api.user.event.UserSessionEvent;
import org.jboss.portal.common.util.ParameterValidation;
import org.jboss.portal.portlet.InvokerUnavailableException;
import org.jboss.portal.portlet.PortletInvokerException;
@@ -54,7 +57,7 @@
* @version $Revision$
* @since 2.4 (May 31, 2006)
*/
-public class SessionHandler
+public class SessionHandler implements PortalEventListener
{
protected WSRPConsumerImpl consumer;
private static Logger log = Logger.getLogger(SessionHandler.class);
@@ -65,6 +68,7 @@
/** The prefix used to isolate WSRP-related session information in the actual session
object. */
private static final String SESSION_ID_PREFIX =
"org.jboss.portal.wsrp.session.";
+ /** session id -> ProducerSessionInformation */
private Map sessionInfos = new HashMap(); // todo: thread-safe?
/**
@@ -95,7 +99,7 @@
void initProducerSessionInformation(PortletInvocation invocation) throws
PortletInvokerException
{
// if we need cookies, set the current group id
- String groupId = null;
+ String groupId;
if (requiresGroupInitCookie())
{
WSRPPortletInfo info = consumer.getPortletInfo(invocation);
@@ -246,12 +250,14 @@
if (sessionInformation != null)
{
sessionInformation.setParent(this);
+ sessionInformation.setParentSessionId(session.getId());
}
else
{
if (create)
{
sessionInformation = new ProducerSessionInformation();
+ sessionInformation.setParentSessionId(session.getId());
session.setAttribute(producerSessionKey, sessionInformation);
sessionInformation.setParent(this);
}
@@ -365,6 +371,8 @@
}
}
+ // ProducerSessionInformation callbacks
+
/**
* Update session mappings when a session has expired
*
@@ -387,4 +395,46 @@
{
sessionInfos.put(sessionID, producerSessionInformation);
}
+
+ // End ProducerSessionInformation callbacks
+
+ // PortalEventListener implementation
+
+ public void onEvent(PortalEvent event)
+ {
+ if (event instanceof UserSessionEvent)
+ {
+ UserSessionEvent use = (UserSessionEvent)event;
+ int type = use.getType();
+ String id = use.getRuntimeContext().getSession().getId();
+ switch (type)
+ {
+ case UserSessionEvent.SESSION_CREATED:
+ break; // nothing to do
+
+ case UserSessionEvent.SESSION_DESTROYED:
+ // check if the session being destroyed is the one associated with this
thread
+ ProducerSessionInformation info =
RequestHeaderClientHandler.getCurrentProducerSessionInformation();
+ if (info != null)
+ {
+ if (id != null && id.equals(info.getParentSessionId()))
+ {
+ try
+ {
+ internalReleaseSessions(info.removeSessions());
+ }
+ catch (PortletInvokerException e)
+ {
+ // already logged...
+ }
+ log.debug("Released session '" + id + "'
after session was destroyed by Portal.");
+ }
+ }
+ break;
+
+ default:
+ throw new RuntimeException("Unexpected event: " + event);
+ }
+ }
+ }
}
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java 2007-04-10
15:07:10 UTC (rev 6967)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java 2007-04-10
21:59:28 UTC (rev 6968)
@@ -22,6 +22,7 @@
******************************************************************************/
package org.jboss.portal.wsrp.consumer;
+import org.jboss.portal.api.event.PortalEvent;
import org.jboss.portal.common.i18n.LocaleInfo;
import org.jboss.portal.common.invocation.InvocationException;
import org.jboss.portal.common.util.ParameterValidation;
@@ -607,4 +608,15 @@
{
return getHttpRequest(invocation).getSession();
}
+
+ /**
+ * Just delegate to SessionHandler
+ *
+ * @param event
+ * @since 2.6
+ */
+ public void onEvent(PortalEvent event)
+ {
+ sessionHandler.onEvent(event);
+ }
}
Modified:
trunk/wsrp/src/main/org/jboss/portal/wsrp/handler/RequestHeaderClientHandler.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/handler/RequestHeaderClientHandler.java 2007-04-10
15:07:10 UTC (rev 6967)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/handler/RequestHeaderClientHandler.java 2007-04-10
21:59:28 UTC (rev 6968)
@@ -205,13 +205,8 @@
public static ProducerSessionInformation getCurrentProducerSessionInformation()
{
- return getCurrentProducerSessionInformation(false);
- }
+ CurrentInfo info = getCurrentInfo(false);
- public static ProducerSessionInformation getCurrentProducerSessionInformation(boolean
create)
- {
- CurrentInfo info = getCurrentInfo(create);
-
if (info != null)
{
return info.sessionInfo;
Deleted:
trunk/wsrp/src/main/org/jboss/portal/wsrp/servlet/ReleaseSessionsSessionListener.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/servlet/ReleaseSessionsSessionListener.java 2007-04-10
15:07:10 UTC (rev 6967)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/servlet/ReleaseSessionsSessionListener.java 2007-04-10
21:59:28 UTC (rev 6968)
@@ -1,84 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2007, 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.jboss.portal.wsrp.servlet;
-
-import org.jboss.portal.api.event.PortalEvent;
-import org.jboss.portal.api.event.PortalEventListener;
-import org.jboss.portal.api.user.event.UserSessionEvent;
-import org.jboss.portal.wsrp.consumer.ProducerSessionInformation;
-import org.jboss.portal.wsrp.handler.RequestHeaderClientHandler;
-
-/**
- * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
- * @version $Revision$
- * @since 2.6
- */
-public class ReleaseSessionsSessionListener implements PortalEventListener
-{
- private static ThreadLocal local = new ThreadLocal();
- private static final String ID = "ReleaseSessionsSessionListener";
-
- public void sessionCreated(String id)
- {
- // do nothing when the session is created
- System.out.println("Session created: " + id);
- local.set(id);
- }
-
- public void sessionDestroyed(String id)
- {
- System.out.println("Session destroyed: " + id);
-
- // check if the session being destroyed is the one associated with this thread
- String storedId = (String)local.get();
- if (id != null && id.equals(storedId))
- {
- ProducerSessionInformation producerSessionInfo =
RequestHeaderClientHandler.getCurrentProducerSessionInformation();
- if (producerSessionInfo != null)
- {
- producerSessionInfo.removeSession(id);
- }
- }
- }
-
- public void onEvent(PortalEvent event)
- {
- if (event instanceof UserSessionEvent)
- {
- UserSessionEvent use = (UserSessionEvent)event;
- int type = use.getType();
- switch (type)
- {
- case UserSessionEvent.SESSION_CREATED:
- sessionCreated(use.getRuntimeContext().getSession().getId());
- break;
- case UserSessionEvent.SESSION_DESTROYED:
- sessionDestroyed(use.getRuntimeContext().getSession().getId());
- break;
- default:
- throw new RuntimeException("Unexpected event: " + event);
- }
- }
- }
-}
Modified: trunk/wsrp/src/resources/portal-wsrp-sar/META-INF/jboss-service.xml
===================================================================
--- trunk/wsrp/src/resources/portal-wsrp-sar/META-INF/jboss-service.xml 2007-04-10
15:07:10 UTC (rev 6967)
+++ trunk/wsrp/src/resources/portal-wsrp-sar/META-INF/jboss-service.xml 2007-04-10
21:59:28 UTC (rev 6968)
@@ -157,12 +157,7 @@
<depends>portal:service=Hibernate,type=WSRPConsumer</depends>
<attribute
name="SessionFactoryJNDIName">java:/portal/WSRPConsumerSessionFactory</attribute>
<depends optional-attribute-name="FederatingPortletInvoker"
proxy-type="attribute">portal:service=PortletInvoker,type=Federating</depends>
- </mbean>
-
- <!-- Listen for session events so that releaseSessions can be called when needed
-->
- <mbean
code="org.jboss.portal.wsrp.servlet.ReleaseSessionsSessionListener"
name="portal.wsrp:service=SessionListener"
- xmbean-dd=""
xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
- <xmbean/>
+ <depends optional-attribute-name="PortalEventListenerRegistry"
proxy-type="attribute">portal:service=ListenerRegistry</depends>
</mbean>
</server>