You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2015/06/15 14:33:59 UTC

svn commit: r1685570 - in /tomcat/tc7.0.x/trunk: java/org/apache/tomcat/websocket/WsSession.java java/org/apache/tomcat/websocket/WsWebSocketContainer.java test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java webapps/docs/changelog.xml

Author: remm
Date: Mon Jun 15 12:33:59 2015
New Revision: 1685570

URL: http://svn.apache.org/r1685570
Log:
Port r1685562 57974: Key the open session map on the endpoint instance rather than endpoint class.

Modified:
    tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/WsSession.java
    tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
    tomcat/tc7.0.x/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml

Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/WsSession.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/WsSession.java?rev=1685570&r1=1685569&r2=1685570&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/WsSession.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/WsSession.java Mon Jun 15 12:33:59 2015
@@ -393,7 +393,7 @@ public class WsSession implements Sessio
     @Override
     public Set<Session> getOpenSessions() {
         checkState();
-        return webSocketContainer.getOpenSessions(localEndpoint.getClass());
+        return webSocketContainer.getOpenSessions(localEndpoint);
     }
 
 

Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java?rev=1685570&r1=1685569&r2=1685570&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java Mon Jun 15 12:33:59 2015
@@ -115,8 +115,8 @@ public class WsWebSocketContainer
     private final Object asynchronousChannelGroupLock = new Object();
 
     private final Log log = LogFactory.getLog(WsWebSocketContainer.class);
-    private final Map<Class<?>, Set<WsSession>> endpointSessionMap =
-            new HashMap<Class<?>, Set<WsSession>>();
+    private final Map<Endpoint, Set<WsSession>> endpointSessionMap =
+            new HashMap<Endpoint, Set<WsSession>>();
     private final Map<WsSession,WsSession> sessions = new ConcurrentHashMap<WsSession, WsSession>();
     private final Object endPointSessionMapLock = new Object();
 
