You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2013/06/22 15:24:17 UTC
svn commit: r1495724 -
/tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java
Author: markt
Date: Sat Jun 22 13:24:16 2013
New Revision: 1495724
URL: http://svn.apache.org/r1495724
Log:
Fix failing test.
Don't mark session as closed until Endpoint.onClose has completed.
Reduce code duplication
Modified:
tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.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=1495724&r1=1495723&r2=1495724&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java Sat Jun 22 13:24:16 2013
@@ -332,22 +332,7 @@ public class WsSession implements Sessio
@Override
public void close(CloseReason closeReason) throws IOException {
- // Double-checked locking. OK because state is volatile
- if (state != State.OPEN) {
- return;
- }
-
- synchronized (stateLock) {
- if (state != State.OPEN) {
- return;
- }
-
- state = State.CLOSING;
-
- sendCloseMessage(closeReason);
-
- fireEndpointOnClose(closeReason);
- }
+ doClose(closeReason, closeReason);
}
@@ -356,7 +341,8 @@ public class WsSession implements Sessio
* Need internal close method as spec requires that the local endpoint
* receives a 1006 on timeout.
*/
- private void closeTimeout(CloseReason closeReason) {
+ private void doClose(CloseReason closeReasonMessage,
+ CloseReason closeReasonLocal) {
// Double-checked locking. OK because state is volatile
if (state != State.OPEN) {
return;
@@ -369,13 +355,10 @@ public class WsSession implements Sessio
state = State.CLOSING;
- sendCloseMessage(closeReason);
+ sendCloseMessage(closeReasonMessage);
+ fireEndpointOnClose(closeReasonLocal);
- CloseReason localCloseReason =
- new CloseReason(CloseCodes.CLOSED_ABNORMALLY,
- closeReason.getReasonPhrase());
-
- fireEndpointOnClose(localCloseReason);
+ state = State.CLOSED;
}
}
@@ -391,10 +374,9 @@ public class WsSession implements Sessio
if (state == State.OPEN) {
sendCloseMessage(closeReason);
fireEndpointOnClose(closeReason);
+ state = State.CLOSED;
}
- state = State.CLOSED;
-
// Close the socket
wsRemoteEndpoint.close();
}
@@ -520,14 +502,15 @@ public class WsSession implements Sessio
}
if (System.currentTimeMillis() - lastActive > timeout) {
- closeTimeout(new CloseReason(CloseCodes.GOING_AWAY,
- sm.getString("wsSession.timeout")));
+ String msg = sm.getString("wsSession.timeout");
+ doClose(new CloseReason(CloseCodes.GOING_AWAY, msg),
+ new CloseReason(CloseCodes.CLOSED_ABNORMALLY, msg));
}
}
private void checkState() {
- if (!isOpen()) {
+ if (state == State.CLOSED) {
throw new IllegalStateException(sm.getString("wsSession.closed"));
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org