AkkaRpcActor(final T rpcEndpoint, final CompletableFuture<Boolean> terminationFuture, final int version) { this.rpcEndpoint = checkNotNull(rpcEndpoint, "rpc endpoint"); this.mainThreadValidator = new MainThreadValidatorUtil(rpcEndpoint); this.terminationFuture = checkNotNull(terminationFuture); this.version = version; this.state = State.STOPPED; }
private void handleMessage(Object message) { mainThreadValidator.enterMainThread(); try { if (message instanceof RunAsync) { handleRunAsync((RunAsync) message); } else if (message instanceof CallAsync) { handleCallAsync((CallAsync) message); } else if (message instanceof RpcInvocation) { handleRpcInvocation((RpcInvocation) message); } else { LOG.warn( "Received message of unknown type {} with value {}. Dropping this message!", message.getClass().getName(), message); } } finally { mainThreadValidator.exitMainThread(); } }
@Override public void onReceive(final Object message) { if (message instanceof RemoteHandshakeMessage) { handleHandshakeMessage((RemoteHandshakeMessage) message); } else if (message.equals(Processing.START)) { state = State.STARTED; } else if (message.equals(Processing.STOP)) { state = State.STOPPED; } else if (state == State.STARTED) { mainThreadValidator.enterMainThread(); try { handleRpcMessage(message); } finally { mainThreadValidator.exitMainThread(); } } else { log.info("The rpc endpoint {} has not been started yet. Discarding message {} until processing is started.", rpcEndpoint.getClass().getName(), message.getClass().getName()); sendErrorIfSender(new AkkaRpcException( String.format("Discard message, because the rpc endpoint %s has not been started yet.", rpcEndpoint.getAddress()))); } }
AkkaRpcActor(final T rpcEndpoint, final CompletableFuture<Boolean> terminationFuture, final int version) { this.rpcEndpoint = checkNotNull(rpcEndpoint, "rpc endpoint"); this.mainThreadValidator = new MainThreadValidatorUtil(rpcEndpoint); this.terminationFuture = checkNotNull(terminationFuture); this.version = version; this.state = State.STOPPED; }
@Override public void postStop() throws Exception { mainThreadValidator.enterMainThread(); try { CompletableFuture<Void> postStopFuture; try { postStopFuture = rpcEndpoint.postStop(); } catch (Throwable throwable) { postStopFuture = FutureUtils.completedExceptionally(throwable); } super.postStop(); // IMPORTANT: This only works if we don't use a restarting supervisor strategy. Otherwise // we would complete the future and let the actor system restart the actor with a completed // future. // Complete the termination future so that others know that we've stopped. postStopFuture.whenComplete( (Void value, Throwable throwable) -> { if (throwable != null) { terminationFuture.completeExceptionally(throwable); } else { terminationFuture.complete(null); } }); } finally { mainThreadValidator.exitMainThread(); } }
AkkaRpcActor(final T rpcEndpoint, final CompletableFuture<Void> terminationFuture) { this.rpcEndpoint = checkNotNull(rpcEndpoint, "rpc endpoint"); this.mainThreadValidator = new MainThreadValidatorUtil(rpcEndpoint); this.terminationFuture = checkNotNull(terminationFuture); }
@Override public void postStop() throws Exception { mainThreadValidator.enterMainThread(); try { CompletableFuture<Void> postStopFuture; try { postStopFuture = rpcEndpoint.postStop(); } catch (Throwable throwable) { postStopFuture = FutureUtils.completedExceptionally(throwable); } super.postStop(); // IMPORTANT: This only works if we don't use a restarting supervisor strategy. Otherwise // we would complete the future and let the actor system restart the actor with a completed // future. // Complete the termination future so that others know that we've stopped. postStopFuture.whenComplete( (Void value, Throwable throwable) -> { if (throwable != null) { terminationFuture.completeExceptionally(throwable); } else { terminationFuture.complete(null); } }); } finally { mainThreadValidator.exitMainThread(); } }
AkkaRpcActor(final T rpcEndpoint, final CompletableFuture<Boolean> terminationFuture, final int version) { this.rpcEndpoint = checkNotNull(rpcEndpoint, "rpc endpoint"); this.mainThreadValidator = new MainThreadValidatorUtil(rpcEndpoint); this.terminationFuture = checkNotNull(terminationFuture); this.version = version; this.state = State.STOPPED; }
@Override public void postStop() throws Exception { mainThreadValidator.enterMainThread(); try { CompletableFuture<Void> postStopFuture; try { postStopFuture = rpcEndpoint.postStop(); } catch (Throwable throwable) { postStopFuture = FutureUtils.completedExceptionally(throwable); } super.postStop(); // IMPORTANT: This only works if we don't use a restarting supervisor strategy. Otherwise // we would complete the future and let the actor system restart the actor with a completed // future. // Complete the termination future so that others know that we've stopped. postStopFuture.whenComplete( (Void value, Throwable throwable) -> { if (throwable != null) { terminationFuture.completeExceptionally(throwable); } else { terminationFuture.complete(null); } }); } finally { mainThreadValidator.exitMainThread(); } }
@Override public void onReceive(final Object message) { if (message instanceof RemoteHandshakeMessage) { handleHandshakeMessage((RemoteHandshakeMessage) message); } else if (message.equals(Processing.START)) { state = State.STARTED; } else if (message.equals(Processing.STOP)) { state = State.STOPPED; } else if (state == State.STARTED) { mainThreadValidator.enterMainThread(); try { handleRpcMessage(message); } finally { mainThreadValidator.exitMainThread(); } } else { log.info("The rpc endpoint {} has not been started yet. Discarding message {} until processing is started.", rpcEndpoint.getClass().getName(), message.getClass().getName()); sendErrorIfSender(new AkkaRpcException( String.format("Discard message, because the rpc endpoint %s has not been started yet.", rpcEndpoint.getAddress()))); } }
@Override public void onReceive(final Object message) { if (message instanceof RemoteHandshakeMessage) { handleHandshakeMessage((RemoteHandshakeMessage) message); } else if (message.equals(Processing.START)) { state = State.STARTED; } else if (message.equals(Processing.STOP)) { state = State.STOPPED; } else if (state == State.STARTED) { mainThreadValidator.enterMainThread(); try { handleRpcMessage(message); } finally { mainThreadValidator.exitMainThread(); } } else { log.info("The rpc endpoint {} has not been started yet. Discarding message {} until processing is started.", rpcEndpoint.getClass().getName(), message.getClass().getName()); sendErrorIfSender(new AkkaRpcException( String.format("Discard message, because the rpc endpoint %s has not been started yet.", rpcEndpoint.getAddress()))); } }