Author: chris.laprun(a)jboss.com
Date: 2007-04-04 16:08:24 -0400 (Wed, 04 Apr 2007)
New Revision: 6919
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/ProducerSessionInformationTestCase.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerSessionInformation.java
Log:
- Improvements to session releasing code.
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-04
16:17:58 UTC (rev 6918)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/ProducerSessionInformationTestCase.java 2007-04-04
20:08:24 UTC (rev 6919)
@@ -127,7 +127,7 @@
assertEquals(sid2, info.getSessionIdForPortlet(handle2));
assertEquals(1, info.getNumberOfSessions());
- info.releaseSessionIdForPortlet(handle2);
+ info.releaseSessionForPortlet(handle2);
assertEquals(0, info.getNumberOfSessions());
}
@@ -163,6 +163,30 @@
info.releaseSessions();
assertEquals(0, info.getNumberOfSessions());
+
+ addSession("handle", "id", 1);
+ addSession("handle2", "id2", 2);
+
+ info.releaseSession("id2");
+
+ assertEquals(1, info.getNumberOfSessions());
+ assertNull(info.getSessionIdForPortlet("handle2"));
+ assertEquals("id", info.getSessionIdForPortlet("handle"));
+
+ info.releaseSessionForPortlet("handle");
+
+ assertEquals(0, info.getNumberOfSessions());
+ assertNull(info.getSessionIdForPortlet("handle"));
+
+ try
+ {
+ info.releaseSessionForPortlet("handle");
+ fail("Session for portlet 'handle' should have already been
released!");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ // expected
+ }
}
private Cookie createCookie(String name, String value, int secondsBeforeExpiration)
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-04
16:17:58 UTC (rev 6918)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerSessionInformation.java 2007-04-04
20:08:24 UTC (rev 6919)
@@ -27,7 +27,6 @@
import org.jboss.logging.Logger;
import org.jboss.portal.common.util.ParameterValidation;
import org.jboss.portal.common.util.Tools;
-import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.wsrp.WSRPConstants;
import org.jboss.portal.wsrp.WSRPConsumer;
import org.jboss.portal.wsrp.core.SessionContext;
@@ -47,7 +46,7 @@
*/
public class ProducerSessionInformation
{
- private Logger log = Logger.getLogger(ProducerSessionInformation.class);
+ private static Logger log = Logger.getLogger(ProducerSessionInformation.class);
private boolean initCookieDone = false;
private boolean perGroupCookies = false;
@@ -69,6 +68,11 @@
{
ParameterValidation.throwIllegalArgExceptionIfNull(associatedConsumer,
"Consumer");
this.associatedConsumer = associatedConsumer;
+ /*if (associatedConsumer instanceof WSRPConsumerImpl)
+ {
+ WSRPConsumerImpl consumer = (WSRPConsumerImpl)associatedConsumer;
+ consumer.add
+ }*/
}
public String getUserCookie()
@@ -202,8 +206,58 @@
return idResult.id;
}
- public void releaseSessionIdForPortlet(String portletHandle)
+ public int getNumberOfSessions()
{
+ if (portletSessions != null)
+ {
+ return portletSessions.size();
+ }
+ else
+ {
+ return 0;
+ }
+ }
+
+ public void releaseSession(String sessionId)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(sessionId, "session
id");
+
+ String portletHandle = (String)sessionId2PortletHandle.get(sessionId);
+ if (portletHandle == null)
+ {
+ throw new IllegalArgumentException("No such session id: '" +
sessionId + "'");
+ }
+
+ releaseSessionForPortlet(portletHandle);
+ }
+
+ public void releaseSessions()
+ {
+ List idsToRelease = new ArrayList(getNumberOfSessions());
+
+ // copy to avoid ConcurrentModificationException
+ List handlesCopy = new ArrayList(portletSessions.keySet());
+
+ for (Iterator handles = handlesCopy.iterator(); handles.hasNext();)
+ {
+ String handle = (String)handles.next();
+ SessionIdResult result = removeSessionIdForPortlet(handle);
+
+ // only release sessions that are still valid
+ if (!result.expired)
+ {
+ idsToRelease.add(result.id);
+ }
+ }
+
+ if (!idsToRelease.isEmpty())
+ {
+ releaseSessions((String[])idsToRelease.toArray(new String[0]));
+ }
+ }
+
+ public void releaseSessionForPortlet(String portletHandle)
+ {
SessionIdResult result = removeSessionIdForPortlet(portletHandle);
// if the session is still valid, release it and remove the associated mappings
@@ -232,7 +286,7 @@
{
associatedConsumer.releaseSessions(sessionIds);
}
- catch (PortletInvokerException e)
+ catch (Exception e)
{
log.debug(e);
}
@@ -247,6 +301,11 @@
ProducerSessionInformation.SessionIdResult result =
internalGetSessionIdForPortlet(portletHandle);
final String id = result.id;
+ if (id == null)
+ {
+ throw new IllegalArgumentException("There is no Session associated with
portlet '" + portletHandle + "'");
+ }
+
// if the session is still valid, release it and remove the associated mappings
if (!result.expired)
{
@@ -257,56 +316,6 @@
return result;
}
- public int getNumberOfSessions()
- {
- if (portletSessions != null)
- {
- return portletSessions.size();
- }
- else
- {
- return 0;
- }
- }
-
- public void releaseSession(String id)
- {
- ParameterValidation.throwIllegalArgExceptionIfNull(id, "session id");
-
- String portletHandle = (String)sessionId2PortletHandle.get(id);
- if (portletHandle == null)
- {
- throw new IllegalArgumentException("No such session id: '" + id +
"'");
- }
-
- releaseSessionIdForPortlet(portletHandle);
- }
-
- public void releaseSessions()
- {
- List idsToRelease = new ArrayList(getNumberOfSessions());
-
- // copy to avoid ConcurrentModificationException
- List handlesCopy = new ArrayList(portletSessions.keySet());
-
- for (Iterator handles = handlesCopy.iterator(); handles.hasNext();)
- {
- String handle = (String)handles.next();
- SessionIdResult result = removeSessionIdForPortlet(handle);
-
- // only release sessions that are still valid
- if (!result.expired)
- {
- idsToRelease.add(result.id);
- }
- }
-
- if (!idsToRelease.isEmpty())
- {
- releaseSessions((String[])idsToRelease.toArray(new String[0]));
- }
- }
-
public void replaceUserCookiesWith(ProducerSessionInformation currentSessionInfo)
{
if (currentSessionInfo != null && currentSessionInfo.userCookie != null
&& currentSessionInfo.userCookie.length > 0)
Show replies by date