He-Pin commented on code in PR #1386: URL: https://github.com/apache/pekko/pull/1386#discussion_r1664523062
########## actor-typed/src/main/scala/org/apache/pekko/actor/typed/Behavior.scala: ########## @@ -71,6 +69,43 @@ abstract class Behavior[T](private[pekko] val _tag: Int) { behavior => } +/** + * TODO scala doc + */ +final class SuperviseBehavior[T] private[pekko] ( + val wrapped: Behavior[T]) extends Behavior[T](BehaviorTags.SuperviseBehavior) { + private final val ThrowableClassTag = ClassTag(classOf[Throwable]) + + /** Specify the [[SupervisorStrategy]] to be invoked when the wrapped behavior throws. */ + def onFailure[Thr <: Throwable](strategy: SupervisorStrategy)( + implicit tag: ClassTag[Thr] = ThrowableClassTag): SuperviseBehavior[T] = { + val effectiveTag = if (tag == ClassTag.Nothing) ThrowableClassTag else tag + new SuperviseBehavior[T](Supervisor(Behavior.validateAsInitial(wrapped), strategy)(effectiveTag)) + } + + /** + * Java API: + * Specify the [[SupervisorStrategy]] to be invoked when the wrapped behavior throws. + * + * Only exceptions of the given type (and their subclasses) will be handled by this supervision behavior. + */ + def onFailure[Thr <: Throwable](clazz: Class[Thr], strategy: SupervisorStrategy): SuperviseBehavior[T] = { + onFailure(strategy)(ClassTag(clazz)) + } + + /** + * Java API: + * Specify the [[SupervisorStrategy]] to be invoked when the wrapped behavior throws. + * + * Only exceptions of the given type (and their subclasses) will be handled by this supervision behavior. + */ + def onNotFatalFailure[Thr <: Throwable](strategy: SupervisorStrategy): SuperviseBehavior[T] = { + onFailure(classOf[Exception], strategy) Review Comment: Better with NonFatal apply? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@pekko.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@pekko.apache.org For additional commands, e-mail: notifications-h...@pekko.apache.org