net.ninjacat.drama
Class Actor

java.lang.Object
  extended by net.ninjacat.drama.Actor
All Implemented Interfaces:
Runnable

public class Actor
extends Object
implements Runnable

 Override this class to implement your actors.

 To receive messages from other actors declare methods that will receive messages.
 Receivers should be annotated with Receiver annotation and have following signature:

   public void onMessage(ActorRef sender, T message);

 message parameter could be of any type.

 If there is no receiver method for a specified message type, then message will be delivered to
 unhandled(ActorRef, Object) receiver. By default that receiver does nothing.

 Be aware that message receiver methods could be called on any thread. Each other message could be received on
 different thread.

 ActorRef parameter to a receiver method can be null.

 Messages should be immutable. It is also recommended that message classes be declared as final.
 Declaring receiver for a particular type and sending messages of descendant types is supported, but not
 recommended as it is inefficient and requires additional memory.

 


Field Summary
protected  Collection<Method> allReceiverMethods
           
protected  Map<Class<?>,Method> receivers
           
protected  Set<Class<?>> unsupportedMessageClasses
           
 
Constructor Summary
Actor()
           
 
Method Summary
 boolean equals(Object o)
           
 ActorSystem getActorSystem()
           
protected  Semaphore getExecutionLock()
           
 String getName()
           
 ActorRef getSelf()
           
 int hashCode()
           
protected  void onShutdown()
           This method is called after actor is deleted.
protected  void onStartup()
           This method is called when new actor is created, before any message could be delivered to this actor.
 void onSystemMessage(ActorRef sender, SystemMessage message)
           
 void run()
          Performs message dispatching for this actor's inbox
 String toString()
           
protected  void unhandled(ActorRef sender, Object message)
           This method is called when no other receivers for message is found.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

allReceiverMethods

protected final Collection<Method> allReceiverMethods

receivers

protected final Map<Class<?>,Method> receivers

unsupportedMessageClasses

protected final Set<Class<?>> unsupportedMessageClasses
Constructor Detail

Actor

public Actor()
Method Detail

getName

public String getName()
Returns:
The name of this actor in its ActorSystem

getSelf

public ActorRef getSelf()
Returns:
Reference to this actor

getActorSystem

public ActorSystem getActorSystem()
Returns:
Actor's parent ActorSystem

run

public final void run()
Performs message dispatching for this actor's inbox

Specified by:
run in interface Runnable

onSystemMessage

public final void onSystemMessage(ActorRef sender,
                                  SystemMessage message)

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

getExecutionLock

protected Semaphore getExecutionLock()

onStartup

protected void onStartup()
 This method is called when new actor is created, before any message could be delivered to this actor.
 Default implementation does nothing.
 


onShutdown

protected void onShutdown()
 This method is called after actor is deleted. No messages will be delivered to this actor after this method is called.
 Default implementation does nothing.

 Usually actor is deleted by calling ActorRef.stop(), but it may as well be deleted when its ActorSystem
 is terminating.
 


unhandled

protected void unhandled(ActorRef sender,
                         Object message)
 This method is called when no other receivers for message is found.
 

Parameters:
sender - ActorRef which sent the message
message - Message itself


Copyright © 2014. All rights reserved.