Package titan.scheduler
Class WorkerRegistry
java.lang.Object
titan.scheduler.WorkerRegistry
A central registry for managing
Worker instances within the Titan scheduler system.
This class provides mechanisms to add, retrieve, update, and remove workers,
facilitating the discovery and management of available processing capabilities.
It uses a ConcurrentHashMap to ensure thread-safe operations.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a newWorkerRegistryand initializes the internal worker map. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a new worker to the registry or updates an existing worker's capabilities and permanence status.private StringgenerateKey(String host, int port) A private helper method to generate a consistent key for a worker.getWorkerKey(String host, int port) Generates a unique key for a worker based on its host and port.Returns the underlying map of workers.Retrieves a collection of all currently registered workers.getWorkersByCapability(String requiredSkill) Retrieves a list of workers that possess a specific capability.voidmarkWorkerDead(String host, int port) Marks a worker as dead by removing it from the registry.private voidremoveWorker(String host, int port) A private helper method to remove a worker from the registry based on its host and port.voidupdateLastSeen(String host, int port) Updates the 'last seen' timestamp for a specific worker.
-
Field Details
-
workerMap
A thread-safe map storingWorkerinstances, keyed by a unique string generated from the worker's host and port (e.g., "host:port").
-
-
Constructor Details
-
WorkerRegistry
public WorkerRegistry()Constructs a newWorkerRegistryand initializes the internal worker map.
-
-
Method Details
-
getWorkerMap
Returns the underlying map of workers. This map is a live view of the registry's state. Modifications to the returned map will directly affect the registry. -
getWorkerKey
Generates a unique key for a worker based on its host and port. This key is used internally to identify workers in the registry.- Parameters:
host- The hostname or IP address of the worker.port- The port number the worker is listening on.- Returns:
- A string representing the unique key for the worker (e.g., "localhost:8080").
-
addWorker
Adds a new worker to the registry or updates an existing worker's capabilities and permanence status. If a worker with the given host and port already exists, its capabilities list will be updated to include the new capability if it's not already present. The `isPermanent` status will be set to true if the worker was previously marked permanent, ensuring permanence is sticky.- Parameters:
host- The hostname or IP address of the worker.port- The port number the worker is listening on.capability- A specific skill or capability that the worker possesses.isPermanent-trueif the worker should be considered permanent and not removed by cleanup processes;falseotherwise. Once a worker is marked permanent, it remains permanent.
-
getWorkers
Retrieves a collection of all currently registered workers.- Returns:
- A
CollectionofWorkerobjects currently in the registry.
-
generateKey
A private helper method to generate a consistent key for a worker.- Parameters:
host- The hostname or IP address of the worker.port- The port number the worker is listening on.- Returns:
- A string key in the format "host:port".
-
updateLastSeen
Updates the 'last seen' timestamp for a specific worker. This method is typically called when a heartbeat or check-in is received from a worker, indicating it is still active.- Parameters:
host- The hostname or IP address of the worker.port- The port number the worker is listening on.
-
markWorkerDead
Marks a worker as dead by removing it from the registry. This method effectively removes the worker entry, making it unavailable for task assignment.- Parameters:
host- The hostname or IP address of the worker to mark as dead.port- The port number of the worker to mark as dead.
-
getWorkersByCapability
Retrieves a list of workers that possess a specific capability. -
removeWorker
A private helper method to remove a worker from the registry based on its host and port.- Parameters:
host- The hostname or IP address of the worker to remove.port- The port number of the worker to remove.
-