edu.vub.at.actors.natives
Class ELActor

java.lang.Object
  extended byedu.vub.at.actors.eventloops.EventLoop
      extended byedu.vub.at.actors.natives.ELActor
Direct Known Subclasses:
ELDiscoveryActor

public class ELActor
extends EventLoop

An instance of the class ELActor represents a programmer-defined AmbientTalk/2 actor. The event queue of the actor event loop serves as the actor's 'meta-level' queue. The events in the 'meta-level' queue are handled by the actor's mirror object. This mirror is normally an instance of NATActorMirror, but it can be any programmer-defined object that adheres to the ATActorMirror interface.

Author:
tvcutsem

Nested Class Summary
 
Nested classes inherited from class edu.vub.at.actors.eventloops.EventLoop
EventLoop.EventProcessor
 
Field Summary
private  ATObject behaviour_
           
protected  ELVirtualMachine host_
           
private  ATActorMirror mirror_
           
protected  ReceptionistsSet receptionists_
           
 
Fields inherited from class edu.vub.at.actors.eventloops.EventLoop
eventQueue_, processor_
 
Constructor Summary
  ELActor(ATActorMirror mirror, ELVirtualMachine host)
           
protected ELActor(ELVirtualMachine host)
          constructor dedicated to initialization of discovery actor
 
Method Summary
static ELActor currentActor()
           
 void event_accept(Packet serializedMessage)
          The main entry point for any asynchronous messages sent to this actor by external sources (e.g. the VM or other local actors).
 void event_acceptSelfSend(ATAsyncMessage msg)
          The main entry point for any asynchronous self-sends.
protected  void event_init(BlockingFuture future, Packet parametersPkt, Packet initcodePkt)
          The initial event sent by the actor mirror to its event loop to intialize itself.
 void event_serviceJoined(Packet requiredStripePkt, ATFarReference myHandler, Packet discoveredStripePkt, Packet remoteServicePkt)
          When the discovery manager receives a publication from another local actor or another remote VM, the actor is asked to compare the incoming publication against a subscription that it had announced previously.
 NATLocalFarRef export(ATObject object)
          Export the given local object such that it is now remotely accessible via the returned object id.
 ATActorMirror getActorMirror()
           
 ELVirtualMachine getHost()
           
 void handle(Event event)
          Actor event loops handle events by allowing the meta-level events to process themselves.
protected  void initRootObject()
          Initialises the root using the contents of the init file stored by the hosting virtual machine.
protected  void initSharedFields()
          Initialises various fields in the lexical root of the actor, which are defined in the context of every actor.
 ATObject resolve(ATObjectID id, ATStripe[] stripes)
          Resolve the given object id into a local reference.
 void setActorMirror(ATActorMirror mirror)
           
 ATObject sync_event_eval(ATAbstractGrammar ast)
          This method should only be used for purposes such as the IAT shell or unit testing.
 java.lang.Object sync_event_performTest(Callable c)
          This method should only be used for purposes of unit testing.
 java.lang.Object sync_event_symbioticInvocation(Callable invocation)
          This method is invoked by a coercer in order to schedule a symbiotic invocation from the Java world, which should be synchronous to the Java thread, but which must be scheduled asynchronously to comply with the AT/2 actor model.
 
Methods inherited from class edu.vub.at.actors.eventloops.EventLoop
currentEventLoop, execute, owner, receive, receiveAndWait, receivePrioritized, stopProcessing, toEventLoop, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

mirror_

private ATActorMirror mirror_

host_

protected final ELVirtualMachine host_

receptionists_

protected final ReceptionistsSet receptionists_

behaviour_

private ATObject behaviour_
Constructor Detail

ELActor

public ELActor(ATActorMirror mirror,
               ELVirtualMachine host)

ELActor

protected ELActor(ELVirtualMachine host)
constructor dedicated to initialization of discovery actor

Method Detail

currentActor

public static final ELActor currentActor()

handle

public void handle(Event event)
Actor event loops handle events by allowing the meta-level events to process themselves.

Specified by:
handle in class EventLoop
Parameters:
event - the event object which was dequeued and which should be processed

