myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tandrasc...@apache.org
Subject [myfaces] branch master updated: refactored
Date Sun, 14 Apr 2019 18:42:28 GMT
This is an automated email from the ASF dual-hosted git repository.

tandraschko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces.git


The following commit(s) were added to refs/heads/master by this push:
     new 508a340  refactored
508a340 is described below

commit 508a340a61a8231a9d09f97c57e28b82527e0e62
Author: Thomas Andraschko <tandraschko@apache.org>
AuthorDate: Sun Apr 14 20:42:21 2019 +0200

    refactored
---
 .../myfaces/push/cdi/PushContextFactoryBean.java   |  4 ---
 .../apache/myfaces/push/cdi/PushContextImpl.java   | 10 +-------
 .../myfaces/push/cdi/WebsocketApplicationBean.java | 17 +++++--------
 .../cdi/WebsocketApplicationSessionHolder.java     | 15 +----------
 .../apache/myfaces/push/cdi/WebsocketChannel.java  |  6 -----
 .../push/cdi/WebsocketChannelTokenBuilderBean.java |  2 +-
 .../myfaces/push/cdi/WebsocketSessionBean.java     | 15 +++++------
 .../apache/myfaces/push/cdi/WebsocketViewBean.java | 29 ++++++----------------
 8 files changed, 22 insertions(+), 76 deletions(-)

diff --git a/impl/src/main/java/org/apache/myfaces/push/cdi/PushContextFactoryBean.java b/impl/src/main/java/org/apache/myfaces/push/cdi/PushContextFactoryBean.java
index b3b58b3..a467b32 100644
--- a/impl/src/main/java/org/apache/myfaces/push/cdi/PushContextFactoryBean.java
+++ b/impl/src/main/java/org/apache/myfaces/push/cdi/PushContextFactoryBean.java
@@ -26,14 +26,10 @@ import javax.faces.push.Push;
 import javax.faces.push.PushContext;
 import javax.inject.Named;
 
