Index: jetspeed-2/components/portal/src/java/org/apache/jetspeed/aggregator/impl/RenderingJobImpl.java =================================================================== --- jetspeed-2/components/portal/src/java/org/apache/jetspeed/aggregator/impl/RenderingJobImpl.java (revision 483788) +++ jetspeed-2/components/portal/src/java/org/apache/jetspeed/aggregator/impl/RenderingJobImpl.java (working copy) @@ -16,6 +16,7 @@ package org.apache.jetspeed.aggregator.impl; +import java.util.Iterator; import java.util.Map; import javax.portlet.UnavailableException; @@ -27,6 +28,8 @@ import org.apache.jetspeed.PortalReservedParameters; import org.apache.jetspeed.aggregator.PortletContent; import org.apache.jetspeed.aggregator.RenderingJob; +import org.apache.jetspeed.aggregator.Worker; +import org.apache.jetspeed.aggregator.CurrentWorkerContext; import org.apache.jetspeed.om.common.portlet.MutablePortletEntity; import org.apache.jetspeed.om.page.ContentFragment; import org.apache.jetspeed.request.RequestContext; @@ -132,9 +135,8 @@ public void execute() { long start = System.currentTimeMillis(); + boolean isParallelMode = false; - Map workerAsMap = null; - try { log.debug("Rendering OID "+this.window.getId()+" "+ this.request +" "+this.response); @@ -142,21 +144,26 @@ // if the current thread is worker, then store attribues in that. if (this.workerAttributes != null) { - Thread ct = Thread.currentThread(); - if (ct instanceof Map) + isParallelMode = (Thread.currentThread() instanceof Worker); + + if (isParallelMode) { - workerAsMap = (Map) ct; - workerAsMap.putAll(this.workerAttributes); + Iterator itAttrNames = this.workerAttributes.keySet().iterator(); + while (itAttrNames.hasNext()) { + String name = (String) itAttrNames.next(); + CurrentWorkerContext.setAttribute(name, this.workerAttributes.get(name)); + } + // Sometimes, the portlet definition of some portlet entities are replaced. // I could not find why it happens. // If the portlet definition of portlet entity is not same as an attribute of worker's, then // reset the portlet definition of portlet entity. (by Woonsan Ko) // TODO: Investigate more and find why it happens. PortletDefinition portletDefinition = - (PortletDefinition) workerAsMap.get(PortalReservedParameters.PORTLET_DEFINITION_ATTRIBUTE); + (PortletDefinition) CurrentWorkerContext.getAttribute(PortalReservedParameters.PORTLET_DEFINITION_ATTRIBUTE); PortletWindow window = - (PortletWindow) workerAsMap.get(PortalReservedParameters.PORTLET_WINDOW_ATTRIBUTE); + (PortletWindow) CurrentWorkerContext.getAttribute(PortalReservedParameters.PORTLET_WINDOW_ATTRIBUTE); PortletEntityImpl portletEntityImpl = (PortletEntityImpl) window.getPortletEntity(); PortletDefinition oldPortletDefinition = portletEntityImpl.getPortletDefinition(); @@ -189,9 +196,9 @@ } finally { - if (workerAsMap != null) + if (isParallelMode) { - workerAsMap.clear(); + CurrentWorkerContext.removeAllAttributes(); } portletContent.complete(); Index: jetspeed-2/components/portal/src/java/org/apache/jetspeed/aggregator/impl/WorkerImpl.java =================================================================== --- jetspeed-2/components/portal/src/java/org/apache/jetspeed/aggregator/impl/WorkerImpl.java (revision 483788) +++ jetspeed-2/components/portal/src/java/org/apache/jetspeed/aggregator/impl/WorkerImpl.java (working copy) @@ -19,8 +19,6 @@ import java.security.AccessControlContext; import java.security.PrivilegedAction; import java.util.Collection; -import java.util.HashMap; -import java.util.Map; import java.util.Set; import javax.security.auth.Subject; @@ -39,7 +37,7 @@ * @author Rapha�l Luta * @version $Id$ */ -public class WorkerImpl extends Thread implements Worker, Map +public class WorkerImpl extends Thread implements Worker { /** Commons logging */ protected final static Log log = LogFactory.getLog(WorkerImpl.class); @@ -60,9 +58,6 @@ /** Monitor for this Worker */ private WorkerMonitor monitor = null; - /** Attributes for this Worker **/ - private Map attributes = null; - public WorkerImpl(WorkerMonitor monitor) { super(); @@ -207,82 +202,5 @@ monitor.release(this); } } - - // map implementations - - public int size() - { - return (null == this.attributes ? 0 : this.attributes.size()); - } - - public boolean isEmpty() - { - return (null == this.attributes ? true : this.attributes.isEmpty()); - } - - public boolean containsKey(Object key) - { - return (null == this.attributes ? false : this.attributes.containsKey(key)); - } - - public boolean containsValue(Object value) - { - return (null == this.attributes ? false : this.attributes.containsValue(value)); - } - - public Object get(Object key) - { - return (null == this.attributes ? null : this.attributes.get(key)); - } - - public Object put(Object key, Object value) - { - if (null == this.attributes) { - this.attributes = new HashMap(); - } - - return this.attributes.put(key, value); - } - - public Object remove(Object key) - { - if (null != this.attributes) { - return this.attributes.remove(key); - } else { - return null; - } - } - - public void putAll(Map t) - { - if (null == this.attributes) { - this.attributes = new HashMap(); - } - - this.attributes.putAll(t); - } - - public void clear() - { - if (null != this.attributes) { - this.attributes.clear(); - } - } - - public Set keySet() - { - return (null == this.attributes ? null : this.attributes.keySet()); - } - - public Collection values() - { - return (null == this.attributes ? null : this.attributes.values()); - } - - public Set entrySet() - { - return (null == this.attributes ? null : this.attributes.entrySet()); - } - } Index: jetspeed-2/components/portal/src/java/org/apache/jetspeed/container/invoker/ServletPortletInvoker.java =================================================================== --- jetspeed-2/components/portal/src/java/org/apache/jetspeed/container/invoker/ServletPortletInvoker.java (revision 483788) +++ jetspeed-2/components/portal/src/java/org/apache/jetspeed/container/invoker/ServletPortletInvoker.java (working copy) @@ -16,7 +16,6 @@ package org.apache.jetspeed.container.invoker; import java.io.IOException; -import java.util.Map; import javax.portlet.ActionRequest; import javax.portlet.ActionResponse; @@ -43,6 +42,8 @@ import org.apache.jetspeed.om.common.portlet.MutablePortletApplication; import org.apache.jetspeed.om.common.portlet.PortletApplication; import org.apache.jetspeed.request.RequestContext; +import org.apache.jetspeed.aggregator.Worker; +import org.apache.jetspeed.aggregator.CurrentWorkerContext; import org.apache.pluto.om.portlet.PortletDefinition; import org.apache.pluto.om.servlet.WebApplicationDefinition; @@ -169,14 +170,13 @@ // So, hide the member variable by the following local variable. PortletDefinition portletDefinition = null; - // In case of parallel mode, get portlet definition object from the worker thread. + // In case of parallel mode, get portlet definition object from the worker thread context. // Otherwise, refer the member variable. - Map workerAsMap = null; - Thread ct = Thread.currentThread(); - if (ct instanceof Map) + boolean isParallelMode = (Thread.currentThread() instanceof Worker); + + if (isParallelMode) { - workerAsMap = (Map) ct; - portletDefinition = (PortletDefinition) workerAsMap.get(PortalReservedParameters.PORTLET_DEFINITION_ATTRIBUTE); + portletDefinition = (PortletDefinition) CurrentWorkerContext.getAttribute(PortalReservedParameters.PORTLET_DEFINITION_ATTRIBUTE); } else { @@ -231,15 +231,15 @@ servletRequest.setAttribute(ContainerConstants.PORTAL_CONTEXT, requestContext.getRequest().getContextPath()); // Store same request attributes into the worker in parallel mode. - if (workerAsMap != null) + if (isParallelMode) { - workerAsMap.put(ContainerConstants.PORTLET, portletInstance); - workerAsMap.put(ContainerConstants.PORTLET_CONFIG, portletInstance.getConfig()); - workerAsMap.put(ContainerConstants.PORTLET_REQUEST, portletRequest); - workerAsMap.put(ContainerConstants.PORTLET_RESPONSE, portletResponse); - workerAsMap.put(ContainerConstants.METHOD_ID, methodID); - workerAsMap.put(ContainerConstants.PORTLET_NAME, app.getName()+"::"+portletDefinition.getName()); - workerAsMap.put(ContainerConstants.PORTAL_CONTEXT, requestContext.getRequest().getContextPath()); + CurrentWorkerContext.setAttribute(ContainerConstants.PORTLET, portletInstance); + CurrentWorkerContext.setAttribute(ContainerConstants.PORTLET_CONFIG, portletInstance.getConfig()); + CurrentWorkerContext.setAttribute(ContainerConstants.PORTLET_REQUEST, portletRequest); + CurrentWorkerContext.setAttribute(ContainerConstants.PORTLET_RESPONSE, portletResponse); + CurrentWorkerContext.setAttribute(ContainerConstants.METHOD_ID, methodID); + CurrentWorkerContext.setAttribute(ContainerConstants.PORTLET_NAME, app.getName()+"::"+portletDefinition.getName()); + CurrentWorkerContext.setAttribute(ContainerConstants.PORTAL_CONTEXT, requestContext.getRequest().getContextPath()); } PortletRequestContext.createContext(portletDefinition, portletInstance, portletRequest, portletResponse); @@ -257,16 +257,16 @@ { PortletRequestContext.clearContext(); - // In parallel mode, remove attributes of worker. - if (workerAsMap != null) + // In parallel mode, remove all attributes of worker context. + if (isParallelMode) { - workerAsMap.remove(ContainerConstants.PORTLET); - workerAsMap.remove(ContainerConstants.PORTLET_CONFIG); - workerAsMap.remove(ContainerConstants.PORTLET_REQUEST); - workerAsMap.remove(ContainerConstants.PORTLET_RESPONSE); - workerAsMap.remove(ContainerConstants.METHOD_ID); - workerAsMap.remove(ContainerConstants.PORTLET_NAME); - workerAsMap.remove(ContainerConstants.PORTAL_CONTEXT); + CurrentWorkerContext.removeAttribute(ContainerConstants.PORTLET); + CurrentWorkerContext.removeAttribute(ContainerConstants.PORTLET_CONFIG); + CurrentWorkerContext.removeAttribute(ContainerConstants.PORTLET_REQUEST); + CurrentWorkerContext.removeAttribute(ContainerConstants.PORTLET_RESPONSE); + CurrentWorkerContext.removeAttribute(ContainerConstants.METHOD_ID); + CurrentWorkerContext.removeAttribute(ContainerConstants.PORTLET_NAME); + CurrentWorkerContext.removeAttribute(ContainerConstants.PORTAL_CONTEXT); } servletRequest.removeAttribute(ContainerConstants.PORTLET); Index: jetspeed-2/components/portal/src/java/org/apache/jetspeed/request/JetspeedRequestContextComponent.java =================================================================== --- jetspeed-2/components/portal/src/java/org/apache/jetspeed/request/JetspeedRequestContextComponent.java (revision 483788) +++ jetspeed-2/components/portal/src/java/org/apache/jetspeed/request/JetspeedRequestContextComponent.java (working copy) @@ -16,7 +16,6 @@ package org.apache.jetspeed.request; import java.lang.reflect.Constructor; -import java.util.Map; import javax.servlet.ServletConfig; import javax.servlet.http.HttpServletRequest; @@ -27,6 +26,8 @@ import org.apache.jetspeed.PortalReservedParameters; import org.apache.jetspeed.userinfo.UserInfoManager; +import org.apache.jetspeed.aggregator.Worker; +import org.apache.jetspeed.aggregator.CurrentWorkerContext; /** * JetspeedRequestContextComponent @@ -118,10 +119,9 @@ RequestContext rc = null; Thread ct = Thread.currentThread(); - if (ct instanceof Map) + if (ct instanceof Worker) { - Map workerAsMap = (Map) ct; - rc = (RequestContext) workerAsMap.get(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE); + rc = (RequestContext) CurrentWorkerContext.getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE); } else { Index: jetspeed-2/components/portal/src/java/org/apache/jetspeed/engine/servlet/ServletRequestImpl.java =================================================================== --- jetspeed-2/components/portal/src/java/org/apache/jetspeed/engine/servlet/ServletRequestImpl.java (revision 483788) +++ jetspeed-2/components/portal/src/java/org/apache/jetspeed/engine/servlet/ServletRequestImpl.java (working copy) @@ -42,6 +42,8 @@ import org.apache.jetspeed.container.url.PortalURL; import org.apache.jetspeed.request.JetspeedRequestContext; import org.apache.jetspeed.request.RequestContext; +import org.apache.jetspeed.aggregator.Worker; +import org.apache.jetspeed.aggregator.CurrentWorkerContext; import org.apache.pluto.om.common.ObjectID; import org.apache.pluto.om.entity.PortletApplicationEntity; import org.apache.pluto.om.entity.PortletEntity; @@ -213,10 +215,9 @@ Thread ct = Thread.currentThread(); - if (ct instanceof Map) + if (ct instanceof Worker) { - Map workerAsMap = (Map) ct; - value = workerAsMap.get(name); + value = CurrentWorkerContext.getAttribute(name); } // If no attribute found, then look up from the request @@ -374,17 +375,15 @@ Thread ct = Thread.currentThread(); - if (ct instanceof Map) + if (ct instanceof Worker) { - Map workerAsMap = (Map) ct; - if (null == value) { - workerAsMap.remove(name); + CurrentWorkerContext.removeAttribute(name); } else { - workerAsMap.put(name, value); + CurrentWorkerContext.setAttribute(name, value); } } Index: jetspeed-2/jetspeed-api/src/java/org/apache/jetspeed/aggregator/CurrentWorkerContext.java =================================================================== --- jetspeed-2/jetspeed-api/src/java/org/apache/jetspeed/aggregator/CurrentWorkerContext.java (revision 0) +++ jetspeed-2/jetspeed-api/src/java/org/apache/jetspeed/aggregator/CurrentWorkerContext.java (revision 0) @@ -0,0 +1,91 @@ +/* + * Copyright 2000-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jetspeed.aggregator; + +import java.util.Enumeration; +import java.util.Hashtable; + +/** + * Maintains a context attributes for the current Thread + * + * @author David Sean Taylor + * @version $Id: $ + */ +public final class CurrentWorkerContext +{ + private static ThreadLocal currentWorkerContext = + new ThreadLocal() { + protected synchronized Object initialValue() { + return new Hashtable(); + } + }; + + private CurrentWorkerContext() + { + } + + /** + * Returns an Enumeration containing the names of the attributes available to this Thread. + * This method returns an empty Enumeration if the thread has no attributes available to it. + */ + public Enumeration getAttributeNames() + { + return ((Hashtable) currentWorkerContext.get()).keys(); + } + + /** + * @return an attribute in the current Thread + * @param attrName Locale for this Thread + */ + public static Object getAttribute(String name) + { + return ((Hashtable) currentWorkerContext.get()).get(name); + } + + /** + * Stores an attribute in this Thread. + *
+ * @param name - a String specifying the name of the attribute + * @param o - the Object to be stored + */ + public static void setAttribute(String name, Object o) + { + if (o != null) { + ((Hashtable) currentWorkerContext.get()).put(name, o); + } else { + removeAttribute(name); + } + } + + /** + * Removes an attribute from this Thread. + *
+ * @param name - a String specifying the name of the attribute + */ + public static void removeAttribute(String name) + { + ((Hashtable) currentWorkerContext.get()).remove(name); + } + + /** + * Removes all attributes from this Thread. + */ + public static void removeAllAttributes() + { + ((Hashtable) currentWorkerContext.get()).clear(); + } + +} Index: jetspeed-2/commons/src/java/org/apache/jetspeed/container/JetspeedContainerServlet.java =================================================================== --- jetspeed-2/commons/src/java/org/apache/jetspeed/container/JetspeedContainerServlet.java (revision 483788) +++ jetspeed-2/commons/src/java/org/apache/jetspeed/container/JetspeedContainerServlet.java (working copy) @@ -20,7 +20,6 @@ import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.StringWriter; -import java.util.Map; import java.util.Timer; import java.util.TimerTask; @@ -45,6 +44,8 @@ import org.apache.jetspeed.services.PortletServices; import org.apache.jetspeed.tools.pamanager.PortletApplicationManagement; import org.apache.jetspeed.util.DirectoryHelper; +import org.apache.jetspeed.aggregator.Worker; +import org.apache.jetspeed.aggregator.CurrentWorkerContext; /** * Jetspeed Container entry point. @@ -204,19 +205,16 @@ Integer method = ContainerConstants.METHOD_NOOP; Portlet portlet = null; boolean destroyPortlet = false; - Map workerAsMap = null; + boolean isParallelMode = false; try { - Thread ct = Thread.currentThread(); - if (ct instanceof Map) + isParallelMode = (Thread.currentThread() instanceof Worker); + + if (isParallelMode) { - workerAsMap = (Map) ct; + method = (Integer) CurrentWorkerContext.getAttribute(ContainerConstants.METHOD_ID); } - if (workerAsMap != null) - { - method = (Integer) workerAsMap.get(ContainerConstants.METHOD_ID); - } else { method = (Integer) request.getAttribute(ContainerConstants.METHOD_ID); @@ -225,10 +223,10 @@ { return; } - if (workerAsMap != null) + if (isParallelMode) { - portlet = (Portlet) workerAsMap.get(ContainerConstants.PORTLET); - portletName = (String) workerAsMap.get(ContainerConstants.PORTLET_NAME); + portlet = (Portlet) CurrentWorkerContext.getAttribute(ContainerConstants.PORTLET); + portletName = (String) CurrentWorkerContext.getAttribute(ContainerConstants.PORTLET_NAME); } else { @@ -251,10 +249,10 @@ RenderRequest renderRequest = null; RenderResponse renderResponse = null; - if (workerAsMap != null) + if (isParallelMode) { - renderRequest = (RenderRequest) workerAsMap.get(ContainerConstants.PORTLET_REQUEST); - renderResponse = (RenderResponse) workerAsMap.get(ContainerConstants.PORTLET_RESPONSE); + renderRequest = (RenderRequest) CurrentWorkerContext.getAttribute(ContainerConstants.PORTLET_REQUEST); + renderResponse = (RenderResponse) CurrentWorkerContext.getAttribute(ContainerConstants.PORTLET_RESPONSE); } else {