edu.vub.at.actors.natives
Class ELVirtualMachine

java.lang.Object
  extended byedu.vub.at.actors.eventloops.EventLoop
      extended byedu.vub.at.actors.natives.ELVirtualMachine
All Implemented Interfaces:
DiscoveryListener, org.jgroups.blocks.RequestHandler

public final class ELVirtualMachine
extends EventLoop
implements org.jgroups.blocks.RequestHandler, DiscoveryListener

A ELVirtualMachine represents a virtual machine which hosts several actors. The virtual machine is in charge of creating connections with other virtual machines and orchestrates the broadcasting of its presence, the exchange of service descriptions and messages. It also contains a set of runtime parameters (such as the objectpath and initfile) which are needed to initialise a new actor. TODO: use pure JChannel to send pure async messages rather than using a MessageDispatcher? Or use dispatcher only for message transmission. TODO: urgently clean up the vm address book: race conditions exist wher ELFarRefs query the address book when there is no entry for the remote VM's address

Author:
tvcutsem, smostinc

Nested Class Summary
 
Nested classes inherited from class edu.vub.at.actors.eventloops.EventLoop
EventLoop.EventProcessor
 
Field Summary
private static java.lang.String _GROUP_NAME_
          the name of the multicast group joined by all AmbientTalk VMs
 ELDiscoveryActor discoveryActor_
           
private  ATAbstractGrammar initialisationCode_
          startup parameter to the VM: the code of the init.at file to use
private  java.util.Hashtable localActors_
          a table mapping actor IDs to local native actors (int -> ELActor)
 MembershipNotifier membershipNotifier_
          the JGroups discovery bus for this Virtual Machine
 org.jgroups.blocks.MessageDispatcher messageDispatcher_
          the JGroups communication bus for this Virtual Machine
private  SharedActorField[] sharedFields_
          startup parameter to the VM: the list of fields to be initialized in every hosted actor
private  org.jgroups.Address vmAddress_
          the JGroups Address of the VM
 VMAddressBook vmAddressBook_
          A table mapping VM GUIDs to Address objects.
private  GUID vmId_
          the GUID of this VM
 
Fields inherited from class edu.vub.at.actors.eventloops.EventLoop
eventQueue_, processor_
 
Constructor Summary
ELVirtualMachine(ATAbstractGrammar initCode, SharedActorField[] fields)
           
 
Method Summary
static ELVirtualMachine currentVM()
           
 void event_actorCreated(ELActor actor)
          Event that signals the creation of a new actor on this virtual machine.
 void event_goOffline()
          Signals that this VM must disconnect from the underlying network channel
 void event_goOnline()
          Signals that this VM can connect to the underlying network channel and can start distributed interaction.
 void event_memberJoined(org.jgroups.Address remoteVMAddress)
          Notifies the discovery manager that a VM has joined the network.
 void event_memberLeft(org.jgroups.Address virtualMachine)
           
 ELActor getActor(int id)
           
 SharedActorField[] getFieldsToInitialize()
           
 GUID getGUID()
           
 ELVirtualMachine getHost()
           
 ATAbstractGrammar getInitialisationCode()
           
 org.jgroups.Address getLocalVMAddress()
           
 void handle(Event event)
          An event loop handles events by dispatching to the event itself.
 java.lang.Object handle(org.jgroups.Message message)
           
private  void initializeNetwork()
           
 void memberJoined(org.jgroups.Address virtualMachine)
           
 void memberLeft(org.jgroups.Address virtualMachine)
           
 
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

_GROUP_NAME_

private static final java.lang.String _GROUP_NAME_
the name of the multicast group joined by all AmbientTalk VMs

See Also:
Constant Field Values

initialisationCode_

private final ATAbstractGrammar initialisationCode_
startup parameter to the VM: the code of the init.at file to use


sharedFields_

private final SharedActorField[] sharedFields_
startup parameter to the VM: the list of fields to be initialized in every hosted actor


vmId_

private final GUID vmId_
the GUID of this VM


vmAddress_

private org.jgroups.Address vmAddress_
the JGroups Address of the VM


vmAddressBook_

public final VMAddressBook vmAddressBook_
A table mapping VM GUIDs to Address objects. Each time a VM connects, it sends its GUID and an entry mapping that GUID to its current Address is registered in this table. When a remote reference needs to send a message to the remote object, the VM is contacted based on its GUID and this table. When a VM disconnects, the disconnecting address is removed from this table.


localActors_

private final java.util.Hashtable localActors_
a table mapping actor IDs to local native actors (int -> ELActor)


messageDispatcher_

public org.jgroups.blocks.MessageDispatcher messageDispatcher_
the JGroups communication bus for this Virtual Machine


membershipNotifier_

public MembershipNotifier membershipNotifier_
the JGroups discovery bus for this Virtual Machine


discoveryActor_

public final ELDiscoveryActor discoveryActor_
Constructor Detail

ELVirtualMachine

public ELVirtualMachine(ATAbstractGrammar initCode,
                        SharedActorField[] fields)
Method Detail

currentVM

public static final ELVirtualMachine currentVM()

getGUID

public GUID getGUID()

getInitialisationCode

public ATAbstractGrammar getInitialisationCode()

getFieldsToInitialize

public SharedActorField[] getFieldsToInitialize()

getHost

public ELVirtualMachine getHost()

handle

public void handle(Event event)
An event loop handles events by dispatching to the event itself. Not to be confused with this class' handle(Message) method, which enables the VM event loop to handle incoming JGroups Messages!

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

getActor

public ELActor getActor(int id)

getLocalVMAddress

public org.jgroups.Address getLocalVMAddress()

memberJoined

public void memberJoined(org.jgroups.Address virtualMachine)
Specified by:
memberJoined in interface DiscoveryListener

memberLeft

public void memberLeft(org.jgroups.Address virtualMachine)
Specified by:
memberLeft in interface DiscoveryListener

event_goOnline

public void event_goOnline()
Signals that this VM can connect to the underlying network channel and can start distributed interaction.


event_goOffline

public void event_goOffline()
Signals that this VM must disconnect from the underlying network channel


event_memberJoined

public void event_memberJoined(org.jgroups.Address remoteVMAddress)
Notifies the discovery manager that a VM has joined the network. This VM may be a first-time participant or it may be a previously disconnected VM that has become reconnected. The VM asks the newly joined VM whether it has any services that match the type of an outstanding subscription on this VM.


event_memberLeft

public void event_memberLeft(org.jgroups.Address virtualMachine)

event_actorCreated

public void event_actorCreated(ELActor actor)
Event that signals the creation of a new actor on this virtual machine.


handle

public java.lang.Object handle(org.jgroups.Message message)
Specified by:
handle in interface org.jgroups.blocks.RequestHandler

initializeNetwork

private void initializeNetwork()