/** * Check if the current state is equal to the specified state. */ private boolean isInState(WebSocketState state) { synchronized (mStateManager) { return (mStateManager.getState() == state); } }
/** * Get the current state of this WebSocket. * * <p> * The initial state is {@link WebSocketState#CREATED CREATED}. * When {@link #connect()} is called, the state is changed to * {@link WebSocketState#CONNECTING CONNECTING}, and then to * {@link WebSocketState#OPEN OPEN} after a successful opening * handshake. The state is changed to {@link * WebSocketState#CLOSING CLOSING} when a closing handshake * is started, and then to {@link WebSocketState#CLOSED CLOSED} * when the closing handshake finished. * </p> * * <p> * See the description of {@link WebSocketState} for details. * </p> * * @return * The current state. * * @see WebSocketState */ public WebSocketState getState() { synchronized (mStateManager) { return mStateManager.getState(); } }
/** * Flush frames to the server. Flush is performed asynchronously. * * @return * {@code this} object. * * @since 1.5 */ public WebSocket flush() { synchronized (mStateManager) { WebSocketState state = mStateManager.getState(); if (state != OPEN && state != CLOSING) { return this; } } // Get the reference to the instance of WritingThread. WritingThread wt = mWritingThread; // If and only if an instance of WritingThread is available. if (wt != null) { // Request flush. wt.queueFlush(); } return this; }
private void changeStateOnConnect() throws WebSocketException { synchronized (mStateManager) { // If the current state is not CREATED. if (mStateManager.getState() != CREATED) { throw new WebSocketException( WebSocketError.NOT_IN_CREATED_STATE, "The current state of the WebSocket is not CREATED."); } // Change the state to CONNECTING. mStateManager.setState(CONNECTING); } // Notify the listeners of the state change. mListenerManager.callOnStateChanged(CONNECTING); }
private void changeToClosing() { StateManager manager = mWebSocket.getStateManager(); boolean stateChanged = false; synchronized (manager) { // The current state of the web socket. WebSocketState state = manager.getState(); // If the current state is neither CLOSING nor CLOSED. if (state != CLOSING && state != CLOSED) { // Change the state to CLOSING. manager.changeToClosing(CloseInitiator.CLIENT); stateChanged = true; } } if (stateChanged) { // Notify the listeners of the state change. mWebSocket.getListenerManager().callOnStateChanged(CLOSING); } }
WebSocketState state = mStateManager.getState();
WebSocketState state = manager.getState();
switch (mStateManager.getState())
/** * Check if the current state is equal to the specified state. */ private boolean isInState(WebSocketState state) { synchronized (mStateManager) { return (mStateManager.getState() == state); } }
/** * Get the current state of this WebSocket. * * <p> * The initial state is {@link WebSocketState#CREATED CREATED}. * When {@link #connect()} is called, the state is changed to * {@link WebSocketState#CONNECTING CONNECTING}, and then to * {@link WebSocketState#OPEN OPEN} after a successful opening * handshake. The state is changed to {@link * WebSocketState#CLOSING CLOSING} when a closing handshake * is started, and then to {@link WebSocketState#CLOSED CLOSED} * when the closing handshake finished. * </p> * * <p> * See the description of {@link WebSocketState} for details. * </p> * * @return * The current state. * * @see WebSocketState */ public WebSocketState getState() { synchronized (mStateManager) { return mStateManager.getState(); } }
/** * Flush frames to the server. Flush is performed asynchronously. * * @return * {@code this} object. * * @since 1.5 */ public WebSocket flush() { synchronized (mStateManager) { WebSocketState state = mStateManager.getState(); if (state != OPEN && state != CLOSING) { return this; } } // Get the reference to the instance of WritingThread. WritingThread wt = mWritingThread; // If and only if an instance of WritingThread is available. if (wt != null) { // Request flush. wt.queueFlush(); } return this; }
private void changeStateOnConnect() throws WebSocketException { synchronized (mStateManager) { // If the current state is not CREATED. if (mStateManager.getState() != CREATED) { throw new WebSocketException( WebSocketError.NOT_IN_CREATED_STATE, "The current state of the WebSocket is not CREATED."); } // Change the state to CONNECTING. mStateManager.setState(CONNECTING); } // Notify the listeners of the state change. mListenerManager.callOnStateChanged(CONNECTING); }
private void changeToClosing() { StateManager manager = mWebSocket.getStateManager(); boolean stateChanged = false; synchronized (manager) { // The current state of the web socket. WebSocketState state = manager.getState(); // If the current state is neither CLOSING nor CLOSED. if (state != CLOSING && state != CLOSED) { // Change the state to CLOSING. manager.changeToClosing(CloseInitiator.CLIENT); stateChanged = true; } } if (stateChanged) { // Notify the listeners of the state change. mWebSocket.getListenerManager().callOnStateChanged(CLOSING); } }
WebSocketState state = mStateManager.getState();
WebSocketState state = manager.getState();
switch (mStateManager.getState())