Author: markt
Date: Fri Jun 28 13:15:45 2013
New Revision: 1497763
URL: http://svn.apache.org/r1497763
Log:
Refactor to register and unregister endpoint instances and session instances
rather than endpoint classes and session instances.
This is required to support implementation of WebSocket 1.0, section 7.2
Modified:
tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java
tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
tomcat/trunk/java/org/apache/tomcat/websocket/server/WsHttpUpgradeHandler.java
tomcat/trunk/java/org/apache/tomcat/websocket/server/WsServerContainer.java
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java?rev=1497763&r1=1497762&r2=1497763&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java Fri Jun 28
13:15:45 2013
@@ -464,8 +464,7 @@ public class WsSession implements Sessio
wsRemoteEndpoint.close();
localEndpoint.onError(this, ioe);
} finally {
- webSocketContainer.unregisterSession(
- localEndpoint.getClass(), this);
+ webSocketContainer.unregisterSession(localEndpoint, this);
}
}
Modified:
tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java?rev=1497763&r1=1497762&r2=1497763&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
(original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java Fri
Jun 28 13:15:45 2013
@@ -334,7 +334,7 @@ public class WsWebSocketContainer
Collections.EMPTY_MAP, false,
clientEndpointConfiguration);
endpoint.onOpen(wsSession, clientEndpointConfiguration);
- registerSession(endpoint.getClass(), wsSession);
+ registerSession(endpoint, wsSession);
// Object creation will trigger input processing
@SuppressWarnings("unused")
@@ -345,7 +345,11 @@ public class WsWebSocketContainer
}
- protected void registerSession(Class<?> endpoint, WsSession wsSession) {
+ protected void registerSession(Object endpointInstance,
+ WsSession wsSession) {
+
+ Class<?> endpointClazz = endpointInstance.getClass();
+
if (!wsSession.isOpen()) {
// The session was closed during onOpen. No need to register it.
return;
@@ -354,10 +358,10 @@ public class WsWebSocketContainer
if (endpointSessionMap.size() == 0) {
BackgroundProcessManager.getInstance().register(this);
}
- Set<WsSession> wsSessions = endpointSessionMap.get(endpoint);
+ Set<WsSession> wsSessions = endpointSessionMap.get(endpointClazz);
if (wsSessions == null) {
wsSessions = new HashSet<>();
- endpointSessionMap.put(endpoint, wsSessions);
+ endpointSessionMap.put(endpointClazz, wsSessions);
}
wsSessions.add(wsSession);
}
@@ -365,13 +369,17 @@ public class WsWebSocketContainer
}
- protected void unregisterSession(Class<?> endpoint, WsSession wsSession) {
+ protected void unregisterSession(Object endpointInstance,
+ WsSession wsSession) {
+
+ Class<?> endpointClazz = endpointInstance.getClass();
+
synchronized (endPointSessionMapLock) {
- Set<WsSession> wsSessions = endpointSessionMap.get(endpoint);
+ Set<WsSession> wsSessions = endpointSessionMap.get(endpointClazz);
if (wsSessions != null) {
wsSessions.remove(wsSession);
if (wsSessions.size() == 0) {
- endpointSessionMap.remove(endpoint);
+ endpointSessionMap.remove(endpointClazz);
}
}
if (endpointSessionMap.size() == 0) {
Modified:
tomcat/trunk/java/org/apache/tomcat/websocket/server/WsHttpUpgradeHandler.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/WsHttpUpgradeHandler.java?rev=1497763&r1=1497762&r2=1497763&view=diff
==============================================================================
---
tomcat/trunk/java/org/apache/tomcat/websocket/server/WsHttpUpgradeHandler.java
(original)
+++
tomcat/trunk/java/org/apache/tomcat/websocket/server/WsHttpUpgradeHandler.java
Fri Jun 28 13:15:45 2013
@@ -128,7 +128,7 @@ public class WsHttpUpgradeHandler implem
sos.setWriteListener(
new WsWriteListener(this, wsRemoteEndpointServer));
ep.onOpen(wsSession, endpointConfig);
- webSocketContainer.registerSession(ep.getClass(), wsSession);
+ webSocketContainer.registerSession(ep, wsSession);
} catch (DeploymentException e) {
throw new IllegalArgumentException(e);
} finally {
Modified:
tomcat/trunk/java/org/apache/tomcat/websocket/server/WsServerContainer.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/WsServerContainer.java?rev=1497763&r1=1497762&r2=1497763&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/server/WsServerContainer.java
(original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/server/WsServerContainer.java
Fri Jun 28 13:15:45 2013
@@ -304,22 +304,24 @@ public class WsServerContainer extends W
/**
* {@inheritDoc}
*
- * Overridden to make them visible to other classes in this package.
+ * Overridden to make it visible to other classes in this package.
*/
@Override
- protected void registerSession(Class<?> endpoint, WsSession wsSession) {
- super.registerSession(endpoint, wsSession);
+ protected void registerSession(Object endpointInstance,
+ WsSession wsSession) {
+ super.registerSession(endpointInstance, wsSession);
}
/**
* {@inheritDoc}
*
- * Overridden to make them visible to other classes in this package.
+ * Overridden to make it visible to other classes in this package.
*/
@Override
- protected void unregisterSession(Class<?> endpoint, WsSession wsSession) {
- super.unregisterSession(endpoint, wsSession);
+ protected void unregisterSession(Object endpointInstance,
+ WsSession wsSession) {
+ super.unregisterSession(endpointInstance, wsSession);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]