public void closeAndRemoveWebSocket(String chargingStationIdentifier, @Nullable WebSocket webSocket) {
        if (webSocket != null && webSocket.isOpen()) {
            // received a web socket, close it no matter what
            webSocket.close();
        }

        WebSocketWrapper existingWrapper = sockets.get(chargingStationIdentifier);

        if (existingWrapper == null) {
            LOG.info("Could not find websocket to remove for {}.", chargingStationIdentifier);
            return;
        }

        if (webSocket == null || webSocket.equals(existingWrapper.getWebSocket())) {
            if (existingWrapper.isOpen()) {
                LOG.info("Websocket to remove was not closed for {}. Closing now and removing websocket...", chargingStationIdentifier);
                existingWrapper.close();
            }

            WebSocketWrapper removedSocket = sockets.remove(chargingStationIdentifier);

            // if the caller passed a web socket then only remove the web socket if it equals the passed web socket
            if (webSocket != null && !webSocket.equals(removedSocket.getWebSocket())) {
                // some other thread beat us to it (other thread added a new web socket to the set while we were in this method)
                // we removed the new socket, we put it back and act like nothing happened...
                sockets.put(chargingStationIdentifier, removedSocket);
            }
        }
    }
public void closeAndRemoveWebSocket ( String chargingStationIdentifier , @ Nullable WebSocket webSocket ) { if ( webSocket != null && webSocket . isOpen ( ) ) { webSocket . close ( ) ; } WebSocketWrapper existingWrapper = sockets . get ( chargingStationIdentifier ) ; if ( existingWrapper == null ) { LOG . info ( "Could not find websocket to remove for {}." , chargingStationIdentifier ) ; return ; } if ( webSocket == null || webSocket . equals ( existingWrapper . getWebSocket ( ) ) ) { if ( existingWrapper . isOpen ( ) ) { LOG . info ( "Websocket to remove was not closed for {}. Closing now and removing websocket..." , chargingStationIdentifier ) ; existingWrapper . close ( ) ; } WebSocketWrapper removedSocket = sockets . remove ( chargingStationIdentifier ) ; if ( webSocket != null && ! webSocket . equals ( removedSocket . getWebSocket ( ) ) ) { sockets . put ( chargingStationIdentifier , removedSocket ) ; } } }
Close and remove a web socket from the set of sockets.

By passing a webSocket object the caller can force this method to check if it's removing the handle that
contains this web socket. If the parameter is null this method will close whatever it has for the identifier.

@param chargingStationIdentifier charging station identifier for the socket
@param webSocket                 if not null this method checks if the socket in the set contains this socket