-/**
- *
- */
 @Named(PushContextFactoryBean.PUSH_CONTEXT_FACTORY_BEAN_NAME)
 @ApplicationScoped
 public class PushContextFactoryBean
 {
-
     protected static final String PUSH_CONTEXT_FACTORY_BEAN_NAME
             = "oam_PUSH_CONTEXT_FACTORY_BEAN_NAME";
     
diff --git a/impl/src/main/java/org/apache/myfaces/push/cdi/PushContextImpl.java b/impl/src/main/java/org/apache/myfaces/push/cdi/PushContextImpl.java
index 79301a6..2892094 100644
--- a/impl/src/main/java/org/apache/myfaces/push/cdi/PushContextImpl.java
+++ b/impl/src/main/java/org/apache/myfaces/push/cdi/PushContextImpl.java
@@ -34,12 +34,8 @@ import javax.faces.context.FacesContext;
 import javax.faces.push.PushContext;
 import org.apache.myfaces.cdi.util.CDIUtils;
 
-/**
- *
- */
 public class PushContextImpl implements PushContext
 {
-    
     private final String channel;
 
     public PushContextImpl(String channel)
@@ -47,9 +43,6 @@ public class PushContextImpl implements PushContext
         this.channel = channel;
     }
 
-    /**
-     * @return the channel
-     */
     public String getChannel()
     {
         return channel;
@@ -212,8 +205,7 @@ public class PushContextImpl implements PushContext
         return result;
     }
     
-    private Set<Future<Void>> send(
-            List<String> channelTokens, Object message)
+    private Set<Future<Void>> send(List<String> channelTokens, Object message)
     {
         if (channelTokens != null && !channelTokens.isEmpty())
         {
diff --git a/impl/src/main/java/org/apache/myfaces/push/cdi/WebsocketApplicationBean.java
b/impl/src/main/java/org/apache/myfaces/push/cdi/WebsocketApplicationBean.java
index bc663f3..dac1f58 100644
--- a/impl/src/main/java/org/apache/myfaces/push/cdi/WebsocketApplicationBean.java
+++ b/impl/src/main/java/org/apache/myfaces/push/cdi/WebsocketApplicationBean.java
@@ -27,26 +27,21 @@ import java.util.List;
 import java.util.Map;
 import javax.enterprise.context.ApplicationScoped;
 
-/**
- *
- */
 @ApplicationScoped
 public class WebsocketApplicationBean
 {
-    
+   
     /**
      * This map has as key the channel and as values a list of websocket channels
      */
-    private Map<String, List<WebsocketChannel> > channelTokenListMap = 
-        new HashMap<String, List<WebsocketChannel> >(2);
+    private Map<String, List<WebsocketChannel> > channelTokenListMap = new HashMap<>(2);
 
     public void registerWebsocketSession(String token, WebsocketChannelMetadata metadata)
     {
         if ("application".equals(metadata.getScope()))
         {
-            channelTokenListMap.putIfAbsent(metadata.getChannel(), new ArrayList<WebsocketChannel>(1));
-            channelTokenListMap.get(metadata.getChannel()).add(new WebsocketChannel(
-                    token, metadata));
+            channelTokenListMap.putIfAbsent(metadata.getChannel(), new ArrayList<>(1));
+            channelTokenListMap.get(metadata.getChannel()).add(new WebsocketChannel(token,
metadata));
         }
     }
     
@@ -68,7 +63,7 @@ public class WebsocketApplicationBean
         List<WebsocketChannel> list = channelTokenListMap.get(channel);
         if (list != null && !list.isEmpty())
         {
-            List<String> value = new ArrayList<String>(list.size());
+            List<String> value = new ArrayList<>(list.size());
             for (WebsocketChannel md : list)
             {
                 value.add(md.getChannelToken());
@@ -83,7 +78,7 @@ public class WebsocketApplicationBean
         List<WebsocketChannel> list = channelTokenListMap.get(channel);
         if (list != null && !list.isEmpty())
         {
-            List<String> value = new ArrayList<String>(list.size());
+            List<String> value = new ArrayList<>(list.size());
             for (WebsocketChannel md : list)
             {
                 if (user.equals(md.getUser()))
diff --git a/impl/src/main/java/org/apache/myfaces/push/cdi/WebsocketApplicationSessionHolder.java
b/impl/src/main/java/org/apache/myfaces/push/cdi/WebsocketApplicationSessionHolder.java
index af5cf18..a01f4cd 100644
--- a/impl/src/main/java/org/apache/myfaces/push/cdi/WebsocketApplicationSessionHolder.java
+++ b/impl/src/main/java/org/apache/myfaces/push/cdi/WebsocketApplicationSessionHolder.java
@@ -38,9 +38,6 @@ import org.apache.myfaces.util.ClassUtils;
 import org.apache.myfaces.util.ConcurrentLRUCache;
 import org.apache.myfaces.util.WebConfigParamUtils;
 
-/**
- *
- */
 public final class WebsocketApplicationSessionHolder
 {
     
@@ -53,11 +50,7 @@ public final class WebsocketApplicationSessionHolder
     
     private volatile static WeakHashMap<ClassLoader, Queue<String>> clWebsocketRestoredQueue
=
             new WeakHashMap<ClassLoader, Queue<String>>();
-    
-    /**
-     * 
-     * @return 
-     */
+
     public static ConcurrentLRUCache<String, Reference<Session>> getWebsocketSessionLRUCache()
     {
         ClassLoader cl = ClassUtils.getContextClassLoader();
@@ -78,10 +71,6 @@ public final class WebsocketApplicationSessionHolder
         return metadata;
     }
 
-    /**
-     * 
-     * @param context
-     */
     public static void initWebsocketSessionLRUCache(ExternalContext context)
     {
         ClassLoader cl = ClassUtils.getContextClassLoader();
@@ -133,8 +122,6 @@ public final class WebsocketApplicationSessionHolder
         }
         return metadata;
     }
-    
-            
 
     /**
      * Removes the cached MetadataTarget instances in order to prevent a memory leak.
diff --git a/impl/src/main/java/org/apache/myfaces/push/cdi/WebsocketChannel.java b/impl/src/main/java/org/apache/myfaces/push/cdi/WebsocketChannel.java
index 6c9fc63..9c5adec 100644
--- a/impl/src/main/java/org/apache/myfaces/push/cdi/WebsocketChannel.java
+++ b/impl/src/main/java/org/apache/myfaces/push/cdi/WebsocketChannel.java
@@ -22,9 +22,6 @@ package org.apache.myfaces.push.cdi;
 import java.io.Serializable;
 import java.util.Objects;
 
-/**
- *
- */
 public class WebsocketChannel implements Serializable
 {
     private String channelToken;
@@ -56,9 +53,6 @@ public class WebsocketChannel implements Serializable
         return metadata.getUser();
     }
 
-    /**
-     * @return the channel
-     */
     public String getChannel()
     {
         return metadata.getChannel();
diff --git a/impl/src/main/java/org/apache/myfaces/push/cdi/WebsocketChannelTokenBuilderBean.java
b/impl/src/main/java/org/apache/myfaces/push/cdi/WebsocketChannelTokenBuilderBean.java
index 892667d..79a67f3 100644
--- a/impl/src/main/java/org/apache/myfaces/push/cdi/WebsocketChannelTokenBuilderBean.java
+++ b/impl/src/main/java/org/apache/myfaces/push/cdi/WebsocketChannelTokenBuilderBean.java
@@ -55,7 +55,7 @@ public class WebsocketChannelTokenBuilderBean
         {
             csrfSessionTokenFactory = new RandomCsrfSessionTokenFactory(facesContext);
         }        
-        initialized=true;
+        initialized = true;
     }
     
     public String createChannelToken(FacesContext facesContext, String channel)
diff --git a/impl/src/main/java/org/apache/myfaces/push/cdi/WebsocketSessionBean.java b/impl/src/main/java/org/apache/myfaces/push/cdi/WebsocketSessionBean.java
index 5ec60c3..45ce6ce 100644
--- a/impl/src/main/java/org/apache/myfaces/push/cdi/WebsocketSessionBean.java
+++ b/impl/src/main/java/org/apache/myfaces/push/cdi/WebsocketSessionBean.java
@@ -44,16 +44,14 @@ public class WebsocketSessionBean implements Serializable
      * This map hold all tokens that are related to the current scope. 
      * This map use as key channel and as value channelTokens
      */
-    private Map<String, List<WebsocketChannel> > channelTokenListMap = 
-            new ConcurrentHashMap<String, List<WebsocketChannel> >(2);    
+    private Map<String, List<WebsocketChannel> > channelTokenListMap = new ConcurrentHashMap<>(2);
   
     
     /**
      * This map holds all tokens related to the current session and its associated metadata,
that will
      * be used in the websocket handshake to validate if the incoming request is valid and
to store
      * the user object into the Session object.
      */
-    private Map<String, WebsocketChannelMetadata> tokenMap = 
-        new ConcurrentHashMap<String, WebsocketChannelMetadata>();
+    private Map<String, WebsocketChannelMetadata> tokenMap = new ConcurrentHashMap<>();
     
     public WebsocketSessionBean()
     {
@@ -68,9 +66,8 @@ public class WebsocketSessionBean implements Serializable
     {
         if ("session".equals(metadata.getScope()))
         {
-            channelTokenListMap.putIfAbsent(metadata.getChannel(), new ArrayList<WebsocketChannel>(1));
-            channelTokenListMap.get(metadata.getChannel()).add(new WebsocketChannel(
-                    token, metadata));
+            channelTokenListMap.putIfAbsent(metadata.getChannel(), new ArrayList<>(1));
+            channelTokenListMap.get(metadata.getChannel()).add(new WebsocketChannel(token,
metadata));
         }
     }
     
@@ -110,7 +107,7 @@ public class WebsocketSessionBean implements Serializable
         List<WebsocketChannel> list = channelTokenListMap.get(channel);
         if (list != null && !list.isEmpty())
         {
-            List<String> value = new ArrayList<String>(list.size());
+            List<String> value = new ArrayList<>(list.size());
             for (WebsocketChannel md : list)
             {
                 value.add(md.getChannelToken());
@@ -125,7 +122,7 @@ public class WebsocketSessionBean implements Serializable
         List<WebsocketChannel> list = channelTokenListMap.get(channel);
         if (list != null && !list.isEmpty())
         {
-            List<String> value = new ArrayList<String>(list.size());
+            List<String> value = new ArrayList<>(list.size());
             for (WebsocketChannel md : list)
             {
                 if (user.equals(md.getUser()))
diff --git a/impl/src/main/java/org/apache/myfaces/push/cdi/WebsocketViewBean.java b/impl/src/main/java/org/apache/myfaces/push/cdi/WebsocketViewBean.java
index ea75322..bf5a5fd 100644
--- a/impl/src/main/java/org/apache/myfaces/push/cdi/WebsocketViewBean.java
+++ b/impl/src/main/java/org/apache/myfaces/push/cdi/WebsocketViewBean.java
@@ -42,9 +42,8 @@ public class WebsocketViewBean implements Serializable
      * This map hold all tokens that are related to the current scope. 
      * This map use as key channel and as value channelTokens
      */
-    private Map<String, List<WebsocketChannel> > channelTokenListMap = 
-            new HashMap<String, List<WebsocketChannel> >(2);
-    
+    private Map<String, List<WebsocketChannel>> channelTokenListMap = new HashMap<>(2);
+
     /**
      * This map hold all tokens related to the current view. The reason to do this is the
connections must follow
      * the same rules the view has, so if a view is disposed, all related websocket sessions
must be disposed too
@@ -55,7 +54,7 @@ public class WebsocketViewBean implements Serializable
      * per view. In that way, the token can be used to identify on the client if a websocket
initialization request
      * can share a websocket connection or not, simplifying code design.
      */
-    private Map<String, WebsocketChannelMetadata> tokenList = new HashMap<String,
WebsocketChannelMetadata>(2);
+    private Map<String, WebsocketChannelMetadata> tokenList = new HashMap<>(2);
     
     public void registerToken(String token, WebsocketChannelMetadata metadata)
     {
@@ -66,26 +65,12 @@ public class WebsocketViewBean implements Serializable
     {
         if ("view".equals(metadata.getScope()))
         {
-            channelTokenListMap.putIfAbsent(metadata.getChannel(), new ArrayList<WebsocketChannel>(1));
+            channelTokenListMap.putIfAbsent(metadata.getChannel(), new ArrayList<>(1));
             channelTokenListMap.get(metadata.getChannel()).add(new WebsocketChannel(
                     token, metadata));
         }
     }
-    
-    public boolean isSessionTokenValid(String token)
-    {
-        boolean valid = false;
-        for (List<WebsocketChannel> chlist : channelTokenListMap.values())
-        {
-            if (chlist.contains(token))
-            {
-                valid = true;
-                break;
-            }
-        }
-        return valid;
-    }
-    
+
     /**
      * Indicate if the channel mentioned is valid for view scope.
      * 
@@ -104,7 +89,7 @@ public class WebsocketViewBean implements Serializable
         List<WebsocketChannel> list = channelTokenListMap.get(channel);
         if (list != null && !list.isEmpty())
         {
-            List<String> value = new ArrayList<String>(list.size());
+            List<String> value = new ArrayList<>(list.size());
             for (WebsocketChannel md : list)
             {
                 value.add(md.getChannelToken());
@@ -138,7 +123,7 @@ public class WebsocketViewBean implements Serializable
         List<WebsocketChannel> list = channelTokenListMap.get(channel);
         if (list != null && !list.isEmpty())
         {
-            List<String> value = new ArrayList<String>(list.size());
+            List<String> value = new ArrayList<>(list.size());
             for (WebsocketChannel md : list)
             {
                 if (user.equals(md.getUser()))


Mime
View raw message