use of javax.websocket.CloseReason.CloseCode in project jetty.project by eclipse.
the class AbstractJsrEventDriver method onClose.
@Override
public final void onClose(CloseInfo close) {
if (hasCloseBeenCalled) {
// avoid duplicate close events (possible when using harsh Session.disconnect())
return;
}
hasCloseBeenCalled = true;
CloseCode closecode = CloseCodes.getCloseCode(close.getStatusCode());
CloseReason closereason = new CloseReason(closecode, close.getReason());
onClose(closereason);
}
use of javax.websocket.CloseReason.CloseCode in project tomcat by apache.
the class TestClose method awaitOnClose.
public static void awaitOnClose(CloseCode... codes) {
Set<CloseCode> set = new HashSet<>();
for (CloseCode code : codes) {
set.add(code);
}
awaitOnClose(set);
}
use of javax.websocket.CloseReason.CloseCode in project tomcat70 by apache.
the class TestClose method awaitOnClose.
public static void awaitOnClose(CloseCode... codes) {
Set<CloseCode> set = new HashSet<CloseCode>();
for (CloseCode code : codes) {
set.add(code);
}
awaitOnClose(set);
}
use of javax.websocket.CloseReason.CloseCode in project tomcat70 by apache.
the class WsSession method sendCloseMessage.
private void sendCloseMessage(CloseReason closeReason) {
// 125 is maximum size for the payload of a control message
ByteBuffer msg = ByteBuffer.allocate(125);
CloseCode closeCode = closeReason.getCloseCode();
// CLOSED_ABNORMALLY should not be put on the wire
if (closeCode == CloseCodes.CLOSED_ABNORMALLY) {
// PROTOCOL_ERROR is probably better than GOING_AWAY here
msg.putShort((short) CloseCodes.PROTOCOL_ERROR.getCode());
} else {
msg.putShort((short) closeCode.getCode());
}
String reason = closeReason.getReasonPhrase();
if (reason != null && reason.length() > 0) {
appendCloseReasonWithTruncation(msg, reason);
}
msg.flip();
try {
wsRemoteEndpoint.startMessageBlock(Constants.OPCODE_CLOSE, msg, true);
} catch (IOException ioe) {
handleCloseException(ioe, closeCode);
} catch (WritePendingException wpe) {
handleCloseException(wpe, closeCode);
} finally {
webSocketContainer.unregisterSession(localEndpoint, this);
}
}
use of javax.websocket.CloseReason.CloseCode in project tomcat70 by apache.
the class TestClose method awaitOnClose.
public static void awaitOnClose(Set<CloseCode> codes) {
awaitLatch(events.onCloseCalled, "onClose not called");
CloseCode received = events.closeReason.getCloseCode();
Assert.assertTrue("Rx: " + received, codes.contains(received));
}
Aggregations