edu.vub.at.actors.natives
Class NATActorMirror

java.lang.Object
  extended byedu.vub.at.objects.natives.NATNil
      extended byedu.vub.at.objects.natives.NATByRef
          extended byedu.vub.at.actors.natives.NATActorMirror
All Implemented Interfaces:
ATAbstractGrammar, ATActorMirror, ATConversions, ATExpression, ATNil, ATObject, ATStatement, java.io.Serializable

public class NATActorMirror
extends NATByRef
implements ATActorMirror

The NATActorMirror class implements the concurrency model of ambienttalk. It continually consumes meta-events which are written to a synchronized queue. This way the actor is notified of incoming messages, discovered and lost services, etc. When no meta- messages are available, the actor consumes base-level messages as they are stored in its inbox. These messages have a receiver object internal to the actor and they will be invoked on this receiver by the actor's thread.

Author:
smostinc
See Also:
Serialized Form

Nested Class Summary
static class NATActorMirror.NATProtocol
          A protocol object is defined as: object: { def installedMirror := //the installed actor mirror; def uninstall() { //uninstall the protocol object } }
static class NATActorMirror.NATPublication
          A publication object is defined as: object: { def topic := //topic under which service is published; def service := //the exported service object; def cancel() { //unexport the service object } }
static class NATActorMirror.NATSubscription
          A subscription object is defined as: object: { def topic := //topic subscribed to; def handler := //the closure to be triggered; def cancel() { //unsubscribe the handler } }
 
Field Summary
private  ELDiscoveryActor discoveryActor_
           
 
Fields inherited from class edu.vub.at.objects.natives.NATNil
_INSTANCE_
 
Fields inherited from interface edu.vub.at.actors.ATActorMirror
_IN_, _OUT_, _PROVIDED_, _REQUIRED_
 
Constructor Summary
NATActorMirror(ELVirtualMachine host)
          When initializing a new actor, do not forget that this constructor is still executed by the creating actor, not by the created actor.
 
Method Summary
 ATActorMirror base_asActorMirror()
           
 ATAsyncMessage base_createMessage(ATObject sender, ATSymbol selector, ATTable arguments)
          Creates a first-class message in the language.
 ATObject base_install_(ATClosure code)
          def install: { code }
 ATObject base_provide(ATStripe topic, ATObject service)
          This mechanism is the most basic mechanism to provide a service.
 ATObject base_require(ATStripe topic, ATClosure handler, ATBoolean isPermanent)
          This mechanism is the most basic mechanism to require a service.
 ATObject base_send(ATAsyncMessage message)
          When default base-level objects send an asynchronous message, they delegate this responsibility to their actor by means of this base-level method.
static NATLocalFarRef createActor(ELVirtualMachine host, Packet parametersPkt, Packet initcodePkt, ATActorMirror actorMirror)
          Creates a new actor on the specified host Virtual Machine.
static NATLocalFarRef createEmptyActor(ELVirtualMachine host, ATActorMirror actorMirror)
          Auxiliary creation method to create an actor with an empty behaviour.
 ATObject meta_clone()
          Clone the receiver object.
 ATTable meta_getStripes()
          Returns the stripes of this object.
 ATObject meta_newInstance(ATTable initargs)
          actor.new(closure) => same effect as evaluating 'actor: closure'
 NATText meta_print()
          Prints out the object in a human-readable way.
 ATObject meta_receive(ATAsyncMessage msg)
          Handles a first-class message of which it is the receiver.
 ATObject meta_send(ATAsyncMessage msg)
          To send a message msg to a receiver object rcv: - if rcv is a local reference, schedule accept(msg) in my incoming event queue - if rcv is a far reference, schedule msg in far reference's outbox
 
Methods inherited from class edu.vub.at.objects.natives.NATByRef
meta_pass, meta_resolve
 
Methods inherited from class edu.vub.at.objects.natives.NATNil
asAmbientTalkObject, asJavaClassUnderSymbiosis, asJavaObjectUnderSymbiosis, asNativeBoolean, asNativeException, asNativeFarReference, asNativeFraction, asNativeNumber, asNativeNumeric, asNativeTable, asNativeText, base__opeql__opeql_, base_asAsyncMessage, base_asBegin, base_asBoolean, base_asClosure, base_asDefinition, base_asExpression, base_asFarReference, base_asField, base_asHandler, base_asMessage, base_asMessageCreation, base_asMethod, base_asMirror, base_asNumber, base_asSplice, base_asStatement, base_asStripe, base_asSymbol, base_asTable, base_asUnquoteSplice, base_asVariableAssignment, base_init, base_isBoolean, base_isCallFrame, base_isClosure, base_isFarReference, base_isMessageCreation, base_isMethod, base_isMirror, base_isSplice, base_isStripe, base_isSymbol, base_isTable, base_isUnquoteSplice, base_isVariableAssignment, base_new, createChild, equals, isAmbientTalkObject, isJavaObjectUnderSymbiosis, isNativeBoolean, isNativeField, isNativeText, meta_addField, meta_addMethod, meta_assignField, meta_assignVariable, meta_defineField, meta_doesNotUnderstand, meta_eval, meta_extend, meta_getDynamicParent, meta_getLexicalParent, meta_grabField, meta_grabMethod, meta_invoke, meta_isCloneOf, meta_isRelatedTo, meta_isStripedWith, meta_listFields, meta_listMethods, meta_lookup, meta_quote, meta_respondsTo, meta_select, meta_share, readResolve, toString, writeReplace
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface edu.vub.at.objects.ATObject
base__opeql__opeql_, base_init, base_new, meta_addField, meta_addMethod, meta_assignField, meta_assignVariable, meta_defineField, meta_doesNotUnderstand, meta_eval, meta_extend, meta_getDynamicParent, meta_getLexicalParent, meta_grabField, meta_grabMethod, meta_invoke, meta_isCloneOf, meta_isRelatedTo, meta_isStripedWith, meta_listFields, meta_listMethods, meta_lookup, meta_pass, meta_quote, meta_resolve, meta_respondsTo, meta_select, meta_share
 
Methods inherited from interface edu.vub.at.objects.coercion.ATConversions
asAmbientTalkObject, asJavaClassUnderSymbiosis, asJavaObjectUnderSymbiosis, asNativeBoolean, asNativeException, asNativeFarReference, asNativeFraction, asNativeNumber, asNativeNumeric, asNativeTable, asNativeText, base_asAsyncMessage, base_asBegin, base_asBoolean, base_asClosure, base_asDefinition, base_asExpression, base_asFarReference, base_asField, base_asHandler, base_asMessage, base_asMessageCreation, base_asMethod, base_asMirror, base_asNumber, base_asSplice, base_asStatement, base_asStripe, base_asSymbol, base_asTable, base_asUnquoteSplice, base_asVariableAssignment, base_isBoolean, base_isCallFrame, base_isClosure, base_isFarReference, base_isMessageCreation, base_isMethod, base_isMirror, base_isSplice, base_isStripe, base_isSymbol, base_isTable, base_isUnquoteSplice, base_isVariableAssignment, isAmbientTalkObject, isJavaObjectUnderSymbiosis, isNativeBoolean, isNativeField, isNativeText
 

Field Detail

discoveryActor_

private final ELDiscoveryActor discoveryActor_
Constructor Detail

NATActorMirror

public NATActorMirror(ELVirtualMachine host)
When initializing a new actor, do not forget that this constructor is still executed by the creating actor, not by the created actor. To make the created actor perform something, it is necessary to use meta_receive to send itself messages for later execution.

Method Detail

createActor

public static NATLocalFarRef createActor(ELVirtualMachine host,
                                         Packet parametersPkt,
                                         Packet initcodePkt,
                                         ATActorMirror actorMirror)
                                  throws InterpreterException
Creates a new actor on the specified host Virtual Machine. The actor its behaviour is intialized by means of the passed parameters and initialization code. The calling thread is **blocked** until the actor has been constructed. However, actor behaviour and root initialization is carried out by the newly created actor itself.

Parameters:
host - the VM hosting this actor - after creation, the actor registers itself with this VM
parametersPkt - the serialized parameters used to invoke the initialization code
initcodePkt - the serialized initialization code used to initialize the actor behaviour
actorMirror - this actor's mirror
Returns:
a far reference to the behaviour of the actor
Throws:
InterpreterException

createEmptyActor

public static NATLocalFarRef createEmptyActor(ELVirtualMachine host,
                                              ATActorMirror actorMirror)
                                       throws InterpreterException
Auxiliary creation method to create an actor with an empty behaviour. Equivalent to evaluating: actor: { nil }

Throws:
InterpreterException

base_createMessage

public ATAsyncMessage base_createMessage(ATObject sender,
                                         ATSymbol selector,
                                         ATTable arguments)
                                  throws InterpreterException
Description copied from interface: ATActorMirror
Creates a first-class message in the language. Note that upon creation the message does not have a receiver yet. This field will be set once the message is actually being sent, a fact which can be intercepted by overriding the sendTo base-level method.

Specified by:
base_createMessage in interface ATActorMirror
Throws:
InterpreterException

base_provide

public ATObject base_provide(ATStripe topic,
                             ATObject service)
                      throws InterpreterException
Description copied from interface: ATActorMirror
This mechanism is the most basic mechanism to provide a service. It requires a separate service description and an object offering the service. The return value is a publication object which allows cancelling the service offer.

Specified by:
base_provide in interface ATActorMirror
Throws:
InterpreterException

base_require

public ATObject base_require(ATStripe topic,
                             ATClosure handler,
                             ATBoolean isPermanent)
                      throws InterpreterException
Description copied from interface: ATActorMirror
This mechanism is the most basic mechanism to require a service. The return value is a subscription object which allows cancelling the service offer.

Specified by:
base_require in interface ATActorMirror
Parameters:
isPermanent - - if true, the subscription is permanent, if false, once the subscription has been satisfied, it is automatically cancelled.
Throws:
InterpreterException

meta_clone

public ATObject meta_clone()
                    throws InterpreterException
Description copied from interface: ATObject
Clone the receiver object. This cloning closely corresponds to the allocation phase in class-based OO languages. In class-based languages, instance creation is based on the equation = () (i.e. first allocate a new instance, then initialize it). In our object-based model, allocation is replaced by cloning. When an object is asked to clone itself, it will also clone its dynamic parent if it extends this parent in an 'is-a' relationship. This is similar to the observation that, in class-based languages, allocating a new object of a subclass entails allocating space for the state of the superclass. Triggers the objectCloned event on this object's beholders (mirror observers). Initializing the clone is the responsibility of the method named .

Specified by:
meta_clone in interface ATObject
Overrides:
meta_clone in class NATNil
Throws:
InterpreterException

meta_newInstance

public ATObject meta_newInstance(ATTable initargs)
                          throws InterpreterException
actor.new(closure) => same effect as evaluating 'actor: closure'

Specified by:
meta_newInstance in interface ATObject
Overrides:
meta_newInstance in class NATNil
Throws:
InterpreterException

meta_print

public NATText meta_print()
                   throws InterpreterException
Description copied from interface: ATObject
Prints out the object in a human-readable way.

Specified by:
meta_print in interface ATObject
Overrides:
meta_print in class NATNil
Throws:
InterpreterException

meta_send

public ATObject meta_send(ATAsyncMessage msg)
                   throws InterpreterException
To send a message msg to a receiver object rcv: - if rcv is a local reference, schedule accept(msg) in my incoming event queue - if rcv is a far reference, schedule msg in far reference's outbox

Specified by:
meta_send in interface ATObject
Overrides:
meta_send in class NATNil
Throws:
InterpreterException

meta_receive

public ATObject meta_receive(ATAsyncMessage msg)
                      throws InterpreterException
Description copied from interface: ATObject
Handles a first-class message of which it is the receiver.

Specified by:
meta_receive in interface ATObject
Overrides:
meta_receive in class NATNil
Throws:
InterpreterException

meta_getStripes

public ATTable meta_getStripes()
                        throws InterpreterException
Description copied from interface: ATObject
Returns the stripes of this object. Note that only the stripes that were attached directly to this object are returned, not all of the parent's stripes as well.

Specified by:
meta_getStripes in interface ATObject
Overrides:
meta_getStripes in class NATNil
Throws:
InterpreterException

base_send

public ATObject base_send(ATAsyncMessage message)
                   throws InterpreterException
When default base-level objects send an asynchronous message, they delegate this responsibility to their actor by means of this base-level method. The actor's base-level 'send' operation dispatches to its meta-level 'send' operation. In effect, the semantics of an object sending an async message are the same as those of an actor sending an async message directly. TODO(discuss) is this the desirable semantics for the base-level hook?

Specified by:
base_send in interface ATActorMirror
Throws:
InterpreterException

base_install_

public ATObject base_install_(ATClosure code)
                       throws InterpreterException
def install: { code }

Specified by:
base_install_ in interface ATActorMirror
Parameters:
code - meta-level code that overrides an actor's MOP methods
Returns:
a protocol object that allows to uninstall the MOP code
Throws:
InterpreterException
See Also:
Technically, this MOP installation is achieved by performing an imperative mixin operation on the actor's mirror.

base_asActorMirror

public ATActorMirror base_asActorMirror()
                                 throws XTypeMismatch
Specified by:
base_asActorMirror in interface ATConversions
Overrides:
base_asActorMirror in class NATNil
Throws:
XTypeMismatch