Author: chris.laprun(a)jboss.com
Date: 2007-03-27 20:56:31 -0400 (Tue, 27 Mar 2007)
New Revision: 6856
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/support/MockConsumerRegistry.java
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/admin/ui/ConsumerManagerBean.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistry.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/WSRPConsumerImpl.java
Log:
- Added ConsumerRegistry.destroyConsumer method (not tested).
- Improved support for releasing sessions on WSRPConsumer and ProducerSessionInformation.
Issue exists to retrieve the appropriate ProducerSessionInformation without an
invocation...
- JBPORTAL-715: started adding support for destroying a consumer.
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/support/MockConsumerRegistry.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/support/MockConsumerRegistry.java 2007-03-28
00:50:40 UTC (rev 6855)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/support/MockConsumerRegistry.java 2007-03-28
00:56:31 UTC (rev 6856)
@@ -112,4 +112,9 @@
{
// do nothing
}
+
+ public void destroyConsumer(String id)
+ {
+ // do nothing
+ }
}
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-03-28
00:50:40 UTC (rev 6855)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/support/MockWSRPConsumer.java 2007-03-28
00:56:31 UTC (rev 6856)
@@ -91,10 +91,14 @@
{
}
- public void releaseSession(String sessionId) throws PortletInvokerException
+ public void releaseSessions(String[] sessionIds) throws PortletInvokerException
{
}
+ public void releaseSessions()
+ {
+ }
+
public void activate() throws Exception
{
}
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-03-28
00:50:40 UTC (rev 6855)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/ProducerSessionInformationTestCase.java 2007-03-28
00:56:31 UTC (rev 6856)
@@ -114,8 +114,8 @@
assertNull(info.getSessionIdForPortlet(handle));
assertEquals(0, info.getNumberOfSessions());
- info.addSessionForPortlet(handle, WSRPTypeFactory.createSessionContext(sid, 1));
- info.addSessionForPortlet(handle2, WSRPTypeFactory.createSessionContext(sid2, 3));
+ addSession(handle, sid, 1);
+ addSession(handle2, sid2, 3);
assertNull(info.getSessionIdForPortlet("unknown"));
@@ -127,7 +127,7 @@
assertEquals(sid2, info.getSessionIdForPortlet(handle2));
assertEquals(1, info.getNumberOfSessions());
- info.removeSessionIdForPortlet(handle2);
+ info.releaseSessionIdForPortlet(handle2);
assertEquals(0, info.getNumberOfSessions());
}
@@ -152,8 +152,26 @@
assertNull(info.getUserCookie());
}
+ public void testReleaseSessions()
+ {
+ addSession("handle", "id", 1);
+ addSession("handle2", "id2", 1);
+ addSession("handle3", "id3", 1);
+
+ assertEquals(3, info.getNumberOfSessions());
+
+ info.releaseSessions();
+
+ assertEquals(0, info.getNumberOfSessions());
+ }
+
private Cookie createCookie(String name, String value, int secondsBeforeExpiration)
{
return new Cookie("domain", name, value, "path",
secondsBeforeExpiration, false);
}
+
+ private void addSession(String handle, String sid, int expires)
+ {
+ info.addSessionForPortlet(handle, WSRPTypeFactory.createSessionContext(sid,
expires));
+ }
}
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPConsumer.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPConsumer.java 2007-03-28 00:50:40 UTC
(rev 6855)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPConsumer.java 2007-03-28 00:56:31 UTC
(rev 6856)
@@ -99,14 +99,33 @@
void refreshProducerInfo() throws PortletInvokerException;
/**
- * Instructs the associated producer to release the specified session.
+ * Instructs the associated producer to release the specified sessions.
*
- * @param sessionId the session id to be released
+ * @param sessionIds
* @since 2.6
*/
- void releaseSession(String sessionId) throws PortletInvokerException;
+ void releaseSessions(String[] sessionIds) throws PortletInvokerException;
+ /**
+ * Releases all the sessions held by this Consumer
+ *
+ * @since 2.6
+ */
+ void releaseSessions();
+
+ /**
+ * Prepares this Consumer to be used: service is started, endpoints are ready.
+ *
+ * @throws Exception
+ * @since 2.6
+ */
void activate() throws Exception;
+ /**
+ * Removes this Consumer from service. It cannot be used before being activated
again.
+ *
+ * @throws Exception
+ * @since 2.6
+ */
void deactivate() throws Exception;
}
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/admin/ui/ConsumerManagerBean.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/admin/ui/ConsumerManagerBean.java 2007-03-28
00:50:40 UTC (rev 6855)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/admin/ui/ConsumerManagerBean.java 2007-03-28
00:56:31 UTC (rev 6856)
@@ -149,6 +149,13 @@
public String destroyConsumer()
{
+ if (refreshConsumerId() != null)
+ {
+ registry.destroyConsumer(selectedId);
+ return listConsumers();
+ }
+
+ //todo: error message
return null;
}
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistry.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistry.java 2007-03-28
00:50:40 UTC (rev 6855)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistry.java 2007-03-28
00:56:31 UTC (rev 6856)
@@ -60,4 +60,6 @@
void deactivateConsumerWith(String id) throws ConsumerException;
void registerOrDeregisterConsumerWith(String id, boolean register);
+
+ void destroyConsumer(String id);
}
\ No newline at end of file
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistryService.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistryService.java 2007-03-28
00:50:40 UTC (rev 6855)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistryService.java 2007-03-28
00:56:31 UTC (rev 6856)
@@ -99,6 +99,30 @@
return createConsumerFrom(info);
}
+ public void destroyConsumer(String id)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(id, "Consumer
identifier", "destroyConsumer");
+
+ WSRPConsumer consumer = getConsumer(id);
+ if (consumer != null)
+ {
+ ProducerInfo info = consumer.getProducerInfo();
+
+// consumer.releaseSessions(); // todo: fix, this is called from a different
thread than the one that sets the req in ServletAccess
+ registerOrDeregisterConsumerWith(id, false);
+ deactivateConsumerWith(id);
+ consumers.remove(id);
+
+ Session session = sessionFactory.getCurrentSession();
+
+ session.delete(info);
+ }
+ else
+ {
+ throw new ConsumerException(CONSUMER_WITH_ID + id + "' doesn't
exist!");
+ }
+ }
+
public void persistConsumer(WSRPConsumer consumer)
{
ParameterValidation.throwIllegalArgExceptionIfNull(consumer,
"Consumer");
Modified:
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerSessionInformation.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerSessionInformation.java 2007-03-28
00:50:40 UTC (rev 6855)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerSessionInformation.java 2007-03-28
00:56:31 UTC (rev 6856)
@@ -32,7 +32,9 @@
import org.jboss.portal.wsrp.WSRPConsumer;
import org.jboss.portal.wsrp.core.SessionContext;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -200,24 +202,35 @@
return idResult.id;
}
- public void removeSessionIdForPortlet(String portletHandle)
+ public void releaseSessionIdForPortlet(String portletHandle)
{
- ProducerSessionInformation.SessionIdResult result =
internalGetSessionIdForPortlet(portletHandle);
- final String id = result.id;
+ SessionIdResult result = removeSessionIdForPortlet(portletHandle);
// if the session is still valid, release it and remove the associated mappings
+ final String[] sessionIds;
if (!result.expired)
{
- portletSessions.remove(portletHandle);
- sessionId2PortletHandle.remove(id);
+ sessionIds = new String[]{result.id};
+ }
+ else
+ {
+ sessionIds = null;
+ }
+ releaseSessions(sessionIds);
+ }
+
+ private void releaseSessions(final String[] sessionIds)
+ {
+ if (sessionIds != null && sessionIds.length > 0)
+ {
Runnable releaseSession = new Runnable()
{
public void run()
{
try
{
- associatedConsumer.releaseSession(id);
+ associatedConsumer.releaseSessions(sessionIds);
}
catch (PortletInvokerException e)
{
@@ -227,7 +240,21 @@
};
new Thread(releaseSession).start();
}
+ }
+ private SessionIdResult removeSessionIdForPortlet(String portletHandle)
+ {
+ ProducerSessionInformation.SessionIdResult result =
internalGetSessionIdForPortlet(portletHandle);
+ final String id = result.id;
+
+ // if the session is still valid, release it and remove the associated mappings
+ if (!result.expired)
+ {
+ portletSessions.remove(portletHandle);
+ sessionId2PortletHandle.remove(id);
+ }
+
+ return result;
}
public int getNumberOfSessions()
@@ -252,9 +279,34 @@
throw new IllegalArgumentException("No such session id: '" + id +
"'");
}
- removeSessionIdForPortlet(portletHandle);
+ 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)
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java 2007-03-28
00:50:40 UTC (rev 6855)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java 2007-03-28
00:56:31 UTC (rev 6856)
@@ -22,8 +22,8 @@
******************************************************************************/
package org.jboss.portal.wsrp.consumer;
+import org.jboss.portal.common.i18n.LocaleInfo;
import org.jboss.portal.common.invocation.InvocationException;
-import org.jboss.portal.common.i18n.LocaleInfo;
import org.jboss.portal.common.util.ParameterValidation;
import org.jboss.portal.common.value.StringValue;
import org.jboss.portal.jems.as.system.AbstractJBossService;
@@ -68,6 +68,7 @@
import org.jboss.portal.wsrp.core.WSRP_v1_Registration_PortType;
import org.jboss.portal.wsrp.core.WSRP_v1_ServiceDescription_PortType;
import org.jboss.portal.wsrp.services.ServiceFactory;
+import org.jboss.portal.wsrp.servlet.ServletAccess;
import org.jboss.portal.wsrp.servlet.UserAccess;
import javax.servlet.http.HttpServletRequest;
@@ -536,10 +537,11 @@
sessionHandler.setRequiresInitCookie(producerInfo.getRequiresInitCookie());
}
- public void releaseSession(String sessionId) throws PortletInvokerException
+ public void releaseSessions(String[] sessionIds) throws PortletInvokerException
{
+ //todo: move to SessionHandler?
ReleaseSessions releaseSessions =
-
WSRPTypeFactory.createReleaseSessions(producerInfo.getRegistrationInfo().getRegistrationContext(),
new String[]{sessionId});
+
WSRPTypeFactory.createReleaseSessions(producerInfo.getRegistrationInfo().getRegistrationContext(),
sessionIds);
try
{
@@ -553,10 +555,24 @@
catch (Exception e)
{
log.debug(e);
- throw new PortletInvokerException("Couldn't release session '"
+ sessionId + "'.", e);
+ throw new PortletInvokerException("Couldn't release session '"
+ sessionIds + "'.", e);
}
}
+ public void releaseSessions()
+ {
+ // todo: move to SessionHandler?
+ HttpSession session = ServletAccess.getRequest().getSession(false);
+ if (session != null)
+ {
+ ProducerSessionInformation info = getProducerSessionInformationFrom(session);
+ if (info != null)
+ {
+ info.releaseSessions();
+ }
+ }
+ }
+
// Support methods
**************************************************************************************************
private String getUserContextKeyFor(UserContext userContext)