@Override public void apply(Object msg) throws Exception { if (msg.equals(Processing.STOP)) { getContext().unbecome(); } else { handleMessage(msg); } } });
private void handleHandshakeMessage(RemoteHandshakeMessage handshakeMessage) { if (!isCompatibleVersion(handshakeMessage.getVersion())) { sendErrorIfSender(new AkkaHandshakeException( String.format( "Version mismatch between source (%s) and target (%s) rpc component. Please verify that all components have the same version.", handshakeMessage.getVersion(), getVersion()))); } else if (!isGatewaySupported(handshakeMessage.getRpcGateway())) { sendErrorIfSender(new AkkaHandshakeException( String.format( "The rpc endpoint does not support the gateway %s.", handshakeMessage.getRpcGateway().getSimpleName()))); } else { getSender().tell(new Status.Success(HandshakeSuccessMessage.INSTANCE), getSelf()); } }
protected void handleRpcMessage(Object message) { 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); sendErrorIfSender(new AkkaUnknownMessageException("Received unknown message " + message + " of type " + message.getClass().getSimpleName() + '.')); } }
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(); } }
Class<?>[] parameterTypes = rpcInvocation.getParameterTypes(); rpcMethod = lookupRpcMethod(methodName, parameterTypes); } catch(ClassNotFoundException e) { LOG.error("Could not load method arguments.", e); getSender().tell(new Status.Failure(rpcException), getSelf()); } catch (IOException e) { LOG.error("Could not deserialize rpc invocation message.", e); getSender().tell(new Status.Failure(rpcException), getSelf()); } catch (final NoSuchMethodException e) { LOG.error("Could not find rpc method for rpc invocation.", e); getSender().tell(new Status.Failure(rpcException), getSelf()); getSender().tell(new Status.Failure(e.getTargetException()), getSelf()); return; Patterns.pipe(flinkFuture.getScalaFuture(), getContext().dispatcher()).to(getSender()); } else { }, getContext().dispatcher()), getContext().dispatcher()); getSender().tell(new Status.Success(result), getSelf()); getSender().tell(new Status.Failure(e), getSelf());
RunAsync message = new RunAsync(runAsync.getRunnable(), timeToRun); final Object envelopedSelfMessage = envelopeSelfMessage(message); getContext().system().scheduler().scheduleOnce(delay, getSelf(), envelopedSelfMessage, getContext().dispatcher(), ActorRef.noSender());
@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.equals(Processing.START)) { getContext().become(new Procedure<Object>() { @Override public void apply(Object msg) throws Exception { if (msg.equals(Processing.STOP)) { getContext().unbecome(); } else { handleMessage(msg); } } }); } else { LOG.info("The rpc endpoint {} has not been started yet. Discarding message {} until processing is started.", rpcEndpoint.getClass().getName(), message.getClass().getName()); if (!getSender().equals(ActorRef.noSender())) { // fail a possible future if we have a sender getSender().tell(new Status.Failure(new AkkaRpcException("Discard message, because " + "the rpc endpoint has not been started yet.")), getSelf()); } } }
RunAsync message = new RunAsync(runAsync.getRunnable(), timeToRun); getContext().system().scheduler().scheduleOnce(delay, getSelf(), message, getContext().dispatcher(), ActorRef.noSender());
private boolean isCompatibleVersion(int sourceVersion) { return sourceVersion == getVersion(); }
Class<?>[] parameterTypes = rpcInvocation.getParameterTypes(); rpcMethod = lookupRpcMethod(methodName, parameterTypes); } catch (ClassNotFoundException e) { log.error("Could not load method arguments.", e); getSender().tell(new Status.Failure(rpcException), getSelf()); } catch (IOException e) { log.error("Could not deserialize rpc invocation message.", e); getSender().tell(new Status.Failure(rpcException), getSelf()); } catch (final NoSuchMethodException e) { log.error("Could not find rpc method for rpc invocation.", e); getSender().tell(new Status.Failure(rpcException), getSelf()); getSender().tell(new Status.Failure(e.getTargetException()), getSelf()); return; Patterns.pipe(promise.future(), getContext().dispatcher()).to(getSender()); } else { getSender().tell(new Status.Success(result), getSelf()); log.error("Error while executing remote procedure call {}.", rpcMethod, e); getSender().tell(new Status.Failure(e), getSelf());
RunAsync message = new RunAsync(runAsync.getRunnable(), timeToRun); final Object envelopedSelfMessage = envelopeSelfMessage(message); getContext().system().scheduler().scheduleOnce(delay, getSelf(), envelopedSelfMessage, getContext().dispatcher(), ActorRef.noSender());
@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()))); } }
private boolean isCompatibleVersion(int sourceVersion) { return sourceVersion == getVersion(); }
private void handleHandshakeMessage(RemoteHandshakeMessage handshakeMessage) { if (!isCompatibleVersion(handshakeMessage.getVersion())) { sendErrorIfSender(new AkkaHandshakeException( String.format( "Version mismatch between source (%s) and target (%s) rpc component. Please verify that all components have the same version.", handshakeMessage.getVersion(), getVersion()))); } else if (!isGatewaySupported(handshakeMessage.getRpcGateway())) { sendErrorIfSender(new AkkaHandshakeException( String.format( "The rpc endpoint does not support the gateway %s.", handshakeMessage.getRpcGateway().getSimpleName()))); } else { getSender().tell(new Status.Success(HandshakeSuccessMessage.INSTANCE), getSelf()); } }
Class<?>[] parameterTypes = rpcInvocation.getParameterTypes(); rpcMethod = lookupRpcMethod(methodName, parameterTypes); } catch (ClassNotFoundException e) { log.error("Could not load method arguments.", e); getSender().tell(new Status.Failure(rpcException), getSelf()); } catch (IOException e) { log.error("Could not deserialize rpc invocation message.", e); getSender().tell(new Status.Failure(rpcException), getSelf()); } catch (final NoSuchMethodException e) { log.error("Could not find rpc method for rpc invocation.", e); getSender().tell(new Status.Failure(rpcException), getSelf()); getSender().tell(new Status.Failure(e.getTargetException()), getSelf()); return; Patterns.pipe(promise.future(), getContext().dispatcher()).to(getSender()); } else { getSender().tell(new Status.Success(result), getSelf()); log.error("Error while executing remote procedure call {}.", rpcMethod, e); getSender().tell(new Status.Failure(e), getSelf());
protected void handleRpcMessage(Object message) { 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); sendErrorIfSender(new AkkaUnknownMessageException("Received unknown message " + message + " of type " + message.getClass().getSimpleName() + '.')); } }