ABOUT THIS MODULE: This repository contains Module 2 of the Distributed Systems (SDIS) course project. It elevates the architecture from Module 1 by implementing a complex, multithreaded server simulating a Spotify-like playlist manager. Instead of raw text, this module utilizes Java Object Serialization to transmit immutable
ProtocolMessagestructures safely across the network.
Building upon the anti-brute force mechanisms of Module 1, this module introduces advanced thread-safe state management:
- Custom Binary Protocol: Network communication is strictly typed using a custom
ProtocolMessageDTO and aProtocolPrimitiveEnum, ensuring predictable parsing. - Stateful Sessions: The server maintains an
isAuthenticatedstate per client handler, rejecting protected commands (ADD2L,DELETEL) via HTTP-like401and403logical errors if not logged in. - Thread-Safe Generic
ConcurrentMultiMap: * Implements a non-blocking mapConcurrentMap<K, ConcurrentLinkedQueue<T>>.- Allows hundreds of concurrent clients to add (
push) and read (pop) songs from playlists atomically without locking the entire map.
- Allows hundreds of concurrent clients to add (
- Deadlock Prevention: Safe initialization of
ObjectOutputStreamusingflush()beforeObjectInputStreaminstantiation, avoiding the classic Java Sockets blocking deadlock.
src/sdis/spotify/
┣ 📂 common
┃ ┣ 📜 ProtocolPrimitive.java # Protocol Commands (XAUTH, ADD2L...)
┃ ┣ 📜 ProtocolMessage.java # Immutable Serializable DTO
┃ ┗ 📜 ServerMessages.java # Centralized string constants
┣ 📂 utils
┃ ┣ 📜 ConnectionManager.java # Rate-limiting and Brute-Force protection
┃ ┗ 📜 ConcurrentMultiMap.java # Thread-Safe generic Queue mapping
┣ 📂 server
┃ ┣ 📜 SpotifyServer.java # Thread Pool (ExecutorService) init
┃ ┗ 📜 ClientHandler.java # Runnable protocol executor
┗ 📂 client
┗ 📜 SpotifyInteractiveClient.java # CLI Client for interactive testing
Navigate to the root directory and compile the entire project structure:
javac sdis/spotify/common/*.java sdis/spotify/utils/*.java sdis/spotify/server/*.java sdis/spotify/client/*.javaStart the Server:
java sdis.spotify.server.SpotifyServerStart the Interactive Client:
java sdis.spotify.client.SpotifyInteractiveClientInteraction Example Client Terminal (Adding a song):
--- SPOTIFY MENU ---
1. Login
2. Add Song to Playlist
3. Read Playlist
4. Delete Playlist
Select an option: 2
Playlist Name: Rock Classics
Song Name: Stairway to Heaven
>> Sending: ADD2L: Rock Classics -> Stairway to Heaven
<< Received: ADDEDServer Logs:
SERVER: [STARTING] on Port 2000
SERVER: New connection from 127.0.0.1
Handler [0]: Processed ADD2L from 127.0.0.1 successfully.-Iván Moro Cienfuegos, David Martín Sebastián, Eric Soto San José and Héctor