/** * deprecated: 对保存seesion信息的map操作 * * <p>2015-03-20 * * @author sharkTang * @param webSocketMap : socket对象集合 * @param session : javax.websocket.Session * @param actionString : action */ public static void webSocketMapAction( Map<Integer, Session> webSessionMap, Session session, String actionString) { try { lock.lock(); if (WebSocketConstants.ADD_STR.equals(actionString)) { webSessionMap.put(session.hashCode(), session); } else if (WebSocketConstants.REMOVE_STR.equals(actionString)) { webSessionMap.remove(session.hashCode()); } } catch (Exception e) { lock.unlock(); } finally { lock.unlock(); } }
/** * deprecated: 对全局websocket对象的集合操作进行加锁操作 * * @author sharkTang * @param webSocketMap : socket对象集合 * @param session : websocketSession * @param actionString : action * @param webSocketBo : websocket object */ public static void webSocketAction( Map<Integer, WebSocketBo> webSocketMap, Session session, String actionString, WebSocketBo webSocketBo) { try { // add lock to webSocketMap lock.lock(); // something to do daPingWebsocketSession = session; Integer webSocketHashCode = session.hashCode(); if (WebSocketConstants.ADD_STR.equals(actionString)) { webSocketMap.put(webSocketHashCode, webSocketBo); } else if (WebSocketConstants.REMOVE_STR.equals(actionString)) { webSocketMap.remove(webSocketHashCode); } } catch (Exception ex) { lock.unlock(); } finally { lock.unlock(); } }