A distributed Master–Worker system that analyzes numbers in parallel using Java RMI.
The Master splits a numeric range into smaller tasks and submits them to a shared Task Bag (an RMI remote object). Multiple Worker processes connect to the Task Bag, pick up tasks, compute results, and send their findings back. The Master then aggregates all results and prints the final list of numbers.
Currently supported categories:
- Prime numbers
- Even numbers
- Odd numbers
- Natural numbers
- Master–Worker architecture using Java RMI
- Shared Task Bag implemented as a remote object
- Parallel processing with multiple Worker processes
- Configurable:
MAX– upper bound of the number rangeGRANULARITY– batch sizeCATEGORY– PRIME / EVEN / ODD / NATURAL
- Thread-safe task queue and result storage
Components
NumberCategory– enum defining the type of numbers to collectNumberTask– serializable task describing a numeric range and categoryTaskBag– RMI remote interface that exposes operations for:- Submitting tasks
- Taking tasks
- Submitting results
- Reading aggregated results
TaskBagImpl– implementation ofTaskBag, running as an RMI serverMaster– CLI process that:- Reads user input (MAX, GRANULARITY, CATEGORY)
- Splits the range into tasks
- Submits tasks to the TaskBag
- Waits for completion and prints final results
Worker– CLI process that:- Repeatedly takes one task from the TaskBag
- Processes the numbers in its range
- Sends back the filtered numbers (based on category)
- Exits once no tasks remain
Data flow
- Master asks the user for
MAX,GRANULARITY, and desiredCATEGORY. - Master creates
NumberTaskobjects for ranges like[0..9],[10..19], etc., and callssubmitTask(...)on the TaskBag. - Each Worker calls
takeTask():- If a task exists, it processes that range and calls
submitResult(...). - If no tasks remain, the Worker exits.
- If a task exists, it processes that range and calls
- Master periodically checks
getCompletedTasks()vsgetTotalTasks(). - Once all tasks are done (or timeout reached), Master calls
getResults(category)and prints the combined list.
Requirements:
- Java 8+
javacandjavaavailable on your PATH
From the project root:
javac -d bin src/com/elvis/numberanalyzer/*.java