You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by di...@apache.org on 2020/01/02 12:54:06 UTC

[airavata-mft] branch master updated: Fixing the bug of streaming buffer stuck at last byte

This is an automated email from the ASF dual-hosted git repository.

dimuthuupe pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata-mft.git


The following commit(s) were added to refs/heads/master by this push:
     new 954ed89  Fixing the bug of streaming buffer stuck at last byte
954ed89 is described below

commit 954ed89999bf4b7781ebd1be206a87d3661dd7ad
Author: Dimuthu Wannipurage <di...@gmail.com>
AuthorDate: Thu Jan 2 07:53:25 2020 -0500

    Fixing the bug of streaming buffer stuck at last byte
---
 .../apache/airavata/mft/core/CircularStreamingBuffer.java | 15 ++++++++++-----
 .../apache/airavata/mft/transport/scp/SCPReceiver.java    |  1 +
 .../org/apache/airavata/mft/transport/scp/SCPSender.java  |  7 ++++++-
 3 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/core/src/main/java/org/apache/airavata/mft/core/CircularStreamingBuffer.java b/core/src/main/java/org/apache/airavata/mft/core/CircularStreamingBuffer.java
index b2d2edd..9086626 100644
--- a/core/src/main/java/org/apache/airavata/mft/core/CircularStreamingBuffer.java
+++ b/core/src/main/java/org/apache/airavata/mft/core/CircularStreamingBuffer.java
@@ -40,8 +40,9 @@ public class CircularStreamingBuffer {
         return inputStream;
     }
 
-    private void updateRead() {
-        if (readSem.availablePermits() == 0) {
+    private void updateRead(boolean forced) {
+        if (forced || readSem.availablePermits() == 0) {
+            //System.out.println("Read sem released");
             readSem.release();
         }
     }
@@ -57,7 +58,7 @@ public class CircularStreamingBuffer {
             for (int i = off; i < len; i ++) {
                 try {
                     buffer.put(b[i]);
-                    updateRead();
+                    updateRead(false);
                 } catch (InterruptedException e) {
                     throw new IOException(e);
                 }
@@ -71,7 +72,7 @@ public class CircularStreamingBuffer {
         @Override
         public void close() throws IOException {
             osClosed = true;
-            updateRead();
+            updateRead(true);
         }
 
         @Override
@@ -79,7 +80,7 @@ public class CircularStreamingBuffer {
             try {
                 buffer.put((byte)b);
                 //System.out.println("Writing");
-                updateRead();
+                updateRead(false);
             } catch (InterruptedException e) {
                 throw new IOException(e);
             }
@@ -95,7 +96,9 @@ public class CircularStreamingBuffer {
                 //System.out.println("Received null in is.read()");
                 if (osClosed) return -1;
                 try {
+                    //System.out.println("Read sem acquired");
                     readSem.acquire();
+                    //System.out.println("Read Released");
                     return read();
                 } catch (InterruptedException e) {
                     throw new IOException(e);
@@ -108,7 +111,9 @@ public class CircularStreamingBuffer {
         @Override
         public int read(byte[] b, int off, int len) throws IOException {
             for (int i = off; i < len; i++) {
+                //System.out.println("Begin read");
                 int res = read();
+                //System.out.println("End read " + res);
                 if (res == -1) {
                     //System.out.println("Received -1 in is.read(byte[], off, len)");
                     if (i == off) {
diff --git a/transport/scp-transport/src/main/java/org/apache/airavata/mft/transport/scp/SCPReceiver.java b/transport/scp-transport/src/main/java/org/apache/airavata/mft/transport/scp/SCPReceiver.java
index aa48e46..f5db8e5 100644
--- a/transport/scp-transport/src/main/java/org/apache/airavata/mft/transport/scp/SCPReceiver.java
+++ b/transport/scp-transport/src/main/java/org/apache/airavata/mft/transport/scp/SCPReceiver.java
@@ -157,6 +157,7 @@ public class SCPReceiver implements Connector {
             buf[0] = 0;
             out.write(buf, 0, 1);
             out.flush();
+            outputStream.close();
         }
 
         channel.disconnect();
diff --git a/transport/scp-transport/src/main/java/org/apache/airavata/mft/transport/scp/SCPSender.java b/transport/scp-transport/src/main/java/org/apache/airavata/mft/transport/scp/SCPSender.java
index b081adc..acf9cbe 100644
--- a/transport/scp-transport/src/main/java/org/apache/airavata/mft/transport/scp/SCPSender.java
+++ b/transport/scp-transport/src/main/java/org/apache/airavata/mft/transport/scp/SCPSender.java
@@ -70,7 +70,12 @@ public class SCPSender implements Connector {
             System.out.println("Session can not be null. Make sure that SCP Sender is properly initialized");
             throw new Exception("Session can not be null. Make sure that SCP Sender is properly initialized");
         }
-        copyLocalToRemote(this.session, this.scpResource.getResourcePath(), context.getStreamBuffer(), context.getMetadata().getResourceSize());
+        try {
+            copyLocalToRemote(this.session, this.scpResource.getResourcePath(), context.getStreamBuffer(), context.getMetadata().getResourceSize());
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw e;
+        }
     }
 
     private void copyLocalToRemote(Session session, String to, CircularStreamingBuffer streamBuffer, long fileSize) throws JSchException, IOException {