return send(new TextFrame(fragment, false, last));
}
}
public Future<Frame> close(final int code, final String reason) {
final CloseFrame outgoingCloseFrame;
final CloseReason closeReason = new CloseReason(CloseReason.CloseCodes.getCloseCode(code), reason);
if (code == CloseReason.CloseCodes.NO_STATUS_CODE.getCode() || code == CloseReason.CloseCodes.CLOSED_ABNORMALLY.getCode()
|| code == CloseReason.CloseCodes.TLS_HANDSHAKE_FAILURE.getCode()) {
outgoingCloseFrame = new CloseFrame(new CloseReason(CloseReason.CloseCodes.NORMAL_CLOSURE, reason));
} else {
outgoingCloseFrame = new CloseFrame(closeReason);
}
return send(outgoingCloseFrame, new CompletionHandler<Frame>() {
@Override
public void cancelled() {
if (webSocket != null && !onClosedCalled.getAndSet(true)) {
webSocket.onClose(new CloseFrame(closeReason));
}
}
@Override
public void failed(final Throwable throwable) {
if (webSocket != null && !onClosedCalled.getAndSet(true)) {
webSocket.onClose(new CloseFrame(closeReason));
}
}
@Override
public void completed(Frame result) {
if (!maskData && (webSocket != null) && !onClosedCalled.getAndSet(true)) {
webSocket.onClose(new CloseFrame(closeReason));
}
}
}, false);
}