use of javax.websocket.CloseReason in project AngularBeans by bessemHmidi.
the class WebsocketReceiver method didClose.
@Override
protected void didClose() {
super.didClose();
try {
ws.close(new CloseReason(CloseReason.CloseCodes.NORMAL_CLOSURE, "Normal closure"));
} catch (IOException x) {
log.log(Level.FINE, "Error closing receiver", x);
}
ws = null;
}
use of javax.websocket.CloseReason in project AngularBeans by bessemHmidi.
the class RawWebsocketSessionReceiver method didClose.
public void didClose() {
if (ws == null) {
return;
}
try {
ws.close(new CloseReason(CloseReason.CloseCodes.NORMAL_CLOSURE, "Normal closure"));
} catch (IOException x) {
log.log(Level.FINE, "Error closing receiver", x);
}
ws = null;
readyState = CLOSED;
connection.emitClose();
connection = null;
}
use of javax.websocket.CloseReason in project tomcat by apache.
the class WsSession method checkExpiration.
protected void checkExpiration() {
long timeout = maxIdleTimeout;
if (timeout < 1) {
return;
}
if (System.currentTimeMillis() - lastActive > timeout) {
String msg = sm.getString("wsSession.timeout", getId());
if (log.isDebugEnabled()) {
log.debug(msg);
}
doClose(new CloseReason(CloseCodes.GOING_AWAY, msg), new CloseReason(CloseCodes.CLOSED_ABNORMALLY, msg));
}
}
use of javax.websocket.CloseReason in project tomcat by apache.
the class WsWebSocketContainer method destroy.
/**
* Cleans up the resources still in use by WebSocket sessions created from
* this container. This includes closing sessions and cancelling
* {@link Future}s associated with blocking read/writes.
*/
public void destroy() {
CloseReason cr = new CloseReason(CloseCodes.GOING_AWAY, sm.getString("wsWebSocketContainer.shutdown"));
for (WsSession session : sessions.keySet()) {
try {
session.close(cr);
} catch (IOException ioe) {
log.debug(sm.getString("wsWebSocketContainer.sessionCloseFail", session.getId()), ioe);
}
}
// registered with it
if (asynchronousChannelGroup != null) {
synchronized (asynchronousChannelGroupLock) {
if (asynchronousChannelGroup != null) {
AsyncChannelGroupUtil.unregister();
asynchronousChannelGroup = null;
}
}
}
}
use of javax.websocket.CloseReason in project tomcat by apache.
the class WsFrameBase method processRemainingHeader.
/**
* @return <code>true</code> if sufficient data was present to complete the
* processing of the header
*/
private boolean processRemainingHeader() throws IOException {
// Ignore the 2 bytes already read. 4 for the mask
int headerLength;
if (isMasked()) {
headerLength = 4;
} else {
headerLength = 0;
}
// Add additional bytes depending on length
if (payloadLength == 126) {
headerLength += 2;
} else if (payloadLength == 127) {
headerLength += 8;
}
if (inputBuffer.remaining() < headerLength) {
return false;
}
// Calculate new payload length if necessary
if (payloadLength == 126) {
payloadLength = byteArrayToLong(inputBuffer.array(), inputBuffer.arrayOffset() + inputBuffer.position(), 2);
inputBuffer.position(inputBuffer.position() + 2);
} else if (payloadLength == 127) {
payloadLength = byteArrayToLong(inputBuffer.array(), inputBuffer.arrayOffset() + inputBuffer.position(), 8);
inputBuffer.position(inputBuffer.position() + 8);
}
if (Util.isControl(opCode)) {
if (payloadLength > 125) {
throw new WsIOException(new CloseReason(CloseCodes.PROTOCOL_ERROR, sm.getString("wsFrame.controlPayloadTooBig", Long.valueOf(payloadLength))));
}
if (!fin) {
throw new WsIOException(new CloseReason(CloseCodes.PROTOCOL_ERROR, sm.getString("wsFrame.controlNoFin")));
}
}
if (isMasked()) {
inputBuffer.get(mask, 0, 4);
}
state = State.DATA;
return true;
}
Aggregations