markusthoemmes commented on a change in pull request #3886: Proposing Lean 
OpenWhisk
URL: 
https://github.com/apache/incubator-openwhisk/pull/3886#discussion_r206262629
 
 

 ##########
 File path: common/scala/src/main/scala/whisk/connector/lean/LeanConsumer.scala
 ##########
 @@ -0,0 +1,49 @@
+/*
+ * 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 whisk.connector.lean
+
+import scala.concurrent.duration._
+import whisk.common.Logging
+import whisk.core.connector.MessageConsumer
+import java.util.concurrent.BlockingQueue
+import java.util.concurrent.TimeUnit
+
+class LeanConsumer(queue: BlockingQueue[Array[Byte]], override val maxPeek: 
Int)(implicit logging: Logging)
+    extends MessageConsumer {
+
+  /**
+   */
+  override def peek(duration: FiniteDuration, retry: Int): Iterable[(String, 
Int, Long, Array[Byte])] = {
+    val record = queue.poll(duration.toMillis, TimeUnit.MILLISECONDS)
+
+    //TODO: currently returns record in the format below, should be refactored 
of kafka later
+    if (record != null) {
+      Iterable(("", 0, 0, record))
+    } else {
+      Iterable()
+    }
 
 Review comment:
   To get away with the `null`, please wrap the poll call in an Option, like:
   
   ```scala
   Option(queue.poll(duration.toMillis, TimeUnit.MILLISECONDS))
     .map(record => Iterable(("", 0, 0, record)))
     .getOrElse(Iterable.empty)
   ```
   
   The Option is either Some (if records is not null), or None otherwise. A 
some is mapped to an iterable like in your code and if records was not defined, 
we return an empty iterable as a fallback.

----------------------------------------------------------------
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