sanha commented on a change in pull request #2: [NEMO-7] Intra-TaskGroup 
pipelining
URL: https://github.com/apache/incubator-nemo/pull/2#discussion_r187039938
 
 

 ##########
 File path: 
compiler/frontend/spark/src/main/java/edu/snu/nemo/compiler/frontend/spark/transform/CollectTransform.java
 ##########
 @@ -22,44 +22,49 @@
 import java.io.FileOutputStream;
 import java.io.ObjectOutputStream;
 import java.util.ArrayList;
-import java.util.Iterator;
+import java.util.List;
 
 /**
  * Collect transform.
  * @param <T> type of data to collect.
  */
 public final class CollectTransform<T> implements Transform<T, T> {
   private String filename;
+  private FileOutputStream fos;
+  private ObjectOutputStream oos;
+  private final List<T> list;
 
   /**
    * Constructor.
+   *
    * @param filename file to keep the result in.
    */
   public CollectTransform(final String filename) {
     this.filename = filename;
+    this.list = new ArrayList<>();
   }
 
   @Override
-  public void prepare(final Context context, final OutputCollector<T> 
outputCollector) {
+  public void prepare(final Context context, final OutputCollector<T> oc) {
     this.filename = filename + JavaRDD.getResultId();
   }
 
   @Override
-  public void onData(final Iterator<T> elements, final String srcVertexId) {
+  public void onData(final T element) {
     // Write result to a temporary file.
     // TODO #740: remove this part, and make it properly transfer with 
executor.
-    try (final FileOutputStream fos = new FileOutputStream(filename)) {
-      try (final ObjectOutputStream oos = new ObjectOutputStream(fos)) {
-        final ArrayList<T> list = new ArrayList<>();
-        elements.forEachRemaining(list::add);
-        oos.writeObject(list);
-      }
-    } catch (Exception e) {
-      throw new RuntimeException(e);
-    }
+    list.add(element);
   }
 
   @Override
   public void close() {
+    try {
 
 Review comment:
   Please use try-with-resource clause for these `Stream`s.

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


With regards,
Apache Git Services

Reply via email to