[GitHub] [flink] pnowojski commented on a change in pull request #9477: [FLINK-13765][task] Introduce the InputSelectionHandler for selecting next input in StreamTwoInputSelectableProcessor

2019-08-23 Thread GitBox
pnowojski commented on a change in pull request #9477: [FLINK-13765][task] 
Introduce the InputSelectionHandler for selecting next input in 
StreamTwoInputSelectableProcessor
URL: https://github.com/apache/flink/pull/9477#discussion_r317160983
 
 

 ##
 File path: 
flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/io/InputSelectionHandler.java
 ##
 @@ -0,0 +1,82 @@
+/*
+ * 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.flink.streaming.runtime.io;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.streaming.api.operators.InputSelectable;
+import org.apache.flink.streaming.api.operators.InputSelection;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+import static org.apache.flink.util.Preconditions.checkState;
+
+/**
+ * This handler is mainly used for selecting the next available input index
+ * in {@link StreamTwoInputSelectableProcessor}.
+ */
+@Internal
+public class InputSelectionHandler {
+
+   private final InputSelectable inputSelector;
+
+   private InputSelection inputSelection;
+
+   private int availableInputsMask;
+
+   public InputSelectionHandler(InputSelectable inputSelectable) {
+   this.inputSelector = checkNotNull(inputSelectable);
+   this.availableInputsMask = (int) new 
InputSelection.Builder().select(1).select(2).build().getInputMask();
+   }
+
+   void nextSelection() {
+   inputSelection = inputSelector.nextSelection();
+   }
+
+   int selectNextInputIndex(int lastReadInputIndex) {
+   return 
inputSelection.fairSelectNextIndexOutOf2(availableInputsMask, 
lastReadInputIndex);
+   }
+
+   boolean shouldSetAvailableForAnotherInput() {
+   return availableInputsMask < 3 && inputSelection.isALLMaskOf2();
+   }
+
+   void setAvailableInput(int inputIndex) {
+   availableInputsMask |= 1 << inputIndex;
+   }
+
+   void setUnavailableInput(int inputIndex) {
+   availableInputsMask &= ~(1 << inputIndex);
+   }
+
+   boolean isALLInputsSelected() {
 
 Review comment:
   Rename to `areAllInputsSelected()`? (with lower case `All`)


This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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


[GitHub] [flink] pnowojski commented on a change in pull request #9477: [FLINK-13765][task] Introduce the InputSelectionHandler for selecting next input in StreamTwoInputSelectableProcessor

2019-08-23 Thread GitBox
pnowojski commented on a change in pull request #9477: [FLINK-13765][task] 
Introduce the InputSelectionHandler for selecting next input in 
StreamTwoInputSelectableProcessor
URL: https://github.com/apache/flink/pull/9477#discussion_r317173222
 
 

 ##
 File path: 
flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/io/InputSelectionHandler.java
 ##
 @@ -0,0 +1,82 @@
+/*
+ * 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.flink.streaming.runtime.io;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.streaming.api.operators.InputSelectable;
+import org.apache.flink.streaming.api.operators.InputSelection;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+import static org.apache.flink.util.Preconditions.checkState;
+
+/**
+ * This handler is mainly used for selecting the next available input index
+ * in {@link StreamTwoInputSelectableProcessor}.
+ */
+@Internal
+public class InputSelectionHandler {
+
+   private final InputSelectable inputSelector;
+
+   private InputSelection inputSelection;
+
+   private int availableInputsMask;
+
+   public InputSelectionHandler(InputSelectable inputSelectable) {
+   this.inputSelector = checkNotNull(inputSelectable);
+   this.availableInputsMask = (int) new 
InputSelection.Builder().select(1).select(2).build().getInputMask();
+   }
+
+   void nextSelection() {
+   inputSelection = inputSelector.nextSelection();
+   }
+
+   int selectNextInputIndex(int lastReadInputIndex) {
+   return 
inputSelection.fairSelectNextIndexOutOf2(availableInputsMask, 
lastReadInputIndex);
+   }
+
+   boolean shouldSetAvailableForAnotherInput() {
+   return availableInputsMask < 3 && inputSelection.isALLMaskOf2();
+   }
+
+   void setAvailableInput(int inputIndex) {
+   availableInputsMask |= 1 << inputIndex;
+   }
+
+   void setUnavailableInput(int inputIndex) {
+   availableInputsMask &= ~(1 << inputIndex);
+   }
+
+   boolean isALLInputsSelected() {
+   checkState(inputSelection != null);
 
 Review comment:
   nitty nit: I think there is little value of this `checkState`, as 
`NullPointerException` would be thrown one line below and it doesn't safeguard 
any arguments. But you can keep this if you prefer.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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


[GitHub] [flink] pnowojski commented on a change in pull request #9477: [FLINK-13765][task] Introduce the InputSelectionHandler for selecting next input in StreamTwoInputSelectableProcessor

2019-08-23 Thread GitBox
pnowojski commented on a change in pull request #9477: [FLINK-13765][task] 
Introduce the InputSelectionHandler for selecting next input in 
StreamTwoInputSelectableProcessor
URL: https://github.com/apache/flink/pull/9477#discussion_r317160696
 
 

 ##
 File path: 
flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/io/InputSelectionHandler.java
 ##
 @@ -0,0 +1,82 @@
+/*
+ * 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.flink.streaming.runtime.io;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.streaming.api.operators.InputSelectable;
+import org.apache.flink.streaming.api.operators.InputSelection;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+import static org.apache.flink.util.Preconditions.checkState;
+
+/**
+ * This handler is mainly used for selecting the next available input index
+ * in {@link StreamTwoInputSelectableProcessor}.
+ */
+@Internal
+public class InputSelectionHandler {
 
 Review comment:
   nit: Maybe rename to `TwoInputSelectionHandler` to mark that it only 
supports two inputs?


This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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