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 TypeMethodDescriptionvoid
addMessage
(Jug jug) Add a message to the work queue.void
addNewMessage
(Jug jug) Add a new message to the work queue with backpressure.protected void
If there's too many messages in-flight, we're going to wait for a bitvoid
Reactivate any actors with messages waiting.void
close()
void
HostBound Actors are always alive so just forward to the actorvoid
void
protected boolean
evict
(ActorEntry ae) Decide if we're going to evict an ActorEntry and if so, do it.void
evictAll()
These are live statistics.void
void
void
void
void
void
void
void
protected boolean
Subjective check to see if messages are being processed.protected void
void
run()
void
setActiveThreadCount
(int count) void
void
setCurrentJobQueue
(int count) protected void
When an actorEntry says there are no more messages and thus has stopped, see if there's actually more work to do.toString()
void
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.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:
getStatistics
in interfaceScheduler
-
getActorGroup
- Specified by:
getActorGroup
in interfaceScheduler
-
addMessage
Add a message to the work queue. First time through starts the thread. Executes in caller thread, not scheduler- Specified by:
addMessage
in interfaceScheduler
- Parameters:
jug
- The (Jug) message to be processed
-
addNewMessage
Add a new message to the work queue with backpressure.- Specified by:
addNewMessage
in 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:
setActiveThreadCount
in 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:
waitForMessagesToFinish
in interfaceScheduler
-
setClosing
public void setClosing()- Specified by:
setClosing
in interfaceScheduler
-
close
public void close() -
getConfig
-
increaseMessageLoad
public void increaseMessageLoad()- Specified by:
increaseMessageLoad
in interfaceScheduler
-
decreaseMessageLoad
public void decreaseMessageLoad()- Specified by:
decreaseMessageLoad
in interfaceScheduler
-
incrementSleepTime
public void incrementSleepTime()- Specified by:
incrementSleepTime
in interfaceScheduler
-
increaseMessageCount
public void increaseMessageCount()- Specified by:
increaseMessageCount
in interfaceScheduler
-
increaseSaveCount
public void increaseSaveCount()- Specified by:
increaseSaveCount
in interfaceScheduler
-
increaseRestoreCount
public void increaseRestoreCount()- Specified by:
increaseRestoreCount
in interfaceScheduler
-
increaseErrorCount
public void increaseErrorCount()- Specified by:
increaseErrorCount
in interfaceScheduler
-
incrementActorsRealized
public void incrementActorsRealized()- Specified by:
incrementActorsRealized
in interfaceScheduler
-
incrementActorsEvicted
public void incrementActorsEvicted()- Specified by:
incrementActorsEvicted
in interfaceScheduler
-
setCurrentJobQueue
public void setCurrentJobQueue(int count) - Specified by:
setCurrentJobQueue
in interfaceScheduler
-
evictAll
public void evictAll() -
toString
-