GUI -- Adding synchronization for message sending and for create/destroy handlers.

Change-Id: Id0cb367dcdaf658d3a58ef3f81718a08d1fd1438
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java
index 854ac5a..9beeb94 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java
@@ -589,7 +589,7 @@
 
 
     // Adds all internal listeners.
-    private void addListeners() {
+    private synchronized void addListeners() {
         listenersRemoved = false;
         clusterService.addListener(clusterListener);
         mastershipService.addListener(mastershipListener);
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/UiWebSocket.java b/web/gui/src/main/java/org/onosproject/ui/impl/UiWebSocket.java
index a35a388..1fbbddf 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/UiWebSocket.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/UiWebSocket.java
@@ -136,7 +136,7 @@
     }
 
     @Override
-    public void sendMessage(ObjectNode message) {
+    public synchronized void sendMessage(ObjectNode message) {
         try {
             if (connection.isOpen()) {
                 connection.sendMessage(message.toString());
@@ -148,7 +148,7 @@
     }
 
     @Override
-    public void sendMessage(String type, long sid, ObjectNode payload) {
+    public synchronized void sendMessage(String type, long sid, ObjectNode payload) {
         ObjectNode message = mapper.createObjectNode();
         message.put("event", type);
         if (sid > 0) {
@@ -160,7 +160,7 @@
     }
 
     // Creates new message handlers.
-    private void createHandlers() {
+    private synchronized void createHandlers() {
         handlers = new HashMap<>();
         UiExtensionService service = directory.get(UiExtensionService.class);
         service.getExtensions().forEach(ext -> {