Class ActorEntry

java.lang.Object
java.lang.Thread
net.sodacan.core.actor.ActorEntry
All Implemented Interfaces:
Runnable

public class ActorEntry extends Thread implements Runnable

The scheduler for a actorGroup manages a map of ActorEntries. Each entry wraps a single actor instance. This entry is what contains the "Runnable" entity for purposes of executing the actor's processMessage method as messages arrive.

  • Field Details

    • actorId

      protected ActorId actorId
    • actor

      protected Actor actor
    • scheduler

      protected Scheduler scheduler
    • config

      protected Config config
    • usage

      protected long usage
    • evicting

      protected boolean evicting
    • serializer

      protected Serializer serializer
  • Constructor Details

    • ActorEntry

      public ActorEntry(Config config, Scheduler scheduler, ActorId actorId)

      Construct a new ActorEntry and instantiate and actor contained within it using a configured actor factory. The only thing an actor "knows" after creation is its ActorId. Additional saved state will arrive shortly after creation, if needed. This is necessary to maintain the spirit of the actor model in Sodacan.

      Parameters:
      config -
      scheduler -
      actorId -
  • Method Details

    • getActorId

      public ActorId getActorId()
    • getUsage

      public long getUsage()
    • startThread

      public void startThread(ThreadPoolExecutor pool)
      Kick off the thread if its not running
    • stopThread

      public void stopThread()
    • queueMessage

      public void queueMessage(Jug jug)
      Callable from any thread to add a message to this queue. Usually called from the scheduler. This queue has no limits. Rather, the message load is used to stall new messages before they get to this point.
      Parameters:
      jug - The Jug (message) to be queued
    • initialize

      protected void initialize() throws Exception
      Throws:
      Exception
    • linger

      protected boolean linger() throws InterruptedException
      If return true, then try to grab a new message, otherwise, get out
      Returns:
      Throws:
      InterruptedException
    • run

      public void run()
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • emptyQueue

      protected boolean emptyQueue()
      Returns:
    • closeHostBoundActor

      protected boolean closeHostBoundActor(CloseHostBoundActor chba)
      Once this actor is closed, we can countdown to allow the ActorGroup to close
      Parameters:
      chba -
      Returns:
    • normalMessage

      protected boolean normalMessage(NormalMessage nm)
    • getQueueSize

      public int getQueueSize()
    • evictionProbability

      public float evictionProbability()
      An actor is subject to eviction at any time. However, the lower this value, the less likely is will be chosen for eviction.
    • toString

      public String toString()
      Overrides:
      toString in class Thread