Package titan.scheduler
Class Worker
java.lang.Object
titan.scheduler.Worker
Represents a worker node in the scheduling system. A worker has a host, port, and a set of capabilities.
It maintains its current load, maximum capacity, and last seen timestamp to facilitate job assignment
and resource management. Workers can be permanent or temporary.
-
Field Summary
FieldsModifier and TypeFieldDescriptionA list of capabilities or features supported by this worker.The ID of the job currently assigned to this worker, if any.private intThe current number of jobs or tasks actively being processed by this worker.private final StringThe hostname or IP address of the worker.private longThe timestamp (in milliseconds) when the worker became idle (currentLoad dropped to 0).private booleanIndicates whether this worker is a permanent part of the cluster or a temporary, dynamically provisioned worker.private longThe timestamp (in milliseconds) when this worker was last seen or updated.static final intThe maximum number of concurrent job slots available on any worker.private intThe maximum number of jobs or tasks this worker can handle concurrently.private final intThe port number on which the worker is listening. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns an unmodifiable list of capabilities supported by this worker.voidDecrements the current load of the worker by one, if the load is greater than zero.intReturns the current load of the worker.longCalculates and returns the duration (in milliseconds) for which the worker has been idle.intReturns the maximum capacity of the worker.host()Returns the hostname or IP address of the worker.voidIncrements the current load of the worker by one.booleanChecks if this worker is designated as a permanent worker.booleanChecks if the worker is saturated, meaning its current load has reached or exceeded its maximum capacity.longlastSeen()Returns the timestamp (in milliseconds) when this worker was last seen or updated.intport()Returns the port number on which the worker is listening.voidsetCurrentLoad(int load) Sets the current load of the worker.voidsetMaxCap(int maxCap) Sets the maximum capacity of the worker.toString()Returns a string representation of the Worker, including its host, port, and current load.voidUpdates thelastSeentimestamp to the current system time.
-
Field Details
-
host
The hostname or IP address of the worker. -
port
private final int portThe port number on which the worker is listening. -
capabilities
A list of capabilities or features supported by this worker. These capabilities can be used by the scheduler to match jobs to suitable workers. -
lastSeen
private long lastSeenThe timestamp (in milliseconds) when this worker was last seen or updated. Used for liveness checks and identifying stale workers. -
currentLoad
private int currentLoadThe current number of jobs or tasks actively being processed by this worker. -
maxCap
private int maxCapThe maximum number of jobs or tasks this worker can handle concurrently. This field will eventually be replaced byMAX_SLOTS. -
currentJobId
The ID of the job currently assigned to this worker, if any. This field is public for direct access by the scheduler. -
MAX_SLOTS
public static final int MAX_SLOTSThe maximum number of concurrent job slots available on any worker. This is a static constant representing the default or system-wide maximum capacity. This will replace the instance-specificmaxCapfield.- See Also:
-
idleStartTime
private long idleStartTimeThe timestamp (in milliseconds) when the worker became idle (currentLoad dropped to 0). A value of -1 indicates the worker is currently busy. -
isPermanent
private boolean isPermanentIndicates whether this worker is a permanent part of the cluster or a temporary, dynamically provisioned worker. Permanent workers might have different lifecycle management.
-
-
Constructor Details
-
Worker
Constructs a new Worker instance. Initializes the worker with its network details, capabilities, and sets its initial state.- Parameters:
host- The hostname or IP address of the worker.port- The port number on which the worker is listening.capabilities- A list of capabilities supported by this worker. Can be null, in which case an empty list is used.isPermanent- True if this worker is a permanent part of the cluster, false otherwise.
-
-
Method Details
-
updateLastSeen
public void updateLastSeen()Updates thelastSeentimestamp to the current system time. This method is synchronized to ensure thread-safe updates to the worker's liveness status. -
isPermanent
public boolean isPermanent()Checks if this worker is designated as a permanent worker.- Returns:
trueif the worker is permanent,falseotherwise.
-
setCurrentLoad
public void setCurrentLoad(int load) Sets the current load of the worker. If the load becomes 0, it records theidleStartTime. If the load is greater than 0, it resetsidleStartTimeto -1. This method is synchronized to ensure thread-safe updates to the worker's load and idle state.- Parameters:
load- The new current load value. Must be non-negative.
-
setMaxCap
public void setMaxCap(int maxCap) Sets the maximum capacity of the worker. This method is synchronized to ensure thread-safe updates to the worker's capacity.- Parameters:
maxCap- The new maximum capacity value.
-
getMaxCap
public int getMaxCap()Returns the maximum capacity of the worker. This method is synchronized to ensure thread-safe access to the worker's capacity.- Returns:
- The maximum number of jobs or tasks this worker can handle concurrently.
-
getIdleDuration
public long getIdleDuration()Calculates and returns the duration (in milliseconds) for which the worker has been idle. If the worker is currently busy (idleStartTimeis -1), it returns 0.- Returns:
- The idle duration in milliseconds, or 0 if the worker is currently busy.
-
getCurrentLoad
public int getCurrentLoad()Returns the current load of the worker. This method is synchronized to ensure thread-safe access to the worker's load.- Returns:
- The current number of jobs or tasks actively being processed.
-
incrementCurrentLoad
public void incrementCurrentLoad()Increments the current load of the worker by one. Resets theidleStartTimeif it was previously set, as the worker is now busy. This method is synchronized to ensure thread-safe load updates. -
decrementCurrentLoad
public void decrementCurrentLoad()Decrements the current load of the worker by one, if the load is greater than zero. If the load drops to zero after decrementing, it records theidleStartTime. This method is synchronized to ensure thread-safe load updates and idle state management. -
isSaturated
public boolean isSaturated()Checks if the worker is saturated, meaning its current load has reached or exceeded its maximum capacity. This method is synchronized to ensure thread-safe access to load and capacity.- Returns:
trueif the worker is saturated,falseotherwise.
-
host
Returns the hostname or IP address of the worker. This is a record-style accessor for thehostfield.- Returns:
- The host string.
-
port
public int port()Returns the port number on which the worker is listening. This is a record-style accessor for theportfield.- Returns:
- The port number.
-
lastSeen
public long lastSeen()Returns the timestamp (in milliseconds) when this worker was last seen or updated. This is a record-style accessor for thelastSeenfield.- Returns:
- The last seen timestamp.
-
capabilities
Returns an unmodifiable list of capabilities supported by this worker. This is a record-style accessor for thecapabilitiesfield.- Returns:
- An unmodifiable list of capabilities.
-
toString
Returns a string representation of the Worker, including its host, port, and current load.
-