Skip to content

Commit

Permalink
introduce ClientWindow.NUMBER_OF_CLIENT_WINDOWS_PARAM_NAME
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Straßer <christoph.strasser78@gmail.com>
  • Loading branch information
christophs78 committed May 2, 2021
1 parent 167848a commit 20f8727
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ public void sessionDestroyed(HttpSessionEvent event) {
viewScopeManager.sessionDestroyed(event);
}


ClientWindowScopeManager clientWindowScopeManager = (ClientWindowScopeManager) servletContext.getAttribute(CLIENT_WINDOW_SCOPE_MANAGER);
if (clientWindowScopeManager != null) {
clientWindowScopeManager.sessionDestroyed(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@

import com.sun.faces.config.WebConfiguration;
import com.sun.faces.util.FacesLogger;
import com.sun.faces.util.LRUMap;
import jakarta.enterprise.context.spi.Contextual;
import jakarta.enterprise.context.spi.CreationalContext;
import jakarta.enterprise.inject.spi.BeanManager;
import jakarta.enterprise.inject.spi.PassivationCapable;
import jakarta.faces.context.ExternalContext;
import jakarta.faces.context.FacesContext;
import jakarta.faces.lifecycle.ClientWindow;
import jakarta.servlet.http.HttpSession;
import jakarta.servlet.http.HttpSessionEvent;

import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
Expand All @@ -43,9 +46,6 @@ public class ClientWindowScopeContextManager {

private static final Logger LOGGER = FacesLogger.CLIENTWINDOW.getLogger();

/**
* Stores the constant to keep track of all the active clientWindow scope contexts.
*/
private static final String CLIENT_WINDOW_CONTEXTS = "com.sun.faces.cdi.clientwindow.clientWindowContexts";

private final BeanManager beanManager;
Expand Down Expand Up @@ -146,16 +146,17 @@ private Map<String, ClientWindowScopeContextObject> getContextMap(FacesContext f

if (clientWindowScopeContexts == null && create) {
synchronized (session) {
clientWindowScopeContexts = new ConcurrentHashMap<>();
sessionMap.put(CLIENT_WINDOW_CONTEXTS, clientWindowScopeContexts);
Integer size = (Integer) sessionMap.get(ClientWindow.NUMBER_OF_CLIENT_WINDOWS_PARAM_NAME);
if (size == null) {
size = 10;
}
sessionMap.put(CLIENT_WINDOW_CONTEXTS, Collections.synchronizedMap(new LRUMap<String, Object>(size)));
}
}

if (clientWindowScopeContexts != null && clientWindowId != null && create) {
synchronized (clientWindowScopeContexts) {
if (!clientWindowScopeContexts.containsKey(clientWindowId)) {
// TODO: limit the amount of client-windows (eg throw out the oldest ones after some (configureable) limit is exceeded)

clientWindowScopeContexts.put(clientWindowId,
new ConcurrentHashMap<String, ClientWindowScopeContextObject>());
if (distributable) {
Expand Down
10 changes: 10 additions & 0 deletions impl/src/main/java/jakarta/faces/lifecycle/ClientWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ public abstract class ClientWindow {
*/
public static final String CLIENT_WINDOW_MODE_PARAM_NAME = "jakarta.faces.CLIENT_WINDOW_MODE";

/**
* <p class="changed_added_4_0">
* Indicate the max number of ClientWindows, which is used by {@link ClientWindowScoped}.
* It is only active when jakarta.faces.CLIENT_WINDOW_MODE is enabled.
* </p>
*
* @since 4.0
*/
public static final String NUMBER_OF_CLIENT_WINDOWS_PARAM_NAME = "jakarta.faces.NUMBER_OF_CLIENT_WINDOWS";

/**
* <p class="changed_added_2_2">
* This method will be called whenever a URL is generated by the runtime where client window related parameters need to
Expand Down

0 comments on commit 20f8727

Please sign in to comment.