Skip to content

Latest commit

 

History

41 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DS-Project

Distributed Systems Project 2023-2024

A distributed room booking and reservation system implementing a MapReduce-like architecture with Master-Worker-Reducer pattern.

Overview

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

Architecture

Components

1. Master (com.dsproject.master)

  • 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 clients
    • MasterThread.java: Handles individual client connections
    • MasterConnectionsPool.java: Manages active client connections

2. Workers (com.dsproject.worker)

  • 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 server
    • WorkerThread.java: Handles master-worker communication

3. Reducer (com.dsproject.reducer)

  • 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 server
    • RoomResultsPool.java: Manages result aggregation
    • RoomResults.java: Stores aggregated room results

4. Clients

Manager (com.dsproject.client.Manager)
  • Purpose: Room managers who own and manage rooms
  • Features:
    1. Upload new rooms (from JSON file)
    2. Update available dates for rooms
    3. View all reservations for their rooms
Tenant (com.dsproject.client.Tenant)
  • Purpose: Customers who search and book rooms
  • Features:
    1. Search rooms with filters (area, dates, capacity, price, stars)
    2. Make room reservations
    3. Submit reviews for rooms

5. Android Client (dsandroid/)

  • Purpose: Mobile application for tenants
  • Features:
    • Search rooms with filters
    • View search results
    • Make reservations
  • Key Activities:
    • MainActivity.java: Filter input and search
    • ResultsActivity.java: Display results and booking

Features

Room Management

  • 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.

Room Search & Booking

  • 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.

Data Flow

Search Flow (MapReduce Pattern)

  1. Tenant sends filter request to Master
  2. Master assigns a mapId and broadcasts filters to all Workers
  3. Each Worker searches its local room data and sends matching rooms to Reducer
  4. Reducer aggregates results from all Workers
  5. When all Workers respond, Reducer sends complete results to Master
  6. Master routes results back to the requesting Tenant

Reservation Flow

  1. Tenant sends reservation request to Master
  2. Master broadcasts reservation to all Workers
  3. Workers update their local data (move room from available to reserved)
  4. Master confirms reservation to Tenant

Technology Stack

  • Backend: Java 8+
  • Build Tool: Maven
  • Dependencies:
    • json-simple (1.1.1): JSON parsing and creation
    • junit (4.11): Testing
  • Mobile: Android (Java)
  • Communication: Socket-based TCP/IP networking
  • Data Format: JSON

Project Structure

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

Setup Instructions

Prerequisites

  • 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 17

On 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)

Quick Start (Recommended)

The easiest way to run the system is using the interactive launcher script:

On macOS/Linux:

./run.sh

On Windows:

run.bat

The 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

Manual Running (Alternative)

  1. 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
  2. Start Reducer:

    java com.dsproject.reducer.Reducer
  3. Start Master:

    java com.dsproject.master.Master
  4. Run Clients:

    • Manager:
      java com.dsproject.client.Manager
    • Tenant:
      java com.dsproject.client.Tenant

Building with Maven

mvn clean compile
mvn package

Android Client Setup

  1. Open dsandroid/ in Android Studio
  2. Update the IP address in MainActivity.java (line 34) to match your Master server IP
  3. Build and run on Android device/emulator

Configuration

  • 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

Sample Data Format

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
}

Communication Protocol

All communication uses JSON packets with the following structure:

{
    "command": "CommandName",
    "payload": "JSON string or data"
}

Supported Commands

  • RoomUpload: Upload new room data
  • UpdateDates: Update room availability dates
  • SeeAllReservations: Get all reservations for a manager
  • Filters: Search rooms with filters
  • FiltersResults: Return filtered search results
  • Reservation: Make a room reservation
  • Review: Submit a room review

Notes

  • 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

License

This project was created for educational purposes as part of a Distributed Systems course (2023-2024).

About

Κατανεμημένα Συστήματα Εγρασία 2023-2024

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages