Giter Site home page Giter Site logo

base-service-class's Introduction

Base-Service-Class

Module for creating services, transferring requests and responses between them using the base class Service. Developed and maintained on Python 3

Service class

Base service class.

class Service(object)

Service constructor.
[in] name - Service name.
[in] workerTimeout - Service worker timeout.
[in] numWorkerThreads - Count of service worker threads.
[in] jobQueueMaxSize - Service job queue max size.

def __init__(self, name, workerTimeout = 1, numWorkerThreads = 16, jobQueueMaxSize = 100)

Service destructor. Joins worker threads.

def __del__(self)

Starts service. Runs worker threads.

def start(self)

Stops Service. Joins worker threads.

def stop(self)

Gets service state.
[out] true - Service is running.
[out] false - Service is stopped.

def state(self)

Sends request to service.
[in] package - Contained method and arguments to call in request service.

def sendRequest(self, package)

Sends responce to service.
[in] package - Contained method and arguments to call in response service.

def sendResponse(self, package)

Package class

Container for transfering data between services.

class Package(object)

Package constructor.
[in] requestServiceName - Request service name.
[in] requestMethod - Request method in service.
[in] requestArguments - Request arguments for method, can be ignored.
[in] responseServiceName - Response service name, can be ignored.
[in] responseMethod - Response method in service, can be ignored.

def __init__(self, requestServiceName, requestMethod,requestArguments = None,
  responseServiceName = None, responseMethod = None)

Example run

Example of using base Service class.

user@user-lws$ python3 example.py 
[DEBUG, 22-Jan-20 14:22:51] __init__: Calculator
[DEBUG, 22-Jan-20 14:22:51] __init__: User
[DEBUG, 22-Jan-20 14:22:51] start: Calculator
[DEBUG, 22-Jan-20 14:22:51] start: User
[DEBUG, 22-Jan-20 14:22:52] askPlusOperation: 34, 21
[DEBUG, 22-Jan-20 14:22:52] sendRequest: User to Calculator, plusOperation
[DEBUG, 22-Jan-20 14:22:52] __worker: Calculator call plusOperation
[DEBUG, 22-Jan-20 14:22:52] plusOperation: 34, 21
[DEBUG, 22-Jan-20 14:22:52] sendResponse: Calculator to User, onPlusOperationDone
[DEBUG, 22-Jan-20 14:22:52] __worker: User call onPlusOperationDone
[DEBUG, 22-Jan-20 14:22:52] onPlusOperationDone: 34 + 21 = 55
[DEBUG, 22-Jan-20 14:22:53] stop: Calculator
[DEBUG, 22-Jan-20 14:22:54] stop: User
[DEBUG, 22-Jan-20 14:22:55] __del__: Calculator
[DEBUG, 22-Jan-20 14:22:55] __del__: User

Unittests

Provided unit tests for service module.

user@user-lws$ python3 -m unittest -v test
testSendJobs (test.TestService) ... ok
testSendNone (test.TestService) ... ok
testSendNoneWithoutResponse (test.TestService) ... ok
testSendNumber (test.TestService) ... ok
testSendPair (test.TestService) ... ok
testSendTuple (test.TestService) ... ok
testStartStop (test.TestService) ... ok

----------------------------------------------------------------------
Ran 7 tests in 13.323s

OK

base-service-class's People

Contributors

antonmyrhorod avatar isolomak avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.