Add Java API 'getRef' to 'Terminated' (#22985) (#23021)

* Add Java API 'getRef' to 'Terminated' (#22985)

* Expose `ActorRef[Nothing]` as `ActorRef[Void]` in Java API

* Expose `ActorRef[Void]` as Java API for more objects
This commit is contained in:
Arnout Engelen 2017-05-26 03:01:47 -07:00 committed by GitHub
parent 194b223ee0
commit f038d16ac9
2 changed files with 13 additions and 3 deletions

View file

@ -43,7 +43,7 @@ public class BehaviorBuilderTest extends JUnitSuite {
return Actor.<Message>same();
})
.onSignal(Terminated.class, (ctx, t) -> {
System.out.println("Terminating along with " + t.ref());
System.out.println("Terminating along with " + t.getRef());
return stopped();
})
.build();

View file

@ -7,12 +7,18 @@ package akka.typed
* Envelope that is published on the eventStream for every message that is
* dropped due to overfull queues.
*/
final case class Dropped(msg: Any, recipient: ActorRef[Nothing])
final case class Dropped(msg: Any, recipient: ActorRef[Nothing]) {
/** Java API */
def getRecipient(): ActorRef[Void] = recipient.asInstanceOf[ActorRef[Void]]
}
/**
* Exception that an actor fails with if it does not handle a Terminated message.
*/
final case class DeathPactException(ref: ActorRef[Nothing]) extends RuntimeException(s"death pact with $ref was triggered")
final case class DeathPactException(ref: ActorRef[Nothing]) extends RuntimeException(s"death pact with $ref was triggered") {
/** Java API */
def getRef(): ActorRef[Void] = ref.asInstanceOf[ActorRef[Void]]
}
/**
* Envelope for dead letters.
@ -63,4 +69,8 @@ final case class Terminated(ref: ActorRef[Nothing])(failed: Throwable) extends S
def wasFailed: Boolean = failed ne null
def failure: Throwable = failed
def failureOption: Option[Throwable] = Option(failed)
/** Java API */
def getRef(): ActorRef[Void] = ref.asInstanceOf[ActorRef[Void]]
}