Package net.sodacan.core.scheduler
Class DefaultScheduler
java.lang.Object
java.lang.Thread
net.sodacan.core.scheduler.DefaultScheduler
- All Implemented Interfaces:
Closeable,AutoCloseable,Runnable,Scheduler
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsFields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionDefaultScheduler(Config config, ActorGroup actorGroup) Construct a default scheduler, one per ActorGroup -
Method Summary
Modifier and TypeMethodDescriptionvoidaddMessage(Jug jug) Add a message to the work queue.voidaddNewMessage(Jug jug) Add a new message to the work queue with backpressure.protected voidIf there's too many messages in-flight, we're going to wait for a bitvoidReactivate any actors with messages waiting.voidclose()voidHostBound Actors are always alive so just forward to the actorvoidvoidprotected booleanevict(ActorEntry ae) Decide if we're going to evict an ActorEntry and if so, do it.voidevictAll()These are live statistics.voidvoidvoidvoidvoidvoidvoidvoidprotected booleanSubjective check to see if messages are being processed.protected voidvoidrun()voidsetActiveThreadCount(int count) voidvoidsetCurrentJobQueue(int count) protected voidWhen an actorEntry says there are no more messages and thus has stopped, see if there's actually more work to do.toString()voidIn 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.Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, suspend, threadId, yield
-
Field Details
-
actorGroup
-
-
Constructor Details
-
DefaultScheduler
Construct a default scheduler, one per ActorGroup- Parameters:
config- Configuration used by this scheduler
-
-
Method Details
-
getStatistics
These are live statistics. You only need to call this method once. Calling individual methods will get you the current value.- Specified by:
getStatisticsin interfaceScheduler
-
getActorGroup
- Specified by:
getActorGroupin interfaceScheduler
-
addMessage
Add a message to the work queue. First time through starts the thread. Executes in caller thread, not scheduler- Specified by:
addMessagein interfaceScheduler- Parameters:
jug- The (Jug) message to be processed
-
addNewMessage
Add a new message to the work queue with backpressure.- Specified by:
addNewMessagein interfaceScheduler
-
applyBackpressure
protected void applyBackpressure()If there's too many messages in-flight, we're going to wait for a bit -
run
public void run() -
setActiveThreadCount
public void setActiveThreadCount(int count) - Specified by:
setActiveThreadCountin interfaceScheduler
-
normalMessage
-
auditMessageLoad
Reactivate any actors with messages waiting. -
errorMessage
-
closeHostBoundActor
HostBound Actors are always alive so just forward to the actor- Parameters:
chba-
-
evict
Decide if we're going to evict an ActorEntry and if so, do it.- Parameters:
ae-
-
stoppedActor
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:
waitForMessagesToFinishin interfaceScheduler
-
setClosing
public void setClosing()- Specified by:
setClosingin interfaceScheduler
-
close
public void close() -
getConfig
-
increaseMessageLoad
public void increaseMessageLoad()- Specified by:
increaseMessageLoadin interfaceScheduler
-
decreaseMessageLoad
public void decreaseMessageLoad()- Specified by:
decreaseMessageLoadin interfaceScheduler
-
incrementSleepTime
public void incrementSleepTime()- Specified by:
incrementSleepTimein interfaceScheduler
-
increaseMessageCount
public void increaseMessageCount()- Specified by:
increaseMessageCountin interfaceScheduler
-
increaseSaveCount
public void increaseSaveCount()- Specified by:
increaseSaveCountin interfaceScheduler
-
increaseRestoreCount
public void increaseRestoreCount()- Specified by:
increaseRestoreCountin interfaceScheduler
-
increaseErrorCount
public void increaseErrorCount()- Specified by:
increaseErrorCountin interfaceScheduler
-
incrementActorsRealized
public void incrementActorsRealized()- Specified by:
incrementActorsRealizedin interfaceScheduler
-
incrementActorsEvicted
public void incrementActorsEvicted()- Specified by:
incrementActorsEvictedin interfaceScheduler
-
setCurrentJobQueue
public void setCurrentJobQueue(int count) - Specified by:
setCurrentJobQueuein interfaceScheduler
-
evictAll
public void evictAll() -
toString
-