Hi Ruolin,
Please go ahead with the committing of the code to master.
r=ren.zhijun.oracle for commit to master.
BR,
Zhijun
On 3/14/16, 17:01, Ruolin Li wrote:
>
> 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 ".
>
> ==============
> ruolli_at_ruolli-Ubuntu: ~/GIT/mojarra~git $ git diff
> 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 cd22afb..6152b9a 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
> @@ -87,17 +87,49 @@ 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();
>
> }
>
> @@ -173,10 +205,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<>();
> - }
> + if (associate != null && associate.isDevModeEnabled()) {
> activeSessions.add(event.getSession());
> }
> boolean doCreateToken = true;
> @@ -201,9 +230,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);
> @@ -391,7 +418,7 @@ public class WebappLifecycleListener {
>
>
> public List<HttpSession> getActiveSessions() {
> - return new ArrayList<>(activeSessions);
> + return activeSessions.get();
> }
>
>
> (END)
>
> ==============
>
> Thanks and best regards
> Ruolin
>
>
> On 03/14/2016 04:52 PM, Ruolin Li wrote:
>> Hi, guys,
>>
>> Please help review the fix on JAVASERVERFACES-4106.
>>
>> JAVASERVERFACES-4106 was created to enhance the access
>> to WebappLifecycleListener#activeSessions, making the access
>> thread-safe.
>>
>> I drafted a fix by defining an inner class ActiveSessions,
>> which provides thread-safe access to its data member activeSessions.
>>
>> Below is the result from "git diff
>> jsf-ri/src/main/java/com/sun/faces/application/WebappLifecycleListener.java
>> ".
>> And, attached is the modified file.
>>
>> =============
>>
>> ruolli_at_ruolli-Ubuntu: ~/GIT/mojarra~git $ git diff
>> jsf-ri/src/main/java/com/sun/faces/application/WebappLifecycleListener.java
>>
>> 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 cd22afb..6152b9a 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
>> @@ -87,17 +87,49 @@ 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();
>>
>> }
>>
>> @@ -173,10 +205,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<>();
>> - }
>> + if (associate != null && associate.isDevModeEnabled()) {
>> activeSessions.add(event.getSession());
>> }
>> boolean doCreateToken = true;
>> @@ -201,9 +230,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);
>> @@ -391,7 +418,7 @@ public class WebappLifecycleListener {
>>
>>
>> public List<HttpSession> getActiveSessions() {
>> - return new ArrayList<>(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
>
> --
> Ruolin Li (ruolin.li_at_oracle.com)
> Oracle Weblogic Server WebApp Container Team
> 86 10 61065387