org.actorsguildframework
Class Actor

java.lang.Object
  extended by org.actorsguildframework.Actor

@Bean(threadSafe=true)
public abstract class Actor
extends Object

Actor is the class that all actors need to implement.

You can not create an actor using the 'new' operator. Doing so would throw an exception. Instead, Agent.create(Class) must be used to create a new instance. Agent returns a proxy for the actual Actor which must be used to access the actor. Most of the features of the Actor's Guild framework are being done by this invisible proxy.

An actor does not need a constructor, but you can define one without arguments. Anything you write in it will be visible in all normal messages, but not in multi-threaded messages (you need to synchronize manually for them).

For the Actor's initialization you implement bean properties, preferably with the Prop annotation which will ensure that they are thread-safe (the property implementations offered by most IDEs are not!). Properties can be initialized upon creation of the Actor in the Agent.create(Class, Props) invocation. After create completed setting the properties, the Agent will invoke the Actor's Initializer method. Implement one for any additional initialization work.

Every actor should define one or more methods to receive messages. These methods must be annotated with Message, and follow the rules given in the documentation of @Message. All the actual work is being done by the message implementations.

By default, an actor receives only one message at a time. Thus is it operated single-threaded, and does not need to take care of such things as synchronization. In some cases, especially to integrate external interfaces and code, it is useful or even required for an actor to process several messages simultaneously. This can be declared using the Model and Usage annotation.

An actor can have public methods that are not @Message. However, you are responsible for the synchronization of such methods, otherwise they will not work correctly.

See Also:
Agent, Agent.create(Class, Props)

Constructor Summary
Actor()
          The default constructor for all Actors.
 
Method Summary
 Agent getAgent()
          Returns the Agent of this Actor.
static Agent getCurrentAgent()
          Returns the current thread's agent, if the current thread is a thread processing an actor message.
 ImmediateResult<Void> noResult()
          Helper method to create a new ImmediateResult instance for methods that have no result.
<T> ImmediateResult<T>
result(T value)
          Helper method to create a new ImmediateResult instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Actor

public Actor()
The default constructor for all Actors. It will check whether the new Actor sub-class is a proxy. If it is not a proxy, an exception will be thrown to prevent this. You must create all Actors using the methods Agent.create(Class).

Throws:
ActorRuntimeException - if the instantiated actor is not a proxy class
Method Detail

getAgent

public final Agent getAgent()
Returns the Agent of this Actor.

Returns:
the Actor's Agent
See Also:
getCurrentAgent()

result

public <T> ImmediateResult<T> result(T value)
Helper method to create a new ImmediateResult instance.

Type Parameters:
T - the type of result
Parameters:
value - the result value
Returns:
the ImmediateResult instance

noResult

public ImmediateResult<Void> noResult()
Helper method to create a new ImmediateResult instance for methods that have no result.

Returns:
the ImmediateResult instance (carries null as value)

getCurrentAgent

public static Agent getCurrentAgent()
Returns the current thread's agent, if the current thread is a thread processing an actor message. Otherwise it returns null.

Returns:
the current agent, or null
See Also:
getAgent()