Class DefaultScheduler

java.lang.Object
java.lang.Thread
net.sodacan.core.scheduler.DefaultScheduler
All Implemented Interfaces:
Closeable, AutoCloseable, Runnable, Scheduler

public class DefaultScheduler extends Thread implements Scheduler, Closeable
  • Field Details

  • Constructor Details

    • DefaultScheduler

      public DefaultScheduler(Config config, ActorGroup actorGroup)
      Construct a default scheduler, one per ActorGroup
      Parameters:
      config - Configuration used by this scheduler
  • Method Details

    • getStatistics

      public Statistics getStatistics()
      These are live statistics. You only need to call this method once. Calling individual methods will get you the current value.
      Specified by:
      getStatistics in interface Scheduler
    • getActorGroup

      public ActorGroup getActorGroup()
      Specified by:
      getActorGroup in interface Scheduler
    • addMessage

      public void addMessage(Jug jug)
      Add a message to the work queue. First time through starts the thread. Executes in caller thread, not scheduler
      Specified by:
      addMessage in interface Scheduler
      Parameters:
      jug - The (Jug) message to be processed
    • addNewMessage

      public void addNewMessage(Jug jug)
      Add a new message to the work queue with backpressure.
      Specified by:
      addNewMessage in interface Scheduler
    • applyBackpressure

      protected void applyBackpressure()
      If there's too many messages in-flight, we're going to wait for a bit
    • run

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

      public void setActiveThreadCount(int count)
      Specified by:
      setActiveThreadCount in interface Scheduler
    • normalMessage

      protected void normalMessage(NormalMessage nm)
    • auditMessageLoad

      public void auditMessageLoad(AuditMessageLoad aml)
      Reactivate any actors with messages waiting.
    • errorMessage

      public void errorMessage(ErrorMessage em)
    • closeHostBoundActor

      public void closeHostBoundActor(CloseHostBoundActor chba)
      HostBound Actors are always alive so just forward to the actor
      Parameters:
      chba -
    • evict

      protected boolean evict(ActorEntry ae)
      Decide if we're going to evict an ActorEntry and if so, do it.
      Parameters:
      ae -
    • stoppedActor

      protected void stoppedActor(StoppedActor sa)
      When an actorEntry says there are no more messages and thus has stopped, see if there's actually more work to do. If so, start the thread back up. If not, consider removing the ActorEntry and Actor. By the time we get this message, the Actor should be fully passivated so that the Actor can be safely removed from memory.
      Parameters:
      sa - Sent from an actor that is done processing messages
    • livelinessCheck

      protected boolean livelinessCheck()

      Subjective check to see if messages are being processed.

      $$$$ NOTE: This check must be done inside scheduling thread
      Returns:
      true if appears messages are bing processed since last time we were called
    • waitForMessagesToFinish

      public void waitForMessagesToFinish()

      In production, this is where we wait for an ActorGroup to settle down so we can move the ActorGroup to another host or otherwise change it's state.

      In addition to waiting for message load to go to zero, we also do a rough check to see if any messages are getting processed and if not, something is wrong.

      Specified by:
      waitForMessagesToFinish in interface Scheduler
    • setClosing

      public void setClosing()
      Specified by:
      setClosing in interface Scheduler
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface Scheduler
    • getConfig

      public Config getConfig()
      Specified by:
      getConfig in interface Scheduler
    • increaseMessageLoad

      public void increaseMessageLoad()
      Specified by:
      increaseMessageLoad in interface Scheduler
    • decreaseMessageLoad

      public void decreaseMessageLoad()
      Specified by:
      decreaseMessageLoad in interface Scheduler
    • incrementSleepTime

      public void incrementSleepTime()
      Specified by:
      incrementSleepTime in interface Scheduler
    • increaseMessageCount

      public void increaseMessageCount()
      Specified by:
      increaseMessageCount in interface Scheduler
    • increaseSaveCount

      public void increaseSaveCount()
      Specified by:
      increaseSaveCount in interface Scheduler
    • increaseRestoreCount

      public void increaseRestoreCount()
      Specified by:
      increaseRestoreCount in interface Scheduler
    • increaseErrorCount

      public void increaseErrorCount()
      Specified by:
      increaseErrorCount in interface Scheduler
    • incrementActorsRealized

      public void incrementActorsRealized()
      Specified by:
      incrementActorsRealized in interface Scheduler
    • incrementActorsEvicted

      public void incrementActorsEvicted()
      Specified by:
      incrementActorsEvicted in interface Scheduler
    • setCurrentJobQueue

      public void setCurrentJobQueue(int count)
      Specified by:
      setCurrentJobQueue in interface Scheduler
    • evictAll

      public void evictAll()
      Specified by:
      evictAll in interface Scheduler
    • toString

      public String toString()
      Overrides:
      toString in class Thread