@@ -424,8 +424,6 @@ public class WsWebSocketContainer
 
     protected void registerSession(Endpoint endpoint, WsSession wsSession) {
 
-        Class<?> endpointClazz = endpoint.getClass();
-
         if (!wsSession.isOpen()) {
             // The session was closed during onOpen. No need to register it.
             return;
@@ -434,10 +432,10 @@ public class WsWebSocketContainer
             if (endpointSessionMap.size() == 0) {
                 BackgroundProcessManager.getInstance().register(this);
             }
-            Set<WsSession> wsSessions = endpointSessionMap.get(endpointClazz);
+            Set<WsSession> wsSessions = endpointSessionMap.get(endpoint);
             if (wsSessions == null) {
                 wsSessions = new HashSet<WsSession>();
-                endpointSessionMap.put(endpointClazz, wsSessions);
+                endpointSessionMap.put(endpoint, wsSessions);
             }
             wsSessions.add(wsSession);
         }
@@ -447,14 +445,12 @@ public class WsWebSocketContainer
 
     protected void unregisterSession(Endpoint endpoint, WsSession wsSession) {
 
-        Class<?> endpointClazz = endpoint.getClass();
-
         synchronized (endPointSessionMapLock) {
-            Set<WsSession> wsSessions = endpointSessionMap.get(endpointClazz);
+            Set<WsSession> wsSessions = endpointSessionMap.get(endpoint);
             if (wsSessions != null) {
                 wsSessions.remove(wsSession);
                 if (wsSessions.size() == 0) {
-                    endpointSessionMap.remove(endpointClazz);
+                    endpointSessionMap.remove(endpoint);
                 }
             }
             if (endpointSessionMap.size() == 0) {
@@ -465,7 +461,7 @@ public class WsWebSocketContainer
     }
 
 
-    Set<Session> getOpenSessions(Class<?> endpoint) {
+    Set<Session> getOpenSessions(Endpoint endpoint) {
         HashSet<Session> result = new HashSet<Session>();
         synchronized (endPointSessionMapLock) {
             Set<WsSession> sessions = endpointSessionMap.get(endpoint);

Modified: tomcat/tc7.0.x/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java?rev=1685570&r1=1685569&r2=1685570&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java Mon Jun 15 12:33:59 2015
@@ -49,7 +49,6 @@ import javax.websocket.server.ServerEndp
 import org.junit.Assert;
 import org.junit.Assume;
 import org.junit.Test;
-
 import org.apache.catalina.Context;
 import org.apache.catalina.servlets.DefaultServlet;
 import org.apache.catalina.startup.Tomcat;
@@ -596,16 +595,18 @@ public class TestWsWebSocketContainer ex
         WebSocketContainer wsContainer =
                 ContainerProvider.getWebSocketContainer();
 
-        Session s1a = connectToEchoServer(wsContainer, EndpointA.class,
+        EndpointA endpointA = new EndpointA();
+        Session s1a = connectToEchoServer(wsContainer, endpointA,
                 TesterEchoServer.Config.PATH_BASIC);
-        Session s2a = connectToEchoServer(wsContainer, EndpointA.class,
+        Session s2a = connectToEchoServer(wsContainer, endpointA,
                 TesterEchoServer.Config.PATH_BASIC);
-        Session s3a = connectToEchoServer(wsContainer, EndpointA.class,
+        Session s3a = connectToEchoServer(wsContainer, endpointA,
                 TesterEchoServer.Config.PATH_BASIC);
 
-        Session s1b = connectToEchoServer(wsContainer, EndpointB.class,
+        EndpointB endpointB = new EndpointB();
+        Session s1b = connectToEchoServer(wsContainer, endpointB,
                 TesterEchoServer.Config.PATH_BASIC);
-        Session s2b = connectToEchoServer(wsContainer, EndpointB.class,
+        Session s2b = connectToEchoServer(wsContainer, endpointB,
                 TesterEchoServer.Config.PATH_BASIC);
 
         Set<Session> setA = s3a.getOpenSessions();
@@ -649,11 +650,12 @@ public class TestWsWebSocketContainer ex
         wsContainer.setDefaultMaxSessionIdleTimeout(5000);
         wsContainer.setProcessPeriod(1);
 
-        connectToEchoServer(wsContainer, EndpointA.class,
+        EndpointA endpointA = new EndpointA();
+        connectToEchoServer(wsContainer, endpointA,
                 TesterEchoServer.Config.PATH_BASIC);
-        connectToEchoServer(wsContainer, EndpointA.class,
+        connectToEchoServer(wsContainer, endpointA,
                 TesterEchoServer.Config.PATH_BASIC);
-        Session s3a = connectToEchoServer(wsContainer, EndpointA.class,
+        Session s3a = connectToEchoServer(wsContainer, endpointA,
                 TesterEchoServer.Config.PATH_BASIC);
 
         // Check all three sessions are open
@@ -706,13 +708,14 @@ public class TestWsWebSocketContainer ex
         wsContainer.setDefaultMaxSessionIdleTimeout(5000);
         wsContainer.setProcessPeriod(1);
 
-        Session s1a = connectToEchoServer(wsContainer, EndpointA.class,
+        EndpointA endpointA = new EndpointA();
+        Session s1a = connectToEchoServer(wsContainer, endpointA,
                 TesterEchoServer.Config.PATH_BASIC);
         s1a.setMaxIdleTimeout(3000);
-        Session s2a = connectToEchoServer(wsContainer, EndpointA.class,
+        Session s2a = connectToEchoServer(wsContainer, endpointA,
                 TesterEchoServer.Config.PATH_BASIC);
         s2a.setMaxIdleTimeout(6000);
-        Session s3a = connectToEchoServer(wsContainer, EndpointA.class,
+        Session s3a = connectToEchoServer(wsContainer, endpointA,
                 TesterEchoServer.Config.PATH_BASIC);
         s3a.setMaxIdleTimeout(9000);
 
@@ -747,8 +750,8 @@ public class TestWsWebSocketContainer ex
     }
 
     private Session connectToEchoServer(WebSocketContainer wsContainer,
-            Class<? extends Endpoint> clazz, String path) throws Exception {
-        return wsContainer.connectToServer(clazz,
+            Endpoint endpoint, String path) throws Exception {
+        return wsContainer.connectToServer(endpoint,
                 ClientEndpointConfig.Builder.create().build(),
                 new URI("ws://localhost:" + getPort() + path));
     }
@@ -872,7 +875,7 @@ public class TestWsWebSocketContainer ex
         WebSocketContainer wsContainer =
                 ContainerProvider.getWebSocketContainer();
 
-        Session s = connectToEchoServer(wsContainer, EndpointA.class, path);
+        Session s = connectToEchoServer(wsContainer, new EndpointA(), path);
 
         StringBuilder msg = new StringBuilder();
         for (long i = 0; i < size; i++) {

Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1685570&r1=1685569&r2=1685570&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Mon Jun 15 12:33:59 2015
@@ -143,6 +143,11 @@
         <code>javax.websocket.server.ServerEndpointConfig</code> as they vary
         between different requests. (violetagg)
       </fix>
+      <fix>
+        <bug>57974</bug>: Session.getOpenSessions should return all sessions
+        associated with a given endpoint instance, rather than all sessions
+        from the endpoint class. (remm)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Web applications">



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org