johnyangk commented on a change in pull request #153: [NEMO-245,247] Handle 
watermark in OutputWriter and Implement unbounded word count example
URL: https://github.com/apache/incubator-nemo/pull/153#discussion_r232547925
 
 

 ##########
 File path: 
runtime/executor/src/main/java/org/apache/nemo/runtime/executor/datatransfer/NemoEventDecoderFactory.java
 ##########
 @@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.nemo.runtime.executor.datatransfer;
+
+import org.apache.commons.lang.SerializationUtils;
+import org.apache.nemo.common.coder.DecoderFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * A factory for NemoEventDecoder.
+ */
+public final class NemoEventDecoderFactory implements DecoderFactory {
+  private static final Logger LOG = 
LoggerFactory.getLogger(NemoEventDecoderFactory.class.getName());
+
+  private final DecoderFactory valueDecoderFactory;
+
+  public NemoEventDecoderFactory(final DecoderFactory valueDecoderFactory) {
+    this.valueDecoderFactory = valueDecoderFactory;
+  }
+
+  @Override
+  public Decoder create(final InputStream inputStream) throws IOException {
+    return new NemoEventDecoder(valueDecoderFactory.create(inputStream), 
inputStream);
+  }
+
+  /**
+   * This class decodes receive data into two types.
+   * - normal data
+   * - WatermarkWithIndex
+   */
+  private final class NemoEventDecoder implements DecoderFactory.Decoder {
+
+    private final Decoder valueDecoder;
+    private final InputStream inputStream;
+
+    NemoEventDecoder(final Decoder valueDecoder,
+                     final InputStream inputStream) {
+      this.valueDecoder = valueDecoder;
+      this.inputStream = inputStream;
+    }
+
+    @Override
+    public Object decode() throws IOException {
+
+      final byte isWatermark = (byte) inputStream.read();
+      if (isWatermark == -1) {
 
 Review comment:
   // end of the input stream

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to