StefanRRichter commented on a change in pull request #7665: [FLINK-11551][rpc] 
Allow RpcEndpoint to execute asynchronous stop operations
URL: https://github.com/apache/flink/pull/7665#discussion_r255032144
 
 

 ##########
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/rpc/akka/AkkaRpcActor.java
 ##########
 @@ -183,6 +176,64 @@ protected void handleRpcMessage(Object message) {
                }
        }
 
+       private void handleControlMessage(ControlMessages controlMessage) {
+               switch (controlMessage) {
+                       case START:
+                               if (state == State.STOPPED) {
+                                       state = State.STARTED;
+                               } else {
+                                       logStateTransitionWarning(state, 
State.STARTED);
+                               }
+                               break;
+                       case STOP:
+                               if (state == State.STARTED) {
+                                       state = State.STOPPED;
+                               } else {
+                                       logStateTransitionWarning(state, 
State.STOPPED);
+                               }
+                               break;
+                       case TERMINATE:
+                               terminateRpcActor();
+                               break;
+                       default:
+                               final String message = String.format("Received 
unknown control message %s. Dropping this message!", controlMessage);
+                               log.warn(message);
+                               sendErrorIfSender(new 
AkkaUnknownMessageException(message));
+               }
+       }
+
+       private void logStateTransitionWarning(State currentState, State 
targetState) {
+               log.warn("AkkaRpcActor is currently in state {} and cannot go 
into state {}.", currentState, targetState);
+       }
+
+       private void terminateRpcActor() {
+               if (state == State.STOPPED) {
+                       state = State.TERMINATING;
+
+                       rpcEndpointTerminationFuture = 
CompletableFuture.completedFuture(null);
+                       getSelf().tell(Kill.getInstance(), ActorRef.noSender());
+               } else if (state == State.STARTED) {
+                       state = State.TERMINATING;
+
+                       mainThreadValidator.enterMainThread();
+
+                       try {
+                               rpcEndpointTerminationFuture = 
rpcEndpoint.onStop();
+                       } finally {
+                               mainThreadValidator.exitMainThread();
 
 Review comment:
   nit: In case that we really need the finally block and end up there in an 
exceptional case, if asserts are enabled and the assert here is violated, it 
would swallow the original exception.

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