org.semispace.actor
Class Actor

java.lang.Object
  extended by org.semispace.actor.Actor

public abstract class Actor
extends Object

Implementation of an actor. You need to register the actor in a space, in order to get a lifetime of the actor. The read and take templates are registered at this time as well.


Constructor Summary
Actor()
           
 
Method Summary
 Long getActorId()
           
 long getDefaultLifeMsOfSpaceObject()
           
 Object[] getReadTemplates()
          Default implementation which renders empty array, ie nothing is tried read.
 Object[] getTakeTemplates()
          Default implementation which renders an empty array, ie nothing is tried taken.
abstract  void receive(ActorMessage msg)
          Receive a message which either matches the template, or that is addressed to this actor in particular (which implies that you need to check the type for each message).
 void register(SemiSpaceInterface registerWith)
          Register with the space with a very long long actor life.
 void register(SemiSpaceInterface registerWith, long actorLifeMs)
          You must register with a space in order to activate the actor.
 void send(Long destinationId, Object payload)
          This is the regular method for sending a message to an actor.
 void send(Object obj)
          Send two message to the space.
 void setDefaultLifeMsOfSpaceObject(long defaultLifeMsOfSpaceObject)
          How long a message will live in the space when it is sent.
 void unregister()
          Removing the connection(s) from the space rendering the actor, for all practical purposes, dead.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Actor

public Actor()
Method Detail

getDefaultLifeMsOfSpaceObject

public long getDefaultLifeMsOfSpaceObject()

setDefaultLifeMsOfSpaceObject

public void setDefaultLifeMsOfSpaceObject(long defaultLifeMsOfSpaceObject)
How long a message will live in the space when it is sent.


register

public final void register(SemiSpaceInterface registerWith)
Register with the space with a very long long actor life. Useful when you are actively using unregister, or expect the actor to live longer than the VM itself.

See Also:
unregister(), register(SemiSpaceInterface, long)

register

public final void register(SemiSpaceInterface registerWith,
                           long actorLifeMs)
You must register with a space in order to activate the actor.

Parameters:
actorLifeMs - How long the actor shall be active in milliseconds
See Also:
unregister()

unregister

public void unregister()
Removing the connection(s) from the space rendering the actor, for all practical purposes, dead.


send

public void send(Object obj)
Send two message to the space. The first is the object to write, the other is the manifest for the message, which can be used by the listening actor to find the originator. This method is intended only to be used when initiating an actor dialog, as the destination is unknown


send

public void send(Long destinationId,
                 Object payload)
This is the regular method for sending a message to an actor. The message will be delivered directly to the indicated actor. No of the parameters may be null.

Parameters:
destinationId - When replying to a message, the originatorId should be the destination id. i.e. the destination address

getActorId

public Long getActorId()
Returns:
Id of this actor provided that it is registered in a space.

getTakeTemplates

public Object[] getTakeTemplates()
Default implementation which renders an empty array, ie nothing is tried taken. Exchange with relevant elements. Object are tried taken from the space. Observe that the object taken is the one that fits the template, and not necessarily the one which triggered the event.


getReadTemplates

public Object[] getReadTemplates()
Default implementation which renders empty array, ie nothing is tried read.

See Also:
getTakeTemplates()

receive

public abstract void receive(ActorMessage msg)
Receive a message which either matches the template, or that is addressed to this actor in particular (which implies that you need to check the type for each message).



Copyright © 2008-2012. All Rights Reserved.