public T storeIfAbsentWindow(T window) { final IPortletWindowId portletWindowId = window.getPortletWindowId(); // Check if the entity already exists (uses a read lock) T existingWindow = this.getWindow(portletWindowId); if (existingWindow != null) { return existingWindow; } writeLock.lock(); try { // Check again inside the write lock existingWindow = this.windowsById.get(portletWindowId); if (existingWindow != null) { return existingWindow; } this.storeWindow(window); } finally { writeLock.unlock(); } return window; }
protected PortletWindowCache<IPortletWindow> getPortletWindowMap(HttpServletRequest request) { request = portalRequestUtils.getOriginalPortletOrPortalRequest(request); final String mapAttributeName = PORTLET_WINDOW_ATTRIBUTE + Thread.currentThread().getId(); // No need to do this in a request attribute mutex since the map is scoped to a specific // thread @SuppressWarnings("unchecked") PortletWindowCache<IPortletWindow> windowCache = (PortletWindowCache<IPortletWindow>) request.getAttribute(mapAttributeName); if (windowCache == null) { windowCache = new PortletWindowCache<>(false); request.setAttribute(mapAttributeName, windowCache); } return windowCache; }
protected void addPortletWindowData( HttpServletRequest request, IPortletEntityId portletEntityId, final Set<IPortletWindow> portletWindows, final PortletWindowCache<IPortletWindow> portletWindowMap, final PortletWindowCache<PortletWindowData> portletWindowDataMap) { final Set<PortletWindowData> windows = portletWindowDataMap.getWindows(portletEntityId); if (windows == null) { return; } for (final PortletWindowData portletWindowData : windows) { final IPortletWindowId portletWindowId = portletWindowData.getPortletWindowId(); // Skip data windows that aren't for this entity and for windows that are already in the // request cache if (!portletEntityId.equals(portletWindowData.getPortletEntityId()) || portletWindowMap.containsWindow(portletWindowId)) { continue; } // Wrap the data in a window and stick it in the request cache IPortletWindow portletWindow = this.wrapPortletWindowData(request, portletWindowData); portletWindow = portletWindowMap.storeIfAbsentWindow(portletWindow); portletWindows.add(portletWindow); } }
@Override public IPortletWindow getOrCreateDefaultPortletWindow( HttpServletRequest request, IPortletEntityId portletEntityId) { Validate.notNull(request, "request can not be null"); Validate.notNull(portletEntityId, "portletEntityId can not be null"); final IPortletWindowId portletWindowId = this.getDefaultPortletWindowId(request, portletEntityId); final PortletWindowCache<IPortletWindow> portletWindowMap = getPortletWindowMap(request); // Check if there is portlet window cached in the request IPortletWindow portletWindow = portletWindowMap.getWindow(portletWindowId); if (portletWindow != null) { logger.trace( "Found IPortletWindow {} in request cache", portletWindow.getPortletWindowId()); return portletWindow; } final PortletWindowData portletWindowData = this.getOrCreateDefaultPortletWindowData(request, portletEntityId, portletWindowId); portletWindow = wrapPortletWindowData(request, portletWindowData); if (portletWindow == null) { return null; } // Cache the wrapped window in the request return portletWindowMap.storeIfAbsentWindow(portletWindow); }
@Test public void storeIfAbsentWindowTest() { portletWindowCache.storeIfAbsentWindow(portletWindowDescriptor); Set windows = portletWindowCache.getWindows(portletEntityId); assertNotNull(windows); assertEquals(windows.size(), 1); IPortletWindowDescriptor _descriptor_ = (IPortletWindowDescriptor) windows.iterator().next(); assertEquals(_descriptor_.getPortletEntityId(), portletEntityId); assertEquals(_descriptor_.getPortletWindowId(), portletWindowId); IPortletWindowDescriptor _portletWindowDescriptor_ = portletWindowCache.getWindow(portletWindowId); assertEquals(_portletWindowDescriptor_.getPortletEntityId(), portletEntityId); } }
protected PortletWindowData getPortletWindowData( HttpServletRequest request, IPortletWindowId portletWindowId) { final PortletWindowCache<PortletWindowData> portletWindowDataMap = getPortletWindowDataMap(request, false); if (portletWindowDataMap == null) { return null; } final PortletWindowData portletWindowData = portletWindowDataMap.getWindow(portletWindowId); if (portletWindowData == null) { logger.trace("No PortletWindowData {} in session cache", portletWindowId); return null; } logger.trace( "Found PortletWindowData {} in session cache", portletWindowData.getPortletWindowId()); return portletWindowData; }
new LinkedHashSet<>(portletWindowMap.getWindows(portletEntityId));
statelessPortletWindowDataMap.storeWindow(portletWindowData); portletWindowData.setRenderParameters(basePortletWindow.getRenderParameters()); statelessPortletWindowDataMap.storeWindow(portletWindowData); portletWindowMap.storeWindow(statelessPortletWindow);
public Set<T> getWindows(IPortletEntityId portletEntityId) { if (this.windowSetByEntityId.isEmpty()) { return null; } readLock.lock(); try { final Set<T> windowSet = this.getWindowSet(portletEntityId, false); if (windowSet == null) { return Collections.emptySet(); } return Collections.unmodifiableSet(windowSet); } finally { readLock.unlock(); } }
@Override public IPortletWindow getOrCreateDefaultPortletWindow( HttpServletRequest request, IPortletEntityId portletEntityId) { Validate.notNull(request, "request can not be null"); Validate.notNull(portletEntityId, "portletEntityId can not be null"); final IPortletWindowId portletWindowId = this.getDefaultPortletWindowId(request, portletEntityId); final PortletWindowCache<IPortletWindow> portletWindowMap = getPortletWindowMap(request); // Check if there is portlet window cached in the request IPortletWindow portletWindow = portletWindowMap.getWindow(portletWindowId); if (portletWindow != null) { logger.trace( "Found IPortletWindow {} in request cache", portletWindow.getPortletWindowId()); return portletWindow; } final PortletWindowData portletWindowData = this.getOrCreateDefaultPortletWindowData(request, portletEntityId, portletWindowId); portletWindow = wrapPortletWindowData(request, portletWindowData); if (portletWindow == null) { return null; } // Cache the wrapped window in the request return portletWindowMap.storeIfAbsentWindow(portletWindow); }
protected PortletWindowData getPortletWindowData( HttpServletRequest request, IPortletWindowId portletWindowId) { final PortletWindowCache<PortletWindowData> portletWindowDataMap = getPortletWindowDataMap(request, false); if (portletWindowDataMap == null) { return null; } final PortletWindowData portletWindowData = portletWindowDataMap.getWindow(portletWindowId); if (portletWindowData == null) { logger.trace("No PortletWindowData {} in session cache", portletWindowId); return null; } logger.trace( "Found PortletWindowData {} in session cache", portletWindowData.getPortletWindowId()); return portletWindowData; }
new LinkedHashSet<>(portletWindowMap.getWindows(portletEntityId));
statelessPortletWindowDataMap.storeWindow(portletWindowData); portletWindowData.setRenderParameters(basePortletWindow.getRenderParameters()); statelessPortletWindowDataMap.storeWindow(portletWindowData); portletWindowMap.storeWindow(statelessPortletWindow);
public void storeWindow(T window) { writeLock.lock(); try { final IPortletEntityId portletEntityId = window.getPortletEntityId(); final Set<T> windowSet = this.getWindowSet(portletEntityId, true); windowSet.add(window); final IPortletWindowId portletWindowId = window.getPortletWindowId(); this.windowsById.put(portletWindowId, window); } finally { writeLock.unlock(); } }
@Override public IPortletWindow createDelegatePortletWindow( HttpServletRequest request, IPortletEntityId portletEntityId, IPortletWindowId delegationParentId) { Validate.notNull(request, "request can not be null"); Validate.notNull(portletEntityId, "portletEntityId can not be null"); // TODO does a delegate portlet entity need some sort of special treatment or do we just // assume that the calling code is using one? final IPortletWindowId portletWindowId = this.getDefaultPortletWindowId(request, portletEntityId); final PortletWindowCache<IPortletWindow> portletWindowMap = getPortletWindowMap(request); // Check if there is portlet window cached in the request IPortletWindow portletWindow = portletWindowMap.getWindow(portletWindowId); if (portletWindow != null) { logger.trace( "Found IPortletWindow {} in request cache", portletWindow.getPortletWindowId()); return portletWindow; } final PortletWindowData portletWindowData = this.getOrCreateDefaultPortletWindowData( request, portletEntityId, portletWindowId, delegationParentId); portletWindow = wrapPortletWindowData(request, portletWindowData); if (portletWindow == null) { return null; } // Cache the wrapped window in the request return portletWindowMap.storeIfAbsentWindow(portletWindow); }
protected void addPortletWindowData( HttpServletRequest request, IPortletEntityId portletEntityId, final Set<IPortletWindow> portletWindows, final PortletWindowCache<IPortletWindow> portletWindowMap, final PortletWindowCache<PortletWindowData> portletWindowDataMap) { final Set<PortletWindowData> windows = portletWindowDataMap.getWindows(portletEntityId); if (windows == null) { return; } for (final PortletWindowData portletWindowData : windows) { final IPortletWindowId portletWindowId = portletWindowData.getPortletWindowId(); // Skip data windows that aren't for this entity and for windows that are already in the // request cache if (!portletEntityId.equals(portletWindowData.getPortletEntityId()) || portletWindowMap.containsWindow(portletWindowId)) { continue; } // Wrap the data in a window and stick it in the request cache IPortletWindow portletWindow = this.wrapPortletWindowData(request, portletWindowData); portletWindow = portletWindowMap.storeIfAbsentWindow(portletWindow); portletWindows.add(portletWindow); } }
protected PortletWindowCache<IPortletWindow> getPortletWindowMap(HttpServletRequest request) { request = portalRequestUtils.getOriginalPortletOrPortalRequest(request); final String mapAttributeName = PORTLET_WINDOW_ATTRIBUTE + Thread.currentThread().getId(); // No need to do this in a request attribute mutex since the map is scoped to a specific // thread @SuppressWarnings("unchecked") PortletWindowCache<IPortletWindow> windowCache = (PortletWindowCache<IPortletWindow>) request.getAttribute(mapAttributeName); if (windowCache == null) { windowCache = new PortletWindowCache<>(false); request.setAttribute(mapAttributeName, windowCache); } return windowCache; }
@Override public IPortletWindow createDelegatePortletWindow( HttpServletRequest request, IPortletEntityId portletEntityId, IPortletWindowId delegationParentId) { Validate.notNull(request, "request can not be null"); Validate.notNull(portletEntityId, "portletEntityId can not be null"); // TODO does a delegate portlet entity need some sort of special treatment or do we just // assume that the calling code is using one? final IPortletWindowId portletWindowId = this.getDefaultPortletWindowId(request, portletEntityId); final PortletWindowCache<IPortletWindow> portletWindowMap = getPortletWindowMap(request); // Check if there is portlet window cached in the request IPortletWindow portletWindow = portletWindowMap.getWindow(portletWindowId); if (portletWindow != null) { logger.trace( "Found IPortletWindow {} in request cache", portletWindow.getPortletWindowId()); return portletWindow; } final PortletWindowData portletWindowData = this.getOrCreateDefaultPortletWindowData( request, portletEntityId, portletWindowId, delegationParentId); portletWindow = wrapPortletWindowData(request, portletWindowData); if (portletWindow == null) { return null; } // Cache the wrapped window in the request return portletWindowMap.storeIfAbsentWindow(portletWindow); }
@SuppressWarnings("unchecked") protected PortletWindowCache<PortletWindowData> getStatelessPortletWindowDataMap( HttpServletRequest request) { request = portalRequestUtils.getOriginalPortalRequest(request); PortletWindowCache<PortletWindowData> windowCache; final Object mutex = PortalWebUtils.getRequestAttributeMutex(request); synchronized (mutex) { windowCache = (PortletWindowCache<PortletWindowData>) request.getAttribute(PORTLET_WINDOW_DATA_ATTRIBUTE); if (windowCache == null) { windowCache = new PortletWindowCache<>(); request.setAttribute(PORTLET_WINDOW_DATA_ATTRIBUTE, windowCache); } } return windowCache; }
IPortletWindow portletWindow = portletWindowMap.getWindow(portletWindowId); if (portletWindow != null) { logger.trace( this.getStatelessPortletWindowDataMap(request); if (statelessPortletWindowDataMap != null) { portletWindowData = statelessPortletWindowDataMap.getWindow(portletWindowId); } else { portletWindowData = null; return portletWindowMap.storeIfAbsentWindow(portletWindow);