{"id":23507187,"url":"https://github.com/ngljcb/px-publish-subscribe","last_synced_at":"2026-02-21T04:03:34.731Z","repository":{"id":268273621,"uuid":"844688038","full_name":"ngljcb/px-publish-subscribe","owner":"ngljcb","description":"Implements a Java publish/subscribe system where clients post or receive topic-specific messages via a server.","archived":false,"fork":false,"pushed_at":"2025-10-10T15:48:33.000Z","size":150633,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-01T12:37:43.502Z","etag":null,"topics":["client-server","concurrent-programming","operating-system","publish-subscribe","socket","unibo","university-project"],"latest_commit_sha":null,"homepage":"https://ngljcb.github.io/px-publish-subscribe/","language":"Java","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ngljcb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-19T19:13:45.000Z","updated_at":"2025-10-10T15:51:10.000Z","dependencies_parsed_at":"2024-12-15T18:37:21.009Z","dependency_job_id":null,"html_url":"https://github.com/ngljcb/px-publish-subscribe","commit_stats":null,"previous_names":["ngljcb/px-sync","ngljcb/px-publish-subscribe"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ngljcb/px-publish-subscribe","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngljcb%2Fpx-publish-subscribe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngljcb%2Fpx-publish-subscribe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngljcb%2Fpx-publish-subscribe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngljcb%2Fpx-publish-subscribe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ngljcb","download_url":"https://codeload.github.com/ngljcb/px-publish-subscribe/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngljcb%2Fpx-publish-subscribe/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29672776,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T03:11:15.450Z","status":"ssl_error","status_checked_at":"2026-02-21T03:10:34.920Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["client-server","concurrent-programming","operating-system","publish-subscribe","socket","unibo","university-project"],"created_at":"2024-12-25T10:14:51.657Z","updated_at":"2026-02-21T04:03:34.707Z","avatar_url":"https://github.com/ngljcb.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Publish/Subscribe Messaging System\n\n\u003ca href=\"#\"\u003e\u003cimg src=\"./publish-subscribe/assets/pub-sub.png\"\u003e\u003c/a\u003e\n\n**Summary**  \nThis project implements a publish/subscribe messaging system using Java sockets, following a client-server architecture. Multiple clients can connect to a central server to interact as either publishers or subscribers. Publishers send messages to specific topics, while subscribers receive messages from the topics they are subscribed to. The server manages topics, clients, and ensures proper message flow with a focus on concurrency and synchronization.\n\n**Objectives**\n\n- **Client-Server Architecture**: Implement a server that handles multiple client connections using Java sockets.\n- **Publish/Subscribe Model**: Facilitate dynamic topic creation, publication of messages, and topic subscriptions.\n- **Topic Management**: Automatically create and manage topics based on client interactions.\n- **Concurrency Handling**: Ensure the system operates correctly under concurrent client connections and interactions.\n- **Server Administration**: Provide server-side commands for inspecting and managing topics and messages.\n\n**Features**\n\n- Clients can publish messages to topics or subscribe to receive updates from topics.\n- Topics are dynamically created when clients publish to or subscribe to new topics.\n- The server offers administrative commands for inspecting topics and messages, and even allows for message deletion.\n- Threading and concurrency are efficiently managed to allow multiple clients to connect and interact with the system simultaneously.\n- Synchronization mechanisms such as `synchronized` blocks, `wait/notifyAll`, and `CountDownLatch` are used to ensure safe access to shared resources by multiple clients, avoiding race conditions.\n- The system uses Java's socket programming to facilitate client-server communication, ensuring robust message exchange over a network.\n- The server controls prevent message loss or duplication during concurrent access, ensuring messages are delivered to the correct subscribers.\n\n**Concurrency Programming Techniques**  \nThe system uses advanced concurrency programming techniques to handle multiple clients interacting concurrently. Each client has its own thread using the `ClientHandler` class. The `TopicManager` handles shared resources like topics and messages, with synchronization ensuring safe access. Techniques like `BlockingQueue` and `CountDownLatch` are used for thread communication and managing tasks. This ensures that all clients can publish, subscribe, and interact without conflicts or data inconsistencies.\n\n**Code Structure**\n\n- **Server**: Manages client connections, topics, and message flow between clients.\n- **Client**: Clients connect to the server to either publish messages or subscribe to topics.\n- **TopicManager**: Central component for managing topics and coordinating messages between publishers and subscribers.\n- **ClientHandler**: Manages each client’s interaction with the server and processes requests.\n- **Message**: Represents individual messages within a topic, including metadata like timestamps and publisher info.\n\n**Usage Instructions**\n\n1. **Project Structure**  \n   The project is divided into two folders: `client` and `server`.\n\n2. **Compilation**  \n   Navigate to the appropriate folder (`client` or `server`) and use the following command to compile the Java files:\n\n   ```bash\n   javac *.java\n   ```\n\n3. **Starting the Server**  \n   To start the server, run the following command from the `server` directory:\n\n   ```bash\n   java Server \u003cport\u003e\n   ```\n\n   Example:\n\n   \u003ca href=\"#\"\u003e\u003cimg src=\"./publish-subscribe/assets/01-server-launch.gif\"\u003e\u003c/a\u003e\n\n   ```bash\n   java Server 9018\n   ```\n\n4. **Running the Client**  \n   To run a client, execute the following command from the `client` directory:\n\n   ```bash\n   java Client \u003chost\u003e \u003cport\u003e\n   ```\n\n   Example:\n\n   \u003ca href=\"#\"\u003e\u003cimg src=\"./publish-subscribe/assets/02-client-launch.gif\"\u003e\u003c/a\u003e\n\n   ```bash\n   java Client localhost 9018\n   ```\n\n5. **Client Commands**  \n   Once connected, clients can issue the following commands:\n\n   - `publish \u003ctopic\u003e`: Publish messages to a specific topic.\n\n     \u003ca href=\"#\"\u003e\u003cimg src=\"./publish-subscribe/assets/03-publish-topic.gif\"\u003e\u003c/a\u003e\n\n   - `subscribe \u003ctopic\u003e`: Subscribe to a topic to receive updates.\n\n     \u003ca href=\"#\"\u003e\u003cimg src=\"./publish-subscribe/assets/05-subscribe-topic.gif\"\u003e\u003c/a\u003e\n\n   - `show`: Request a list of available topics from the server.\n\n     \u003ca href=\"#\"\u003e\u003cimg src=\"./publish-subscribe/assets/06-show-topic.gif\"\u003e\u003c/a\u003e\n\n   - `quit`: Disconnect from the server.\n\n6. **Commands as Publisher**  \n   As a Publisher, clients can issue the following commands:\n\n   - `send \u003cmessage\u003e`: After choosing a topic, publish a message to it.\n\n     \u003ca href=\"#\"\u003e\u003cimg src=\"./publish-subscribe/assets/04-send-topic.gif\"\u003e\u003c/a\u003e\n\n   - `list`: List messages you’ve published to a topic.\n\n     \u003ca href=\"#\"\u003e\u003cimg src=\"./publish-subscribe/assets/07-publisher-list.gif\"\u003e\u003c/a\u003e\n\n   - `listall`: List all messages in a topic.\n\n     \u003ca href=\"#\"\u003e\u003cimg src=\"./publish-subscribe/assets/08-publisher-listall.gif\"\u003e\u003c/a\u003e\n\n   - `quit`: Disconnect from the server.\n\n7. **Commands as Subscriber**  \n   As a Subscriber, clients can issue the following commands:\n\n   - `listall`: List all messages in a topic.\n\n     \u003ca href=\"#\"\u003e\u003cimg src=\"./publish-subscribe/assets/09-subscriber-listall.gif\"\u003e\u003c/a\u003e\n\n   - `quit`: Disconnect from the server.\n\n8. **Server Administration Commands**  \n   The server accepts administrative commands directly from the console:\n\n   - `show`: Displays all available topics.\n\n     \u003ca href=\"#\"\u003e\u003cimg src=\"./publish-subscribe/assets/10-server-show.gif\"\u003e\u003c/a\u003e\n\n   - `inspect`: Inspect messages in a specific topic.\n\n     \u003ca href=\"#\"\u003e\u003cimg src=\"./publish-subscribe/assets/11-server-inspect.gif\"\u003e\u003c/a\u003e\n\n   - `quit`: Shuts down the server gracefully.\n\n9. **Inspection Commands**  \n   During the inspection, the following commands can be issued from the console:\n\n   - `:listall`: Displays all available messages in a specific topic.\n\n     \u003ca href=\"#\"\u003e\u003cimg src=\"./publish-subscribe/assets/12-server-listall.gif\"\u003e\u003c/a\u003e\n\n   - `:delete \u003cid\u003e`: Eliminates a specific message of a given id.\n\n     \u003ca href=\"#\"\u003e\u003cimg src=\"./publish-subscribe/assets/13-server-delete.gif\"\u003e\u003c/a\u003e\n\n   - `:end`: To end the interactive inspect on console.\n\n\u003cbr\u003e\n\n---\n\nThis project is an implementation of a real-time messaging system using a client-server architecture via Java sockets. The publish/subscribe model is handled effectively, with a strong emphasis on concurrency control using synchronization techniques. The use of Java socket programming ensures robust communication between clients and the server. The design handles concurrent client interactions with efficiency, ensuring that the messaging system scales well with multiple users.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fngljcb%2Fpx-publish-subscribe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fngljcb%2Fpx-publish-subscribe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fngljcb%2Fpx-publish-subscribe/lists"}