Distributed Systems Project 2023-2024
A distributed room booking and reservation system implementing a MapReduce-like architecture with Master-Worker-Reducer pattern.
This project implements a distributed system for managing room bookings, reservations, and reviews. The system uses a Master-Worker-Reducer architecture where:
- Master coordinates client requests and distributes work to workers
- Workers process room data and perform filtering operations
- Reducer aggregates results from multiple workers
- Clients interact with the system through Manager and Tenant applications
- Port: 8080
- Responsibilities:
- Accepts client connections (Manager and Tenant)
- Distributes tasks to workers
- Routes results from reducer back to clients
- Manages connection pool for multiple client sessions
- Key Classes:
Master.java: Main server that connects to workers and accepts clientsMasterThread.java: Handles individual client connectionsMasterConnectionsPool.java: Manages active client connections
- Ports: 4040, 4041, 4042 (configurable, 3 workers by default)
- Responsibilities:
- Store and manage room data (distributed by room name hash)
- Process filter queries
- Handle room reservations
- Update room availability dates
- Process reviews and update ratings
- Key Classes:
Worker.java: Main worker serverWorkerThread.java: Handles master-worker communication
- Port: 2020
- Responsibilities:
- Aggregates results from all workers
- Ensures complete result sets before sending to master
- Manages result pools for different queries
- Key Classes:
Reducer.java: Main reducer serverRoomResultsPool.java: Manages result aggregationRoomResults.java: Stores aggregated room results
- Purpose: Room managers who own and manage rooms
- Features:
- Upload new rooms (from JSON file)
- Update available dates for rooms
- View all reservations for their rooms
- Purpose: Customers who search and book rooms
- Features:
- Search rooms with filters (area, dates, capacity, price, stars)
- Make room reservations
- Submit reviews for rooms
- Purpose: Mobile application for tenants
- Features:
- Search rooms with filters
- View search results
- Make reservations
- Key Activities:
MainActivity.java: Filter input and searchResultsActivity.java: Display results and booking
- Room Upload: Managers can upload rooms from JSON files. Rooms are distributed to workers based on room name hash.
- Date Updates: Managers can update available dates for their rooms.
- Reservation Viewing: Managers can view all reservations for their rooms.
- Filtered Search: Tenants can search rooms using multiple filters:
- Area
- Dates
- Number of persons
- Price
- Star rating
- Reservations: Tenants can book available rooms.
- Reviews: Tenants can submit reviews that update room ratings.
- Tenant sends filter request to Master
- Master assigns a mapId and broadcasts filters to all Workers
- Each Worker searches its local room data and sends matching rooms to Reducer
- Reducer aggregates results from all Workers
- When all Workers respond, Reducer sends complete results to Master
- Master routes results back to the requesting Tenant
- Tenant sends reservation request to Master
- Master broadcasts reservation to all Workers
- Workers update their local data (move room from available to reserved)
- Master confirms reservation to Tenant
- Backend: Java 8+
- Build Tool: Maven
- Dependencies:
json-simple(1.1.1): JSON parsing and creationjunit(4.11): Testing
- Mobile: Android (Java)
- Communication: Socket-based TCP/IP networking
- Data Format: JSON
DS-Project/
├── src/main/java/com/dsproject/
│ ├── client/ # Client applications (Manager, Tenant)
│ ├── common/ # Shared utilities (Connection, PacketFactory)
│ ├── master/ # Master server components
│ ├── reducer/ # Reducer server components
│ └── worker/ # Worker server components
├── dsandroid/ # Android mobile client
│ └── app/src/main/java/com/example/myapplication/
├── pom.xml # Maven configuration
├── run.sh # Interactive launcher script (macOS/Linux)
├── run.bat # Interactive launcher script (Windows)
└── file.json # Sample room data file
- Java 8 or higher (Java 7 is no longer supported)
- Maven 3.x
Installing Java:
On macOS:
# Using Homebrew
brew install openjdk@11
# Or install OpenJDK 17 (LTS)
brew install openjdk@17
# After installation, you may need to set JAVA_HOME
export JAVA_HOME=$(/usr/libexec/java_home -v 11) # or -v 17 for Java 17On Windows:
-
Download from Adoptium (Temurin OpenJDK)
-
Or use Chocolatey:
choco install openjdk11 -
Make sure Java is added to your PATH
-
Android Studio (for Android client)
The easiest way to run the system is using the interactive launcher script:
On macOS/Linux:
./run.shOn Windows:
run.batThe script provides an interactive menu to:
- Compile the project
- Start all components (Workers, Reducer, Master) at once
- Start individual components
- Run client applications (Manager or Tenant)
- Check component status
- Stop all components
Note for macOS/Linux: Make sure the script is executable. If not, run:
chmod +x run.sh-
Start Workers (3 instances):
cd src/main/java java com.dsproject.worker.Worker # Enter port: 4040 (for first worker) # Repeat for ports 4041 and 4042
-
Start Reducer:
java com.dsproject.reducer.Reducer
-
Start Master:
java com.dsproject.master.Master
-
Run Clients:
- Manager:
java com.dsproject.client.Manager
- Tenant:
java com.dsproject.client.Tenant
- Manager:
mvn clean compile
mvn package- Open
dsandroid/in Android Studio - Update the IP address in
MainActivity.java(line 34) to match your Master server IP - Build and run on Android device/emulator
- Number of Workers: Configured in
Master.java(NUM_WORKERS = 3) - Ports:
- Master: 8080
- Workers: 4040-4042 (configurable)
- Reducer: 2020
- Worker Port Assignment: Workers connect to Master on ports 4040 + worker index
Rooms are stored as JSON objects with the following structure:
{
"roomName": "roomName1",
"noOfPersons": 2,
"area": "Area1",
"stars": 4.5,
"noOfReviews": 152,
"roomImage": "/usr/bin/images/roomName1.png",
"roomDates": "1/2/2025 - 1/3/2025",
"roomId": 1,
"price": 100,
"managerId": 1
}All communication uses JSON packets with the following structure:
{
"command": "CommandName",
"payload": "JSON string or data"
}RoomUpload: Upload new room dataUpdateDates: Update room availability datesSeeAllReservations: Get all reservations for a managerFilters: Search rooms with filtersFiltersResults: Return filtered search resultsReservation: Make a room reservationReview: Submit a room review
- The system uses hash-based distribution: rooms are assigned to workers based on
roomName.hashCode() % NUM_WORKERS - Workers maintain separate lists for available and reserved rooms
- The reducer ensures all worker responses are received before sending complete results
- Each client connection is handled by a separate thread on the Master
- The Android client requires network permissions and must be configured with the correct Master server IP address
This project was created for educational purposes as part of a Distributed Systems course (2023-2024).