/** * Closes this {@link TyrusWebSocket} using the specified status code and * reason. * * @param code the closing status code. * @param reason the reason, if any. */ public void close(int code, String reason) { if (state.compareAndSet(State.CONNECTED, State.CLOSING)) { protocolHandler.close(code, reason); } }
/** * Closes this {@link TyrusWebSocket} using the specified status code and * reason. * * @param code the closing status code. * @param reason the reason, if any. */ public void close(int code, String reason) { if (state.compareAndSet(State.CONNECTED, State.CLOSING)) { protocolHandler.close(code, reason); } }
/** * This callback will be invoked when the remote endpoint sent a closing frame. * <p> * The execution of this method is synchronized using {@link ProtocolHandler} instance; see TYRUS-385. Prevents * multiple invocations, especially from container/user code. * * @param frame the close frame from the remote endpoint. */ public void onClose(CloseFrame frame) { boolean locked = lock.tryLock(); if (locked) { try { final CloseReason closeReason = frame.getCloseReason(); if (endpointWrapper != null) { endpointWrapper.onClose(this, closeReason); } if (state.compareAndSet(State.CONNECTED, State.CLOSING)) { protocolHandler.close(closeReason.getCloseCode().getCode(), closeReason.getReasonPhrase()); } else { state.set(State.CLOSED); protocolHandler.doClose(); } } finally { lock.unlock(); } } }
/** * This callback will be invoked when the remote endpoint sent a closing frame. * <p> * The execution of this method is synchronized using {@link ProtocolHandler} instance; see TYRUS-385. Prevents * multiple invocations, especially from container/user code. * * @param frame the close frame from the remote endpoint. */ public void onClose(CloseFrame frame) { boolean locked = lock.tryLock(); if (locked) { try { final CloseReason closeReason = frame.getCloseReason(); if (endpointWrapper != null) { endpointWrapper.onClose(this, closeReason); } if (state.compareAndSet(State.CONNECTED, State.CLOSING)) { protocolHandler.close(closeReason.getCloseCode().getCode(), closeReason.getReasonPhrase()); } else { state.set(State.CLOSED); protocolHandler.doClose(); } } finally { lock.unlock(); } } }