@Override public void onReceive(Object message) throws Exception { final String messageType = message.getClass().getSimpleName(); LOG.trace("onReceive {} {}", messageType, message); // check to see if we got quarantined by another node if(quarantined) { return; } // TODO: follow https://github.com/akka/akka/issues/18758 to see if Akka adds a named // exception for quarantine detection if (message instanceof AssociationErrorEvent) { AssociationErrorEvent event = (AssociationErrorEvent) message; Throwable cause = event.getCause(); if (cause instanceof InvalidAssociation) { Throwable cause2 = ((InvalidAssociation) cause).getCause(); if (cause2.getMessage().contains("quarantined this system")) { quarantined = true; LOG.warn("Got quarantined by {}", event.getRemoteAddress()); // execute the callback callback.apply(); } else { LOG.debug("received AssociationErrorEvent, cause: InvalidAssociation", cause2); } } else { LOG.debug("received AssociationErrorEvent", cause); } } }
@Test public void testOnReceiveAnother() throws Exception { final Address local = Address.apply("http", "local"); final Address remote = Address.apply("http", "remote"); final Throwable t = new RuntimeException("Another exception"); final InvalidAssociation cause = InvalidAssociation.apply(local, remote, t, Option.apply(null)); final AssociationErrorEvent event = new AssociationErrorEvent(cause, local, remote, true, Logging.ErrorLevel()); actor.tell(event, ActorRef.noSender()); verify(callback, never()).apply(); }