Hi Ruolin,
Reviewed your change, no comments from myself, please go ahead to commit
the code to 2.2.8, thanks.
BR,
Zhijun
On 3/30/16, 22:38, Ruolin Li wrote:
> Hi, guys,
>
> Please help review the change by JAVASERVERFACES-4111,
> it's the BACKPORT for JAVASERVERFACES-4106 to 2.2.8 .
>
> JAVASERVERFACES-4106 was created to enhance the access
> to WebappLifecycleListener#activeSessions, making the access thread-safe.
>
> The change includes one file only, i.e.
> "jsf-ri/src/main/java/com/sun/faces/application/WebappLifecycleListener.java".
>
> Below is the result of "git diff ". And, attached is the modified file.
>
> ===============
> ruolli_at_ruolli-Ubuntu: ~/GIT/mojarra~git $ git diff HEAD^ HEAD
> diff --git
> a/jsf-ri/src/main/java/com/sun/faces/application/WebappLifecycleListener.javab/jsf-ri/src/main/java/com/sun/faces/application/WebappLifecycleListener.java
> index b902c32..ddfd265 100644
> ---
> a/jsf-ri/src/main/java/com/sun/faces/application/WebappLifecycleListener.java
> +++
> b/jsf-ri/src/main/java/com/sun/faces/application/WebappLifecycleListener.java
> @@ -85,17 +85,50 @@ public class WebappLifecycleListener {
>
> private ServletContext servletContext;
> private ApplicationAssociate applicationAssociate;
> - private List<HttpSession> activeSessions;
> + private ActiveSessions activeSessions;
>
> + /*
> + * An inner class to provide synchronized access to activeSessions
> + */
> + class ActiveSessions {
> +
> + private List<HttpSession> activeSessions;
> +
> + public ActiveSessions() {
> + activeSessions = new ArrayList();
> + }
> +
> + public synchronized void add(HttpSession hs) {
> + if (activeSessions == null) {
> + activeSessions = new ArrayList();
> + }
> + activeSessions.add(hs);
> + }
> +
> + public synchronized void remove(HttpSession hs) {
> + if (activeSessions != null) {
> + activeSessions.remove(hs);
> + }
> + }
> +
> + public synchronized List<HttpSession> get() {
> + return new ArrayList(activeSessions);
> + }
> +
> + }
>
> // ------------------------------------------------------------
> Constructors
>
>
> - public WebappLifecycleListener() { }
> + public WebappLifecycleListener() {
> + this.activeSessions = new ActiveSessions();
> + }
> +
>
> public WebappLifecycleListener(ServletContext servletContext) {
>
> this.servletContext = servletContext;
> + this.activeSessions = new ActiveSessions();
>
> }
>
> @@ -158,10 +191,7 @@ public class WebappLifecycleListener {
> public void sessionCreated(HttpSessionEvent event) {
> ApplicationAssociate associate = getAssociate();
> // PENDING this should only create a new list if in dev mode
> - if (associate != null && associate.isDevModeEnabled()) {
> - if (activeSessions == null) {
> - activeSessions = new ArrayList<HttpSession>();
> - }
> + if (associate != null && associate.isDevModeEnabled()) {
> activeSessions.add(event.getSession());
> }
> boolean doCreateToken = true;
> @@ -186,9 +216,7 @@ public class WebappLifecycleListener {
> * @param event the notification event
> */
> public void sessionDestroyed(HttpSessionEvent event) {
> - if (activeSessions != null) {
> - activeSessions.remove(event.getSession());
> - }
> + activeSessions.remove(event.getSession());
>
> if (Util.isCDIAvailable(servletContext)) {
> FlowCDIContext.sessionDestroyed(event);
> @@ -376,7 +404,7 @@ public class WebappLifecycleListener {
>
>
> public List<HttpSession> getActiveSessions() {
> - return new ArrayList<HttpSession>(activeSessions);
> + return activeSessions.get();
> }
>
>
> (END)
>
> ===============
>
> Thanks and best regards
> Ruolin
>
> --
> Ruolin Li (ruolin.li_at_oracle.com)
> Oracle Weblogic Server WebApp Container Team
> 86 10 61065387