rymarm commented on a change in pull request #2333: URL: https://github.com/apache/drill/pull/2333#discussion_r734666739
########## File path: exec/rpc/src/main/java/org/apache/drill/exec/rpc/PongListener.java ########## @@ -0,0 +1,61 @@ +/* + * 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.drill.exec.rpc; + +import org.apache.drill.common.exceptions.DrillRuntimeException; +import org.apache.drill.shaded.guava.com.google.common.base.Stopwatch; + +import java.util.EventListener; +import java.util.concurrent.TimeUnit; + +/** + * PongListener realizes the listener pattern. It is used to verify, whether {@link org.apache.drill.exec.rpc.RpcBus.InboundHandler} + * received {@link InboundRpcMessage} with {@link org.apache.drill.exec.proto.GeneralRPCProtos.RpcMode#PONG PONG} mode. + */ +public class PongListener implements EventListener { + private boolean hasReceivedPong = false; + + /** + * Verify whether received {@link org.apache.drill.exec.proto.GeneralRPCProtos.RpcMode#PONG PONG} mode. + * + * @param timeout time in seconds to wait message receiving. Should be higher than 0 + * @return true if message is received until timeout, false otherwise + * @throws DrillRuntimeException if the value supplied for timeout is less than 0 + */ + public boolean pongIsReceived(int timeout) throws DrillRuntimeException { + if (timeout < 0) { + throw new DrillRuntimeException(String.format("Invalid timeout (%d<0).", timeout)); + } + + Stopwatch stopwatch = Stopwatch.createStarted(); + while (!hasReceivedPong) { Review comment: Thank you for your remark! I'll look at how to change this. -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
