Create a gist now

Instantly share code, notes, and snippets.

Embed
PostStart implementation for Akka
trait PostStart { actor: Actor =>
def postStart: Unit
override def preStart {
actor.become {
case "PostStart" => try { postStart } finally { actor.unbecome }
}
actor.self ! "PostStart"
}
}
/*Usage: class MyActor extends Actor with PostStart {
def postStart = {
...
}
def receive = {
... your usual business stuff goes here ...
}
}*/
@alaz

This comment has been minimized.

Show comment
Hide comment
@alaz

alaz Mar 6, 2011

override def preStart {
  super.preStart
  ...

?

alaz commented Mar 6, 2011

override def preStart {
  super.preStart
  ...

?

@viktorklang

This comment has been minimized.

Show comment
Hide comment
@viktorklang

viktorklang Mar 6, 2011

Alaz: Care to write that in code?

Owner

viktorklang commented Mar 6, 2011

Alaz: Care to write that in code?

@alaz

This comment has been minimized.

Show comment
Hide comment
@alaz

alaz Mar 6, 2011

The pleasure is all mine

alaz commented Mar 6, 2011

The pleasure is all mine

@twillouer

This comment has been minimized.

Show comment
Hide comment
@twillouer

twillouer Jan 10, 2013

Hi,

trait PostStart { actor: Actor =>
  def postStart: Unit

  override def preStart {
    context.become {
      case "PostStart" => try { postStart } finally { context.unbecome }
    }
    actor.self ! "PostStart"
  }
}

with Akka 2.1 (I didn't see this version)

Hi,

trait PostStart { actor: Actor =>
  def postStart: Unit

  override def preStart {
    context.become {
      case "PostStart" => try { postStart } finally { context.unbecome }
    }
    actor.self ! "PostStart"
  }
}

with Akka 2.1 (I didn't see this version)

@raq154

This comment has been minimized.

Show comment
Hide comment
@raq154

raq154 Jan 18, 2015

Can you provide java version of this code?

raq154 commented Jan 18, 2015

Can you provide java version of this code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment