Skip to main content

A library for coordinated client-server communication using a queue-based approach.

Project description

QueueSync

The QueueSync is a Python library for coordinating and managing distributed systems. It consists of a Coordinator (server) that queues and processes client requests sequentially, and Worker (client) instances that send requests to the Coordinator. This library is structured to support multi-machine coordination in a networked environment.

Features

  • Queue-based Request Management: The Coordinator class queues client requests, handling them one at a time.
  • Threaded Connections: Supports concurrent connections without blocking operations.
  • Extensible: Built with abstract base classes, allowing custom implementations of both Coordinator and Worker.
  • Optional Status Updates: Display connection status and data transfer updates.

Directory Structure

The project is organized as follows:

QueueSync/
├── src/
│   ├── __init__.py
│   ├── coordinator.py
│   └── worker.py
├── tests/
│   ├── __init__.py
│   ├── test_coordinator.py
│   └── test_worker.py
├── .gitignore
├── LICENSE
├── README.md
├── setup.py                   
└── pyproject.toml

Installation

Clone the repository and ensure you have Python 3.x installed. Optionally, set up a virtual environment:

git clone https://github.com/yourusername/inter-machine-coordinator-library.git
cd inter-machine-coordinator-library
python3 -m venv .venv
source .venv/bin/activate  # On Windows use `.venv\Scripts\activate`

Usage

Coordinator

The Coordinator class, located in src/coordinator.py, is an abstract class that serves as the server, managing client connections and processing requests from a queue.

Key Methods

  • start(): Initializes and starts the server.
  • queue_client_request(client_socket, client_address): Adds client requests to a queue.
  • Process_requests(): Sequentially processes each queued request.
  • handle_request(client_socket, client_address, received_data): Abstract method to be implemented for custom request processing.

Worker

The Worker class, located in src/worker.py, is an abstract class representing the client, which connects to the Coordinator server, sends requests, and receives responses.

Key Methods

  • start(): Connects the Worker to the Coordinator server.
  • query_coordinator(data): Sends data to the server and awaits a response.
  • run_worker(): Abstract method to be implemented for custom worker logic.

Customisation

To implement specific request handling and worker functionality, create subclasses of Coordinator and Worker, then override the handle_request and run_worker methods, respectively.

Example:

from src.coordinator import Coordinator
from src.worker import Worker

class MyCoordinator(Coordinator):
    def handle_request(self, client_socket, client_address, received_data):
        response = b"Custom response data"
        return response

class MyWorker(Worker):
    def run_worker(self):
        data = b"Sample request data"
        response = self.query_coordinator(data)
        print(f"Received response: {response}")

Example

  1. Coordinator:

    coordinator = MyCoordinator(host='127.0.0.1', port=12345, max_num_of_clients=5, are_updates_displayed=True)
    coordinator.start()
    
  2. Worker:

    worker = MyWorker(host='127.0.0.1', port=12345, are_updates_displayed=True)
    worker.start()
    

This example demonstrates a simple setup with a Coordinator listening on localhost and a custom Worker connecting to it.

License

This library is open-source and available under the Apache License 2.0. See the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

queuesync-1.0.1.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

queuesync-1.0.1-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file queuesync-1.0.1.tar.gz.

File metadata

  • Download URL: queuesync-1.0.1.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for queuesync-1.0.1.tar.gz
Algorithm Hash digest
SHA256 f112e91e7c7cd45ad7963ac456a6b25dcee5077ffbd0cbf9cd14bcb330eb0387
MD5 ad95ad3e503836c0488a1d03e0c7469f
BLAKE2b-256 450b822d02ad89d4d4a18df2d85581601589ff9def441e67c0fd452f282f2e4c

See more details on using hashes here.

File details

Details for the file queuesync-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: queuesync-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for queuesync-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 468cba6b8089aa18b2b814358146239bc263294411868c165fa519089a115760
MD5 757dc90bb00572cff8f201b02ac86f20
BLAKE2b-256 34e4f6af0ba713eb4be5868904fe7ed2b07c496737a508228367590c3eac7383

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page