add @throws annotation to actor life-cycle hooks, see #3188

This commit is contained in:
Roland 2013-04-01 16:35:33 +02:00
parent c77cdeb86b
commit d9d7d45ac2
3 changed files with 10 additions and 1 deletions

View file

@ -476,6 +476,7 @@ trait Actor {
* Actors are automatically started asynchronously when created. * Actors are automatically started asynchronously when created.
* Empty default implementation. * Empty default implementation.
*/ */
@throws(classOf[Exception])
def preStart() {} def preStart() {}
/** /**
@ -484,6 +485,7 @@ trait Actor {
* Is called asynchronously after 'actor.stop()' is invoked. * Is called asynchronously after 'actor.stop()' is invoked.
* Empty default implementation. * Empty default implementation.
*/ */
@throws(classOf[Exception])
def postStop() {} def postStop() {}
/** /**
@ -494,6 +496,7 @@ trait Actor {
* Is called on a crashed Actor right BEFORE it is restarted to allow clean * Is called on a crashed Actor right BEFORE it is restarted to allow clean
* up of resources before Actor is terminated. * up of resources before Actor is terminated.
*/ */
@throws(classOf[Exception])
def preRestart(reason: Throwable, message: Option[Any]) { def preRestart(reason: Throwable, message: Option[Any]) {
context.children foreach context.stop context.children foreach context.stop
postStop() postStop()
@ -505,6 +508,7 @@ trait Actor {
* <p/> * <p/>
* Is called right AFTER restart on the newly created Actor to allow reinitialization after an Actor crash. * Is called right AFTER restart on the newly created Actor to allow reinitialization after an Actor crash.
*/ */
@throws(classOf[Exception])
def postRestart(reason: Throwable) { preStart() } def postRestart(reason: Throwable) { preStart() }
/** /**

View file

@ -131,6 +131,7 @@ abstract class UntypedActor extends Actor {
* Actor are automatically started asynchronously when created. * Actor are automatically started asynchronously when created.
* Empty default implementation. * Empty default implementation.
*/ */
@throws(classOf[Exception])
override def preStart(): Unit = super.preStart() override def preStart(): Unit = super.preStart()
/** /**
@ -139,6 +140,7 @@ abstract class UntypedActor extends Actor {
* Is called asynchronously after 'actor.stop()' is invoked. * Is called asynchronously after 'actor.stop()' is invoked.
* Empty default implementation. * Empty default implementation.
*/ */
@throws(classOf[Exception])
override def postStop(): Unit = super.postStop() override def postStop(): Unit = super.postStop()
/** /**
@ -147,6 +149,7 @@ abstract class UntypedActor extends Actor {
* Is called on a crashed Actor right BEFORE it is restarted to allow clean * Is called on a crashed Actor right BEFORE it is restarted to allow clean
* up of resources before Actor is terminated. * up of resources before Actor is terminated.
*/ */
@throws(classOf[Exception])
override def preRestart(reason: Throwable, message: Option[Any]): Unit = super.preRestart(reason, message) override def preRestart(reason: Throwable, message: Option[Any]): Unit = super.preRestart(reason, message)
/** /**
@ -154,6 +157,7 @@ abstract class UntypedActor extends Actor {
* <p/> * <p/>
* Is called right AFTER restart on the newly created Actor to allow reinitialization after an Actor crash. * Is called right AFTER restart on the newly created Actor to allow reinitialization after an Actor crash.
*/ */
@throws(classOf[Exception])
override def postRestart(reason: Throwable): Unit = super.postRestart(reason) override def postRestart(reason: Throwable): Unit = super.postRestart(reason)
final def receive = { case msg onReceive(msg) } final def receive = { case msg onReceive(msg) }

View file

@ -33,7 +33,8 @@ public class InitializationDocSpecJava {
// of the actor. To opt-out from stopping the children, we // of the actor. To opt-out from stopping the children, we
// have to override preRestart() // have to override preRestart()
@Override @Override
public void preRestart(Throwable reason, Option<Object> message) { public void preRestart(Throwable reason, Option<Object> message)
throws Exception {
// Keep the call to postStop(), but no stopping of children // Keep the call to postStop(), but no stopping of children
postStop(); postStop();
} }