diff options
Diffstat (limited to 'ecomp-sdk')
-rw-r--r-- | ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/socket/WebRTCSocket.java | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/socket/WebRTCSocket.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/socket/WebRTCSocket.java index ed8e89e3..dc18c3be 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/socket/WebRTCSocket.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/socket/WebRTCSocket.java @@ -33,13 +33,14 @@ * * ============LICENSE_END============================================ * - * + * */ package org.onap.portalsdk.core.web.socket; -import java.util.Hashtable; +import java.util.HashMap; import java.util.Map; +import java.util.Map.Entry; import javax.websocket.OnClose; import javax.websocket.OnMessage; import javax.websocket.OnOpen; @@ -55,8 +56,9 @@ public class WebRTCSocket { private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(WebRTCSocket.class); - private final static Map<String, Hashtable<String, Object[]>> channelMap = new Hashtable<String, Hashtable<String, Object[]>>(); - private final Map<String, String> sessionMap = new Hashtable<String, String>(); + private static final Map<String, HashMap<String, Object[]>> channelMap = new HashMap<>(); + private static final String MESSAGE_FAILED = "mesage failed"; + private final Map<String, String> sessionMap = new HashMap<>(); private final ObjectMapper mapper = new ObjectMapper(); @OnMessage @@ -69,11 +71,11 @@ public class WebRTCSocket { if (isOpen != null && (Boolean) isOpen) { String channel = (String) jsonObject.get("channel"); Object value = channelMap.get(channel); - Hashtable<String, Object[]> sourceDestMap; + HashMap<String, Object[]> sourceDestMap; if (value == null) - sourceDestMap = new Hashtable<>(); + sourceDestMap = new HashMap<>(); else - sourceDestMap = (Hashtable<String, Object[]>) value; + sourceDestMap = (HashMap<String, Object[]>) value; sourceDestMap.put(session.getId(), new Object[] { session }); channelMap.put(channel, sourceDestMap); @@ -81,7 +83,7 @@ public class WebRTCSocket { } } catch (Exception je) { - logger.error(EELFLoggerDelegate.errorLogger, "mesage failed", je); + logger.error(EELFLoggerDelegate.errorLogger, MESSAGE_FAILED, je); } try { @@ -97,26 +99,27 @@ public class WebRTCSocket { else channel = (String) jsonObject.get("channel"); } catch (Exception json) { - logger.error(EELFLoggerDelegate.errorLogger, "mesage failed", json); + logger.error(EELFLoggerDelegate.errorLogger, MESSAGE_FAILED, json); } - Hashtable<String, Object[]> sourceDestMap = channelMap.get(channel); + HashMap<String, Object[]> sourceDestMap = channelMap.get(channel); if (sourceDestMap != null) - for (String id : sourceDestMap.keySet()) { - if (!id.equals(session.getId())) { - Session otherSession = (Session) (sourceDestMap.get(id))[0]; + for (Entry<String, Object[]> entry : sourceDestMap.entrySet()){ + + if (!entry.getKey().equals(session.getId())) { + Session otherSession = (Session) (entry.getValue())[0]; if (otherSession.isOpen()) otherSession.getBasicRemote().sendText(mapper.writeValueAsString(dataObj)); } } } catch (Exception je) { - logger.error(EELFLoggerDelegate.errorLogger, "mesage failed", je); + logger.error(EELFLoggerDelegate.errorLogger, MESSAGE_FAILED, je); } } catch (Exception je) { - logger.error(EELFLoggerDelegate.errorLogger, "mesage failed", je); + logger.error(EELFLoggerDelegate.errorLogger, MESSAGE_FAILED, je); } } |