smolnar82 commented on a change in pull request #143: KNOX-1997: Adding changes 
to buffer messages from backend in onMessag…
URL: https://github.com/apache/knox/pull/143#discussion_r321695589
 
 

 ##########
 File path: 
gateway-server/src/main/java/org/apache/knox/gateway/websockets/ProxyWebSocketAdapter.java
 ##########
 @@ -198,12 +232,34 @@ public void onError(Throwable cause) {
 
       @Override
       public void onMessageText(String message, Object session) {
-        final RemoteEndpoint remote = getRemote();
-
         LOG.logMessage("[From Backend <---]" + message);
+        remoteLock.lock();
+        final RemoteEndpoint remote = getRemote();
+        if (remote == null) {
+          LOG.logMessage("Remote endpoint is null");
+          if (messageBuffer == null) {
+             messageBuffer = new ArrayList<String>();
+          }
+          if (messageBuffer.size() >= MAX_BUFFER_MESSAGE_COUNT) {
+            throw new RuntimeIOException("Remote is null and message buffer is 
full. Cannot buffer anymore ");
+          }
+          LOG.logMessage("Buffering message: " + message);
+          messageBuffer.add(message);
+          remoteLock.unlock();
 
 Review comment:
   Please surround this logic with a try-finally and move the unlock invocation 
in the finally block.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to