Skip to content

Using Behaviors

ARn edited this page Apr 20, 2016 · 1 revision

Using Behaviors

####Behaviors

Once created, an actor at message reception can :

  • send a message to other actors he knows about
  • create other actors
  • change its own behavior

To change an actor behavior, you could :

  • use the Become statement, all previous behaviors are cleared and replace by the new one
  • use the AddBehavior statement, adding a new behavior to the list of existing behaviors.
Become statement

Here a small sample of usage for the Become statement ...

Become(new ActionBehavior());

It means : "this actor will now answer to Action Message".

AddBehavior statement

And here an example for AddBehavior statement ...

AddBehavior(new ConsoleBehavior<string>()); 
AddBehavior(new ConsoleStringListbehavior()); 
AddBehavior(new ConsoleDictionaryBehavior()); 
AddBehavior(new ConsoleBehavior<int>()); 

this one comes from the ActorConsole.

Clone this wiki locally