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 2019/08/22 16:42:12 UTC
[airavata-mft] 06/22: Adding class and method level comments
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
commit 65e333188fbedd74e72c05f0e56203c864a5e4a9
Author: Dimuthu Wannipurage <di...@gmail.com>
AuthorDate: Tue Aug 6 13:24:44 2019 -0400
Adding class and method level comments
---
.../mft/core/streaming/DoubleByteArrayInputStream.java | 8 ++++++++
.../mft/core/streaming/DoubleByteArrayOutputStream.java | 16 ++++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/core/src/main/java/org/apache/airavata/mft/core/streaming/DoubleByteArrayInputStream.java b/core/src/main/java/org/apache/airavata/mft/core/streaming/DoubleByteArrayInputStream.java
index 6228d93..9845e84 100644
--- a/core/src/main/java/org/apache/airavata/mft/core/streaming/DoubleByteArrayInputStream.java
+++ b/core/src/main/java/org/apache/airavata/mft/core/streaming/DoubleByteArrayInputStream.java
@@ -22,6 +22,10 @@ package org.apache.airavata.mft.core.streaming;
import java.io.IOException;
import java.io.InputStream;
+/**
+ * This accepts {@link DoubleByteArrayOutputStream} and monitors for the availability of readable data. If there is any,
+ * this is exposing them as an {@link InputStream}
+ */
public class DoubleByteArrayInputStream extends InputStream {
private DoubleByteArrayOutputStream outputStream;
@@ -44,6 +48,10 @@ public class DoubleByteArrayInputStream extends InputStream {
return this.currentInputStream.available();
}
+ /**
+ * This will check if there is new data in the {@link DoubleByteArrayOutputStream}
+ * @throws IOException
+ */
private void refresh() throws IOException {
if (this.currentInputStream.available() == 0) {
InputStream tempInputStream = this.outputStream.asInputStream();
diff --git a/core/src/main/java/org/apache/airavata/mft/core/streaming/DoubleByteArrayOutputStream.java b/core/src/main/java/org/apache/airavata/mft/core/streaming/DoubleByteArrayOutputStream.java
index 1f1b56b..56728c3 100644
--- a/core/src/main/java/org/apache/airavata/mft/core/streaming/DoubleByteArrayOutputStream.java
+++ b/core/src/main/java/org/apache/airavata/mft/core/streaming/DoubleByteArrayOutputStream.java
@@ -21,6 +21,13 @@ package org.apache.airavata.mft.core.streaming;
import java.io.*;
+/**
+ * This class wraps two {@link ByteArrayOutputStream} objects and implements the API of {@link OutputStream}. Main
+ * objective of this implementation is to use one stream for writing data and other stream to read the already written data.
+ * Behaviour of this Class is similar to what {@link PipedOutputStream} is doing but with more relaxed modes in thread
+ * contention and high performance. Limitation is that an instance of this class only be used between two threads. One
+ * thread can write to the output stream and other thread can digest data from asInputStream method.
+ */
public class DoubleByteArrayOutputStream extends OutputStream {
private ByteArrayOutputStream stream1 = new ByteArrayOutputStream();
@@ -49,6 +56,10 @@ public class DoubleByteArrayOutputStream extends OutputStream {
processedBytes += len;
}
+ /**
+ * This will swap currently writing {@link BufferedOutputStream} into the non active one. In order to perform
+ * this swap, non active stream should be empty.
+ */
private void swapBuffers() {
while (!clearedNonActiveStream) {
try {
@@ -90,6 +101,11 @@ public class DoubleByteArrayOutputStream extends OutputStream {
isClosed = true;
}
+ /**
+ * This will read currently non updating output stream and convert its data as an {@link InputStream}. Multiple invoking
+ * this will return null if there is no new data.
+ * @return {@link InputStream} of currently un-read data. null otherwise
+ */
public InputStream asInputStream() {
if (clearedNonActiveStream) {
return null;