sanha commented on a change in pull request #45: [NEMO-103] Implement RPC between Client and Driver URL: https://github.com/apache/incubator-nemo/pull/45#discussion_r196278063
########## File path: client/src/main/java/edu/snu/nemo/client/DriverRPCServer.java ########## @@ -0,0 +1,182 @@ +/* + * Copyright (C) 2018 Seoul National University + * + * Licensed 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 edu.snu.nemo.client; + +import com.google.protobuf.InvalidProtocolBufferException; +import edu.snu.nemo.conf.JobConf; +import edu.snu.nemo.runtime.common.comm.ControlMessage; +import org.apache.reef.annotations.audience.ClientSide; +import org.apache.reef.tang.Configuration; +import org.apache.reef.tang.Injector; +import org.apache.reef.tang.Tang; +import org.apache.reef.tang.exceptions.InjectionException; +import org.apache.reef.wake.EventHandler; +import org.apache.reef.wake.impl.SyncStage; +import org.apache.reef.wake.remote.RemoteConfiguration; +import org.apache.reef.wake.remote.address.LocalAddressProvider; +import org.apache.reef.wake.remote.impl.TransportEvent; +import org.apache.reef.wake.remote.transport.Link; +import org.apache.reef.wake.remote.transport.Transport; +import org.apache.reef.wake.remote.transport.netty.NettyMessagingTransport; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.annotation.concurrent.NotThreadSafe; +import java.util.HashMap; +import java.util.Map; + +/** + * Implements RPC endpoint between Nemo Client and Nemo Driver. + */ +@ClientSide +@NotThreadSafe +public final class DriverRPCServer { + private final Map<ControlMessage.DriverToClientMessageType, EventHandler<ControlMessage.DriverToClientMessage>> + handlers = new HashMap<>(); + private boolean isRunning = false; + private boolean isShutdown = false; + private Transport transport; + private Link link; + private String host; + + private static final Logger LOG = LoggerFactory.getLogger(DriverRPCServer.class); + + /** + * Registers handler for the given type of message. + * @param type the type of message + * @param handler handler implementation + * @return {@code this} + */ + public DriverRPCServer registerHandler(final ControlMessage.DriverToClientMessageType type, + final EventHandler<ControlMessage.DriverToClientMessage> handler) { + ensureServerState(false); + if (handlers.putIfAbsent(type, handler) != null) { + throw new RuntimeException(String.format("A handler for %s already registered", type)); + } + return this; + } + + /** + * Runs the RPC server. + */ + public void run() { + ensureServerState(false); Review comment: Please add some method level or line level comment about why the sever is assumed to be not running. (if you think needed, please add similar comments for other uses cases also.) ---------------------------------------------------------------- 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
