Package net.sodacan.core.actor
Class ActorEntry
java.lang.Object
java.lang.Thread
net.sodacan.core.actor.ActorEntry
- All Implemented Interfaces:
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Actorprotected ActorIdprotected Configprotected booleanprotected Schedulerprotected Serializerprotected longFields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionActorEntry(Config config, Scheduler scheduler, ActorId actorId) Construct a new ActorEntry and instantiate and actor contained within it using a configured actor factory. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanOnce this actor is closed, we can countdown to allow the ActorGroup to closeprotected booleanfloatAn actor is subject to eviction at any time.intlonggetUsage()protected voidprotected booleanlinger()If return true, then try to grab a new message, otherwise, get outprotected booleanvoidqueueMessage(Jug jug) Callable from any thread to add a message to this queue.voidrun()voidKick off the thread if its not runningvoidtoString()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
-
actorId
-
actor
-
scheduler
-
config
-
usage
protected long usage -
evicting
protected boolean evicting -
serializer
-
-
Constructor Details
-
ActorEntry
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
-
getUsage
public long getUsage() -
startThread
Kick off the thread if its not running -
stopThread
public void stopThread() -
queueMessage
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
- Throws:
Exception
-
linger
If return true, then try to grab a new message, otherwise, get out- Returns:
- Throws:
InterruptedException
-
run
public void run() -
emptyQueue
protected boolean emptyQueue()- Returns:
-
closeHostBoundActor
Once this actor is closed, we can countdown to allow the ActorGroup to close- Parameters:
chba-- Returns:
-
normalMessage
-
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
-