[jboss-svn-commits] JBoss Portal SVN: r5156 - in trunk: core/src/main/org/jboss/portal/core/aspects/controller core/src/main/org/jboss/portal/core/controller core/src/main/org/jboss/portal/core/controller/command core/src/main/org/jboss/portal/core/controller/portlet core/src/resources/portal-core-sar/META-INF portlet/src/main/org/jboss/portal/portlet/aspects/portlet portlet/src/resources/test-sar/META-INF
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Sep 6 07:38:51 EDT 2006
Author: julien at jboss.com
Date: 2006-09-06 07:38:31 -0400 (Wed, 06 Sep 2006)
New Revision: 5156
Added:
trunk/core/src/main/org/jboss/portal/core/aspects/controller/WindowCacheInterceptor.java
Removed:
trunk/portlet/src/main/org/jboss/portal/portlet/aspects/portlet/ConsumerCacheInterceptor.java
Modified:
trunk/core/src/main/org/jboss/portal/core/controller/ControllerCommand.java
trunk/core/src/main/org/jboss/portal/core/controller/command/InvokeWindowCommand.java
trunk/core/src/main/org/jboss/portal/core/controller/command/MarkupCommand.java
trunk/core/src/main/org/jboss/portal/core/controller/command/RenderWindowCommand.java
trunk/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPortletInvocationContext.java
trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml
trunk/portlet/src/resources/test-sar/META-INF/jboss-service.xml
Log:
improving portal portlet window caching : caching is now done by the controller instead of the consumer part of the portlet container because the controller is aware of when a portlet has been targetted and the portlet container cannot be.
Added: trunk/core/src/main/org/jboss/portal/core/aspects/controller/WindowCacheInterceptor.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/aspects/controller/WindowCacheInterceptor.java 2006-09-05 19:42:48 UTC (rev 5155)
+++ trunk/core/src/main/org/jboss/portal/core/aspects/controller/WindowCacheInterceptor.java 2006-09-06 11:38:31 UTC (rev 5156)
@@ -0,0 +1,165 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., 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.core.aspects.controller;
+
+import org.jboss.portal.core.controller.ControllerInterceptor;
+import org.jboss.portal.core.controller.ControllerCommand;
+import org.jboss.portal.core.controller.command.RenderWindowCommand;
+import org.jboss.portal.core.controller.command.InvokeWindowCommand;
+import org.jboss.portal.core.controller.command.WindowCommand;
+import org.jboss.portal.common.invocation.InvocationException;
+import org.jboss.portal.common.invocation.InvocationContext;
+import org.jboss.portal.portlet.result.FragmentResult;
+import org.jboss.portal.portlet.result.Result;
+import org.jboss.portal.portlet.result.cache.TimedContent;
+import org.jboss.portal.portlet.result.cache.StrongTimedContent;
+import org.jboss.portal.server.ServerInvocation;
+
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class WindowCacheInterceptor extends ControllerInterceptor
+{
+ public void invoke(ControllerCommand cmd) throws Exception, InvocationException
+ {
+ if (cmd instanceof WindowCommand)
+ {
+ WindowCommand wc = (WindowCommand)cmd;
+ InvocationContext invocationCtx = cmd.getContext();
+ String scopeKey = "cached_markup." + wc.getWindowRef();
+
+ //
+ if (cmd instanceof RenderWindowCommand)
+ {
+ RenderWindowCommand rwc = (RenderWindowCommand)cmd;
+
+ //
+ CacheEntry cachedEntry = (CacheEntry)invocationCtx.getAttribute(ServerInvocation.PRINCIPAL_SCOPE, scopeKey);
+
+ //
+ FragmentResult fragment = null;
+ if (cachedEntry != null)
+ {
+ long currentTimeMillis = System.currentTimeMillis();
+
+ // Check time validity for fragment
+ if (currentTimeMillis < cachedEntry.getExpirationTimeMillis())
+ {
+ fragment = cachedEntry.getContent();
+ }
+
+ // Remove the cached fragment
+ if (fragment == null)
+ {
+ invocationCtx.removeAttribute(ServerInvocation.PRINCIPAL_SCOPE, scopeKey);
+ }
+ }
+
+ //
+ if (fragment == null)
+ {
+ // Invoke
+ cmd.invokeNext();
+
+ // Get result
+ Result result = rwc.getResult();
+
+ // Try to cache any fragment result
+ if (result instanceof FragmentResult)
+ {
+ FragmentResult renderResult = (FragmentResult)result;
+
+ // Compute expiration time
+ long expirationTimeMillis = 0;
+ if (renderResult.getExpirationSecs() == -1)
+ {
+ expirationTimeMillis = Long.MAX_VALUE;
+ }
+ else if (renderResult.getExpirationSecs() > 0)
+ {
+ expirationTimeMillis = System.currentTimeMillis() + renderResult.getExpirationSecs() * 1000;
+ }
+
+ // Cache if required
+ if (expirationTimeMillis > 0)
+ {
+ CacheEntry cacheEntry = new CacheEntry(renderResult, expirationTimeMillis);
+ invocationCtx.setAttribute(ServerInvocation.PRINCIPAL_SCOPE, scopeKey, cacheEntry);
+ }
+ }
+ }
+ else
+ {
+ // Use the cached fragment
+ rwc.setResult(fragment);
+ }
+ }
+ else if (cmd instanceof InvokeWindowCommand)
+ {
+ invocationCtx.removeAttribute(ServerInvocation.PRINCIPAL_SCOPE, scopeKey);
+
+ //
+ cmd.invokeNext();
+ }
+ else
+ {
+ cmd.invokeNext();
+ }
+ }
+ else
+ {
+ cmd.invokeNext();
+ }
+ }
+
+ /**
+ * Encapsulate cache information.
+ */
+ public static class CacheEntry implements Serializable
+ {
+
+ /** The timed content. */
+ private final TimedContent cachedResult;
+
+ public CacheEntry(FragmentResult result, long expirationTimeMillis)
+ {
+ if (expirationTimeMillis <= 0)
+ {
+ throw new IllegalArgumentException();
+ }
+ this.cachedResult = new StrongTimedContent(result, expirationTimeMillis);
+ }
+
+ public long getExpirationTimeMillis()
+ {
+ return cachedResult.getExpirationTimeMillis();
+ }
+
+ public FragmentResult getContent()
+ {
+ return cachedResult.getContent();
+ }
+ }
+}
Modified: trunk/core/src/main/org/jboss/portal/core/controller/ControllerCommand.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/controller/ControllerCommand.java 2006-09-05 19:42:48 UTC (rev 5155)
+++ trunk/core/src/main/org/jboss/portal/core/controller/ControllerCommand.java 2006-09-06 11:38:31 UTC (rev 5156)
@@ -92,6 +92,11 @@
this.context = context;
}
+ public ControllerContext getControllerContext()
+ {
+ return context;
+ }
+
/**
* Enforce the security on this command.
*
Modified: trunk/core/src/main/org/jboss/portal/core/controller/command/InvokeWindowCommand.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/controller/command/InvokeWindowCommand.java 2006-09-05 19:42:48 UTC (rev 5155)
+++ trunk/core/src/main/org/jboss/portal/core/controller/command/InvokeWindowCommand.java 2006-09-06 11:38:31 UTC (rev 5156)
@@ -23,7 +23,6 @@
import org.jboss.portal.Mode;
import org.jboss.portal.WindowState;
-import org.jboss.portal.core.controller.command.WindowCommand;
/**
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
Modified: trunk/core/src/main/org/jboss/portal/core/controller/command/MarkupCommand.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/controller/command/MarkupCommand.java 2006-09-05 19:42:48 UTC (rev 5155)
+++ trunk/core/src/main/org/jboss/portal/core/controller/command/MarkupCommand.java 2006-09-06 11:38:31 UTC (rev 5156)
@@ -26,7 +26,6 @@
import org.jboss.portal.common.invocation.AttributeResolver;
import org.jboss.portal.common.invocation.InvocationException;
import org.jboss.portal.common.util.Exceptions;
-import org.jboss.portal.core.controller.portlet.ControllerPortletInvocationContext;
import org.jboss.portal.core.controller.command.info.CommandInfo;
import org.jboss.portal.core.controller.command.info.ViewCommandInfo;
import org.jboss.portal.core.controller.ControllerException;
@@ -41,7 +40,7 @@
import org.jboss.portal.core.model.portal.PortalObject;
import org.jboss.portal.core.model.portal.PortalObjectPermission;
import org.jboss.portal.core.model.portal.Window;
-import org.jboss.portal.core.controller.command.RenderWindowCommand;
+import org.jboss.portal.core.model.portal.Portal;
import org.jboss.portal.identity.User;
import org.jboss.portal.portlet.Properties;
import org.jboss.portal.portlet.info.ModeInfo;
@@ -52,10 +51,12 @@
import org.jboss.portal.portlet.result.InsufficientTransportGuaranteeResult;
import org.jboss.portal.portlet.result.Result;
import org.jboss.portal.portlet.result.UnavailableResult;
-import org.jboss.portal.portlet.spi.PortalContext;
import org.jboss.portal.security.PortalSecurityException;
import org.jboss.portal.security.spi.auth.PortalAuthorizationManager;
import org.jboss.portal.server.ServerInvocation;
+import org.jboss.portal.server.ServerInvocationContext;
+import org.jboss.portal.server.request.URLContext;
+import org.jboss.portal.server.request.URLFormat;
import org.jboss.portal.server.config.ServerConfig;
import org.jboss.portal.theme.LayoutService;
import org.jboss.portal.theme.PortalLayout;
@@ -124,6 +125,9 @@
private final MarkupContainer markupContainer;
/** . */
+ private Portal portal;
+
+ /** . */
private Page page;
/** . */
@@ -252,7 +256,8 @@
}
// Get nearest portal ancestor
- if (page.getPortal() == null)
+ portal = page.getPortal();
+ if (portal == null)
{
throw new ResourceNotFoundException("Portal for " + pageRef);
}
@@ -445,7 +450,7 @@
}
// Compute actions
- ControllerPortletInvocationContext invCtx = (ControllerPortletInvocationContext)renderCmd.getInvocation().getContext();
+// ControllerPortletInvocationContext invCtx = (ControllerPortletInvocationContext)renderCmd.getInvocation().getContext();
// Get window navigational state
WindowNavigationalState windowNavState = (WindowNavigationalState)this.context.getAttribute(ControllerCommand.NAVIGATIONAL_STATE_SCOPE, window.getId() + "_window");
@@ -463,7 +468,7 @@
responseProps = fragment.getProperties();
//
- PortalContext ctx = renderCmd.getInvocation().getPortalContext();
+// PortalContext ctx = renderCmd.getInvocation().getPortalContext();
Instance instance = renderCmd.getInstance();
//
@@ -472,7 +477,7 @@
{
WindowStateInfo windowStateInfo = (WindowStateInfo)i.next();
WindowState windowState = windowStateInfo.getWindowState();
- if (ctx.getWindowStates().contains(windowState))
+ if (portal.getSupportedWindowStates().contains(windowState))
{
supportedWindowStates.add(windowState);
}
@@ -484,7 +489,7 @@
{
ModeInfo modeInfo = (ModeInfo)i.next();
Mode mode = modeInfo.getMode();
- if (ctx.getModes().contains(mode))
+ if (portal.getSupportedModes().contains(mode))
{
supportedModes.add(mode);
}
@@ -492,16 +497,16 @@
// Remove edit mode if the user is not logged it
// commenting out for now since it breaks the tests
- if (renderCmd.getInvocation().getUserContext().getId() == null)
+ if (getControllerContext().getServerInvocation().getServerContext().getClientRequest().getUserPrincipal() == null)
{
supportedModes.remove(Mode.EDIT);
}
//
- addModeActions(actionMap, windowNavState.getMode(), supportedModes, invCtx);
+ addModeActions(window, actionMap, windowNavState.getMode(), supportedModes);
//
- addStateActions(actionMap, windowNavState.getWindowState(), supportedWindowStates, invCtx);
+ addStateActions(window, actionMap, windowNavState.getWindowState(), supportedWindowStates);
switch (fragment.getType())
{
@@ -645,19 +650,15 @@
/**
* Create the action URLs for the allowed window states of the rendered portlet window and add them to the provided
- * actionMap
- *
- * @param actionMap
- * @param currentWindowState
- * @param invCtx
+ * actionMap.
*/
- private static void addStateActions(Map actionMap, WindowState currentWindowState, List supportedWindowStates, ControllerPortletInvocationContext invCtx)
+ private void addStateActions(Window window, Map actionMap, WindowState currentWindowState, List supportedWindowStates)
{
List windowStates = new ArrayList(supportedWindowStates.size());
for (Iterator j = supportedWindowStates.iterator(); j.hasNext();)
{
WindowState windowState = (WindowState)j.next();
- String url = invCtx.createUpdateNavigationalStateURL(null, windowState);
+ String url = createUpdateNavigationalStateURL(window, null, windowState);
boolean disabled = windowState.equals(currentWindowState);
WindowResult.Action action = new WindowResult.Action(windowState, url, !disabled);
windowStates.add(action);
@@ -667,19 +668,15 @@
/**
* Create the action URLs for the allowed portlet modes of the rendered portlet window and add them to the provided
- * actionMap
- *
- * @param actionMap
- * @param currentMode
- * @param invCtx
+ * actionMap.
*/
- private static void addModeActions(Map actionMap, Mode currentMode, List supportedModes, ControllerPortletInvocationContext invCtx)
+ private void addModeActions(Window window, Map actionMap, Mode currentMode, List supportedModes)
{
List modes = new ArrayList(supportedModes.size());
for (Iterator j = supportedModes.iterator(); j.hasNext();)
{
Mode mode = (Mode)j.next();
- String url = invCtx.createUpdateNavigationalStateURL(mode, null);
+ String url = createUpdateNavigationalStateURL(window, mode, null);
boolean disabled = mode.equals(currentMode);
WindowResult.Action action = new WindowResult.Action(mode, url, !disabled);
modes.add(action);
@@ -687,37 +684,15 @@
actionMap.put(WindowResult.MODES_KEY, modes);
}
-/*
- private static void createMoveActions(Map actionMap, WindowNavigationalState state, RenderInvocation render, String handle)
+ public String createUpdateNavigationalStateURL(Window window, Mode mode, WindowState windowState)
{
- Parameters ctrlParams = new Parameters();
-
- ctrlParams.setValue("cmd", "move");
- ctrlParams.setValue("window", handle);
-
- ServerURL serverURL = new ServerURL();
- serverURL.setParameters("ctrl", ctrlParams);
-
- ServerInvocation serverInvocation = context.getServerInvocation();
- ServerResponseContext serverResponseContext = serverInvocation.getResponse().getContext();
- String url = serverResponseContext.encodeURL(serverURL);
-
- WindowResult.Action action = new WindowResult.Action("move", url, true);
- List moves = new ArrayList();
- moves.add(action);
- actionMap.put("move", moves);
-
-// List windowStates = new ArrayList(render.getRequest().getSupportedWindowStates().size());
-// for (Iterator j = render.getRequest().getSupportedWindowStates().iterator(); j.hasNext();)
-// {
-// WindowState windowState = (WindowState)j.next();
-// ServerURL serverURL = crespctx.createUpdateNavigationalStateURL(null, windowState);
-// String url = serverResponseContext.encodeURL(serverURL);
-// boolean disabled = windowState.equals(state.getWindowState());
-// WindowResult.Action action = new WindowResult.Action(windowState.toString(), url, !disabled);
-// windowStates.add(action);
-// }
-// actionMap.put("windowstate", windowStates);
+ InvokeWindowRenderCommand cmd = new InvokeWindowRenderCommand(window.getId(), mode, windowState);
+ ControllerContext controllerContext = getControllerContext();
+ ServerInvocationContext serverContext = controllerContext.getServerInvocation().getServerContext();
+ boolean secure = serverContext.getURLContext().getSecure();
+ boolean authenticated = serverContext.getURLContext().isAuthenticated();
+ URLContext urlContext = URLContext.newInstance(secure, authenticated);
+ return controllerContext.encodeURL(cmd, urlContext, URLFormat.newInstance(true, true));
}
-*/
+
}
Modified: trunk/core/src/main/org/jboss/portal/core/controller/command/RenderWindowCommand.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/controller/command/RenderWindowCommand.java 2006-09-05 19:42:48 UTC (rev 5155)
+++ trunk/core/src/main/org/jboss/portal/core/controller/command/RenderWindowCommand.java 2006-09-06 11:38:31 UTC (rev 5156)
@@ -28,12 +28,11 @@
import org.jboss.portal.core.controller.ControllerCommand;
import org.jboss.portal.core.controller.ControllerContext;
import org.jboss.portal.core.controller.ResourceNotFoundException;
-import org.jboss.portal.core.controller.command.WindowCommand;
import org.jboss.portal.server.ServerInvocation;
import org.jboss.portal.portlet.StateString;
import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.portlet.NoSuchPortletException;
-import org.jboss.portal.portlet.result.Result;
+import org.jboss.portal.portlet.result.FragmentResult;
import org.jboss.portal.portlet.invocation.RenderInvocation;
import org.jboss.portal.theme.navigation.WindowNavigationalState;
import org.jboss.portal.Mode;
@@ -45,41 +44,34 @@
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
* @version $Revision$
*/
-public class RenderWindowCommand extends WindowCommand
+public class
+ RenderWindowCommand extends WindowCommand
{
+ /** . */
private static final CommandInfo info = new ViewCommandInfo(true, "view");
- // private RenderInvocation render;
+ /** . */
+ private FragmentResult result;
- private Result result;
-
- private RenderInvocation invocation;
-
- public RenderWindowCommand(String windowRef)
- throws IllegalArgumentException
+ public RenderWindowCommand(String windowRef) throws IllegalArgumentException
{
super(windowRef);
}
- public Result getResult()
+ public CommandInfo getInfo()
{
- return result;
+ return info;
}
-// public CoreRenderContext getRenderContext()
-// {
-// return renderContext;
-// }
-
- public RenderInvocation getInvocation()
+ public FragmentResult getResult()
{
- return invocation;
+ return result;
}
- public CommandInfo getInfo()
+ public void setResult(FragmentResult result)
{
- return info;
+ this.result = result;
}
public void execute() throws ControllerException
@@ -107,12 +99,18 @@
ControllerRenderContext renderContext = new ControllerRenderContext((ControllerContext)getContext(), sinv, portal, ns, mode, windowState, window);
//
- invocation = (RenderInvocation)renderContext.createInvocation();
+ RenderInvocation invocation = (RenderInvocation)renderContext.createInvocation();
//
try
{
instance.invoke(invocation);
+
+ //
+ if (invocation.getResult() instanceof FragmentResult)
+ {
+ result = (FragmentResult)invocation.getResult();
+ }
}
catch (PortletInvokerException e)
{
@@ -125,8 +123,5 @@
throw new ControllerException(e);
}
}
-
- //
- result = invocation.getResult();
}
}
Modified: trunk/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPortletInvocationContext.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPortletInvocationContext.java 2006-09-05 19:42:48 UTC (rev 5155)
+++ trunk/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPortletInvocationContext.java 2006-09-06 11:38:31 UTC (rev 5156)
@@ -200,13 +200,4 @@
{
return controllerContext.encodeURL(cmd, urlContext, URLFormat.newInstance(relative, true));
}
-
- public String createUpdateNavigationalStateURL(Mode mode, WindowState windowState)
- {
- InvokeWindowRenderCommand cmd = new InvokeWindowRenderCommand(window.getId(), mode, windowState);
- boolean secure = invocation.getServerContext().getURLContext().getSecure();
- boolean authenticated = invocation.getServerContext().getURLContext().isAuthenticated();
- URLContext urlContext = URLContext.newInstance(secure, authenticated);
- return controllerContext.encodeURL(cmd, urlContext, URLFormat.newInstance(true, true));
- }
}
Modified: trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml
===================================================================
--- trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml 2006-09-05 19:42:48 UTC (rev 5155)
+++ trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml 2006-09-06 11:38:31 UTC (rev 5156)
@@ -148,6 +148,13 @@
<xmbean/>
</mbean>
<mbean
+ code="org.jboss.portal.core.aspects.controller.WindowCacheInterceptor"
+ name="portal:service=Interceptor,type=Command,name=WindowCache"
+ xmbean-dd=""
+ xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
+ <xmbean/>
+ </mbean>
+ <mbean
code="org.jboss.portal.server.impl.invocation.JBossInterceptorStackFactory"
name="portal:service=InterceptorStackFactory,type=Command"
xmbean-dd=""
@@ -158,6 +165,7 @@
<depends-list-element>portal:service=Interceptor,type=Command,name=PolicyEnforcement</depends-list-element>
<depends-list-element>portal:service=Interceptor,type=Command,name=PageNavigation</depends-list-element>
<depends-list-element>portal:service=Interceptor,type=Command,name=EventBroadcaster</depends-list-element>
+ <depends-list-element>portal:service=Interceptor,type=Command,name=WindowCache</depends-list-element>
</depends-list>
</mbean>
@@ -171,13 +179,6 @@
<depends optional-attribute-name="PortalAuthorizationManagerFactory" proxy-type="attribute">portal:service=PortalAuthorizationManagerFactory</depends>
</mbean>
<mbean
- code="org.jboss.portal.portlet.aspects.portlet.ConsumerCacheInterceptor"
- name="portal:service=Interceptor,type=Portlet,name=ConsumerCache"
- xmbean-dd=""
- xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
- <xmbean/>
- </mbean>
- <mbean
code="org.jboss.portal.portlet.aspects.portlet.PortalSessionSynchronizationInterceptor"
name="portal:service=Interceptor,type=Portlet,name=PortalSessionSynchronization"
xmbean-dd=""
@@ -192,7 +193,6 @@
<xmbean/>
<depends-list optional-attribute-name="InterceptorNames">
<depends-list-element>portal:service=Interceptor,type=Portlet,name=InstanceSecurity</depends-list-element>
- <depends-list-element>portal:service=Interceptor,type=Portlet,name=ConsumerCache</depends-list-element>
<depends-list-element>portal:service=Interceptor,type=Portlet,name=PortalSessionSynchronization</depends-list-element>
</depends-list>
</mbean>
Deleted: trunk/portlet/src/main/org/jboss/portal/portlet/aspects/portlet/ConsumerCacheInterceptor.java
===================================================================
--- trunk/portlet/src/main/org/jboss/portal/portlet/aspects/portlet/ConsumerCacheInterceptor.java 2006-09-05 19:42:48 UTC (rev 5155)
+++ trunk/portlet/src/main/org/jboss/portal/portlet/aspects/portlet/ConsumerCacheInterceptor.java 2006-09-06 11:38:31 UTC (rev 5156)
@@ -1,226 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., 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.portlet.aspects.portlet;
-
-import org.jboss.portal.Mode;
-import org.jboss.portal.WindowState;
-import org.jboss.portal.common.invocation.InvocationException;
-import org.jboss.portal.portlet.StateString;
-import org.jboss.portal.portlet.invocation.ActionInvocation;
-import org.jboss.portal.portlet.invocation.PortletInterceptor;
-import org.jboss.portal.portlet.invocation.PortletInvocation;
-import org.jboss.portal.portlet.invocation.RenderInvocation;
-import org.jboss.portal.portlet.result.FragmentResult;
-import org.jboss.portal.portlet.result.Result;
-import org.jboss.portal.portlet.result.cache.StrongTimedContent;
-import org.jboss.portal.portlet.result.cache.TimedContent;
-import org.jboss.portal.portlet.spi.PortletInvocationContext;
-import org.jboss.portal.server.ServerInvocation;
-
-import java.io.Serializable;
-
-/**
- * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
- * @version $Revision$
- */
-public class ConsumerCacheInterceptor extends PortletInterceptor
-{
- protected void invoke(PortletInvocation invocation) throws Exception, InvocationException
- {
- PortletInvocationContext invocationCtx = invocation.getPortletContext();
- String scopeKey = "cached_markup." + invocation.getWindowContext().getId();
-
- //
- if (invocation instanceof ActionInvocation)
- {
- //
- invocationCtx.setAttribute(ServerInvocation.PRINCIPAL_SCOPE, scopeKey, null);
-
- // Invoke
- invocation.invokeNext();
- }
- else if (invocation instanceof RenderInvocation)
- {
- CacheEntry cachedEntry = (CacheEntry)invocationCtx.getAttribute(ServerInvocation.PRINCIPAL_SCOPE, scopeKey);
-
- //
- FragmentResult fragment = null;
- if (cachedEntry != null)
- {
- long currentTimeMillis = System.currentTimeMillis();
-
- // Check time validity for fragment
- if (currentTimeMillis < cachedEntry.getExpirationTimeMillis())
- {
- CacheKey cacheKey = new CacheKey(invocationCtx.getNavigationalState(), invocationCtx.getWindowState(), invocationCtx.getMode());
-
- // Check state validity for fragment
- if (cachedEntry.getKey().equals(cacheKey))
- {
- fragment = cachedEntry.getContent();
- }
- }
-
- // Remove the cached fragment
- if (fragment == null)
- {
- invocationCtx.setAttribute(ServerInvocation.PRINCIPAL_SCOPE, scopeKey, null);
- }
- }
-
- //
- if (fragment == null)
- {
- // Invoke
- invocation.invokeNext();
-
- // Get result
- Result result = invocation.getResult();
-
- // Try to cache any fragment result
- if (result instanceof FragmentResult)
- {
- FragmentResult renderResult = (FragmentResult)result;
-
- // Compute expiration time
- long expirationTimeMillis = 0;
- if (renderResult.getExpirationSecs() == -1)
- {
- expirationTimeMillis = Long.MAX_VALUE;
- }
- else if (renderResult.getExpirationSecs() > 0)
- {
- expirationTimeMillis = System.currentTimeMillis() + renderResult.getExpirationSecs() * 1000;
- }
-
- // Cache if required
- if (expirationTimeMillis > 0)
- {
- CacheKey cacheKey = new CacheKey(invocationCtx.getNavigationalState(), invocationCtx.getWindowState(), invocationCtx.getMode());
- CacheEntry cacheEntry = new CacheEntry(renderResult, cacheKey, expirationTimeMillis);
- invocationCtx.setAttribute(ServerInvocation.PRINCIPAL_SCOPE, scopeKey, cacheEntry);
- }
- }
- }
- else
- {
- // Use the cached fragment
- invocation.setResult(fragment);
- }
- }
- }
-
- /**
- * Encapsulate cache information.
- */
- public static class CacheEntry implements Serializable
- {
-
- /** The timed content. */
- private final TimedContent cachedResult;
-
- /** The navigational state. */
- private final CacheKey key;
-
- public CacheEntry(FragmentResult result, CacheKey key, long expirationTimeMillis)
- {
- if (expirationTimeMillis <= 0)
- {
- throw new IllegalArgumentException();
- }
- this.cachedResult = new StrongTimedContent(result, expirationTimeMillis);
- this.key = key;
- }
-
- public CacheKey getKey()
- {
- return key;
- }
-
- public long getExpirationTimeMillis()
- {
- return cachedResult.getExpirationTimeMillis();
- }
-
- public FragmentResult getContent()
- {
- return cachedResult.getContent();
- }
- }
-
- public static class CacheKey implements Serializable
- {
-
- /** The navigational state. */
- private final StateString navigationalState;
-
- /** The window state. */
- private final WindowState windowState;
-
- /** The mode. */
- private final Mode mode;
-
- public CacheKey(StateString navigationalState, WindowState windowState, Mode mode)
- {
- this.navigationalState = navigationalState;
- if (windowState == null)
- {
- throw new IllegalArgumentException("No null window state accepted");
- }
- if (mode == null)
- {
- throw new IllegalArgumentException("No null mode accepted");
- }
- this.windowState = windowState;
- this.mode = mode;
- }
-
- public boolean equals(Object o)
- {
- if (o == this)
- {
- return true;
- }
- if (o instanceof CacheKey)
- {
- CacheKey that = (CacheKey)o;
- if (navigationalState == null)
- {
- if (that.navigationalState != null)
- {
- return false;
- }
- }
- else if (navigationalState.equals(that.navigationalState) == false)
- {
- return false;
- }
- if (windowState.equals(that.windowState) == false)
- {
- return false;
- }
- return mode.equals(that.mode);
- }
- return false;
- }
- }
-}
Modified: trunk/portlet/src/resources/test-sar/META-INF/jboss-service.xml
===================================================================
--- trunk/portlet/src/resources/test-sar/META-INF/jboss-service.xml 2006-09-05 19:42:48 UTC (rev 5155)
+++ trunk/portlet/src/resources/test-sar/META-INF/jboss-service.xml 2006-09-06 11:38:31 UTC (rev 5156)
@@ -47,13 +47,6 @@
<!-- Consumer stack -->
<mbean
- code="org.jboss.portal.portlet.aspects.portlet.ConsumerCacheInterceptor"
- name="portal:service=Interceptor,type=Portlet,name=ConsumerCache"
- xmbean-dd=""
- xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
- <xmbean/>
- </mbean>
- <mbean
code="org.jboss.portal.portlet.aspects.portlet.PortalSessionSynchronizationInterceptor"
name="portal:service=Interceptor,type=Portlet,name=PortalSessionSynchronization"
xmbean-dd=""
@@ -67,7 +60,6 @@
xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
<xmbean/>
<depends-list optional-attribute-name="InterceptorNames">
- <depends-list-element>portal:service=Interceptor,type=Portlet,name=ConsumerCache</depends-list-element>
<depends-list-element>portal:service=Interceptor,type=Portlet,name=PortalSessionSynchronization</depends-list-element>
</depends-list>
</mbean>
More information about the jboss-svn-commits
mailing list