domainlab.compos.pcr package¶
Submodules¶
domainlab.compos.pcr.p_chain_handler module¶
Chain of Responsibility
- class domainlab.compos.pcr.p_chain_handler.AbstractChainNodeHandler(success_node=None)[source]¶
Bases:
object
Chain of Responsibility: 1. Make sure the chain can be constructed successfully even one node fails to initialize its designated service/business object so services from other nodes will still be available. 2. To ensure this decoupling, avoid overriding self.__init__() (the initializer/constructor) of the handler by using multiple inheritance. e.g. inherit both AbstractChainNodeHandler and Factory Interface since doing so couples the Factory initializer with the AbstractChainNodeHandler(): if the initializer/constructor of the Factory does not work, it will affect the whole chain. 3. Instead, return service/business object in a member function of AbstractChainNodeHandler self.init_business(), this can result in redundant code but is safest. 4. A sub-optimal but still acceptable solution is to use Multiple Inheritance (inherit AbstractChainNodeHandler and Factory interface) but only override the self.init_business(*kargs, **kwargs) method (with concrete input arguments) of the Chain Handler so the initializer/constructor of the Chain Handler will always work. Factory can be returned by calling ChainNode.init_business(*kargs, **kwargs). This can still be coupling since there might be some interface methods in Factory, once you change the parent class, some concrete factories has not implemented that, which will break the initalization of the chain.
- handle(request)[source]¶
This method invoke self.is_myjob() to check which node in the chain should handle the request :param request: subclass can override request object to be string or function :return: light weight AbstractChainNodeHandler
- abstract init_business(*kargs)[source]¶
init_business: initialize and return the heavy weight business object for doing the real job :param request: subclass can override request object to be string or function :return: the constructed service object
- class domainlab.compos.pcr.p_chain_handler.DummyBusiness[source]¶
Bases:
object
- message = 'dummy business'¶
- class domainlab.compos.pcr.p_chain_handler.DummyChainNodeHandlerBeaver(success_node=None)[source]¶
Bases:
AbstractChainNodeHandler
Dummy class to show how to inherit from Chain of Responsibility
- class domainlab.compos.pcr.p_chain_handler.DummyChainNodeHandlerLazy(success_node=None)[source]¶
Bases:
AbstractChainNodeHandler
Dummy class to show how to inherit from Chain of Responsibility
domainlab.compos.pcr.request module¶
- class domainlab.compos.pcr.request.RequestArgs2ExpCmd(args)[source]¶
Bases:
object
Isolate args from Request object of chain of responsibility node for experiment For example, args has field names which will couple with experiment class, this request class also serves as isolation class or adaptation class