Class AbstractHost

java.lang.Object
net.sodacan.core.host.AbstractHost
All Implemented Interfaces:
Closeable, AutoCloseable, Host
Direct Known Subclasses:
DefaultHost

public abstract class AbstractHost extends Object implements Host

A host starts out by hosting no actorGroups. The coordinator will tell the host when it should:

  • Add a numbered actorGroup (the host will actually construct the actorGroup).
  • Tell a actorGroup to stop processing messages. This process can take time.
  • Tell a actorGroup to start processing messages. At this point, the actorGroup will create a scheduler and be open to accepting new messages.

The coordinator is not involved in message delivery, only to specify what each host should do actorGroup-wise.

All in-flight messages pass through the host where the actorGroup id of the target is determined and if the actorGroup is active on this host, it will e forwarded, without intermediate queuing, to the actorGroup which will then add it to the message queue of the target actor. If on the other hand, the host is not hosting the target actorGroup, the message will be queued to a special static actorGroup and then to a special actor that will deal with communication to the host where that target actor is "running".

The only thing special about a special actorGroup is that it is locked to the host that created it. In other words, a special actorGroup is only special to the host. The special actorGroup is always active. The special actors are only special in that their purpose is to relay a message to another remote host. The special actorGroup will have one actor for each host in the network. These actors are also used for sending actor replicas.

  • Field Details

  • Constructor Details

    • AbstractHost

      public AbstractHost(Config config)
  • Method Details

    • getConfig

      public Config getConfig()
      Specified by:
      getConfig in interface Host
    • getHostNumber

      public int getHostNumber()
      Specified by:
      getHostNumber in interface Host
    • getActorGroupStatistics

      public Map<Integer,Statistics> getActorGroupStatistics()
      Description copied from interface: Host
      Get stats for all active actorGroups
      Specified by:
      getActorGroupStatistics in interface Host
    • getStatisticsFor

      public Statistics getStatisticsFor(ActorId actorId)
      Specified by:
      getStatisticsFor in interface Host
    • isInitialized

      public boolean isInitialized()
    • getCoordinator

      public Coordinator getCoordinator()
      Specified by:
      getCoordinator in interface Host
    • setInitialized

      public void setInitialized(boolean initialized)
    • update

      public void update()
      Get the updated configuration from coordinator and add/remove actor groups as needed.
      Specified by:
      update in interface Host
    • getHostEntries

      public Set<HostEntry> getHostEntries()
      Specified by:
      getHostEntries in interface Host
    • getActorGroup

      public ActorGroup getActorGroup(HostEntry hostEntry)
      Specified by:
      getActorGroup in interface Host
    • getActorGroups

      public Set<ActorGroup> getActorGroups()
      Specified by:
      getActorGroups in interface Host
    • close

      public void close() throws IOException
      Close the host by closing the ActorGroups. ActorGroup < 0 precedes normal actor groups.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface Host
      Throws:
      IOException
    • replicate

      protected void replicate(int host, NormalMessage nm)
    • forwardToHost

      protected void forwardToHost(int hostNumber, NormalMessage nm)
      Figure our where the host is and send this message there
      Parameters:
      hostNumber -
      nm - A normal message
    • send

      public boolean send(Jug jug)
      Send this message to live actor and also copy it to other specified host(s)
      Specified by:
      send in interface Host
    • sendNormalMessage

      protected boolean sendNormalMessage(NormalMessage nm)
    • waitForMessagesToFinish

      public void waitForMessagesToFinish()
      This method is only useful for testing when it is expected that the message load will drop to zero.
      Specified by:
      waitForMessagesToFinish in interface Host