getActorMirror

public ATActorMirror getActorMirror()

setActorMirror

public void setActorMirror(ATActorMirror mirror)

getHost

public ELVirtualMachine getHost()

export

public NATLocalFarRef export(ATObject object)
                      throws InterpreterException
Export the given local object such that it is now remotely accessible via the returned object id.

Parameters:
object - a **near** reference to the object to export
Returns:
a unique identifier by which this object can be retrieved via the resolve method.
Throws:
XIllegalOperation - if the passed object is a far reference, i.e. non-local
InterpreterException

resolve

public ATObject resolve(ATObjectID id,
                        ATStripe[] stripes)
Resolve the given object id into a local reference. There are three cases to consider: A) The given id designates an object local to this actor: the returned object will be a **near** reference to the object (i.e. the object itself) B) The given id designates a far (non-local) object that lives in the same address space as this actor: the returned object wil be a **far** reference to the object. C) The given id designates a far object that lives on a remote machine: the returned object will be a **far** and **remote** reference to the object.

Parameters:
id - the identifier of the object to resolve
Returns:
a near or far reference to the object, depending on where the designated object lives

initRootObject

protected void initRootObject()
                       throws InterpreterException
Initialises the root using the contents of the init file stored by the hosting virtual machine.

Throws:
InterpreterException

initSharedFields

protected void initSharedFields()
                         throws InterpreterException
Initialises various fields in the lexical root of the actor, which are defined in the context of every actor. Candidates are a "system" field which allows the program to perform IO operations or a "~" field denoting the current working directory.

Throws:
InterpreterException - when initialisation of a field fails

event_init

protected void event_init(BlockingFuture future,
                          Packet parametersPkt,
                          Packet initcodePkt)
The initial event sent by the actor mirror to its event loop to intialize itself.

Parameters:
future - the synchronization point with the creating actor, needs to be fulfilled with a far ref to the behaviour.
parametersPkt - the serialized parameters for the initialization code
initcodePkt - the serialized initialization code

event_acceptSelfSend

public void event_acceptSelfSend(ATAsyncMessage msg)
The main entry point for any asynchronous self-sends. Asynchronous self-sends do not undergo any form of parameter passing, there is no need to serialize and deserialize the message parameter in a Packet.


event_accept

public void event_accept(Packet serializedMessage)
The main entry point for any asynchronous messages sent to this actor by external sources (e.g. the VM or other local actors).


sync_event_symbioticInvocation

public java.lang.Object sync_event_symbioticInvocation(Callable invocation)
                                                throws java.lang.Exception
This method is invoked by a coercer in order to schedule a symbiotic invocation from the Java world, which should be synchronous to the Java thread, but which must be scheduled asynchronously to comply with the AT/2 actor model.

Parameters:
invocation - a functor object that will perform the symbiotic invocation
Returns:
the result of the symbiotic invocation
Throws:
java.lang.Exception - if the symbiotic invocation fails

sync_event_eval

public ATObject sync_event_eval(ATAbstractGrammar ast)
                         throws InterpreterException
This method should only be used for purposes such as the IAT shell or unit testing. It allows an external thread to make this actor evaluate an arbitrary expression.

Parameters:
ast - an abstract syntax tree to be evaluated by the receiving actor (in the scope of its behaviour).
Returns:
the result of the evaluation
Throws:
InterpreterException - if the evaluation fails

sync_event_performTest

public java.lang.Object sync_event_performTest(Callable c)
                                        throws java.lang.Exception
This method should only be used for purposes of unit testing. It allows arbitary code to be scheduled by external threads such as unit testing frameworks.

Throws:
java.lang.Exception

event_serviceJoined

public void event_serviceJoined(Packet requiredStripePkt,
                                ATFarReference myHandler,
                                Packet discoveredStripePkt,
                                Packet remoteServicePkt)
When the discovery manager receives a publication from another local actor or another remote VM, the actor is asked to compare the incoming publication against a subscription that it had announced previously.

Parameters:
myHandler - the closure specified as a handler for the actor's subscription