theLink 10.0
|
List of all callback defined by pymqmsgque
The callback have to be a Python proc or method …
There a two different types of callback:
There are 3 different types of callback :
type | code | self argument |
---|---|---|
procedure | ... proc-callback | yes |
class-method | ... CLASS.callback | yes |
instance-method | ... INSTANCE.callback | yes |
Example from Callback.py
→ using MqServiceCreate with callback
import sys from pymqmsgque import * # General rules for defining a callback in PATHON # ----------------------------------------------- # 1. A callback always begins with the "Object", either the "instanceObject" or the "classObject": # `Object.Method` # 2. If the callback is an "instanceMethod" of another instance, the callback is defined as: # `instanceObject.instanceMethod # 3. If the callback is an "instanceMethod" of its own instance, the callback is defined as: # `self.instanceMethod` # 4. If the callback is a "classMethod," the callback is defined as: # `classObject.classMethod` class OtherServerC(): def __init__(self,wht): self.wht = wht # The "otherInstanceService" require an extra argument, the "cbCtx". def otherInstanceService(self,cbCtx): cbCtx.Send("R","C",cbCtx.ReadSTR() + "-" + self.wht + "-Other-Instance") # The "otherClassService" require an extra argument, the "cbCtx". @staticmethod def otherClassService(cbCtx): cbCtx.Send("R","C",cbCtx.ReadSTR() + "-World-Other-Class") # The "procService" require an extra argument, the "cbCtx". def procService(cbCtx): cbCtx.Send("R","C",cbCtx.ReadSTR() + "-World-Proc") # package-item class CallbackC(MqContextC): # The "ownInstanceService" require no extra argument. def ownInstanceService(self): self.Send("R","C",self.ReadSTR() + "-World-Own-Instance") # The "ownClassService" require an extra argument, the "cbCtx". @staticmethod def ownClassService(cbCtx): cbCtx.Send("R","C",cbCtx.ReadSTR() + "-World-Own-Class") # the "serverSetup" defines the test-services def serverSetup(self): # 1. The "otherInstanceCallback" require an extra argument, the "otherCtx". self.ServiceCreate("HLW1",self.otherCtx.otherInstanceService) # 2. The "otherClassCallback" require NO extra argument. self.ServiceCreate("HLW2",OtherServerC.otherClassService) # 3. The "ownInstanceCallback" require no extra argument. self.ServiceCreate("HLW3",self.ownInstanceService) # 4. The "otherClassCallback" require NO extra argument. self.ServiceCreate("HLW4",CallbackC.ownClassService) # 5. The "procCallback" require NO extra argument self.ServiceCreate("HLW5",procService) # factory startup (constructor) def __init__(self,tmpl=None): super().__init__(self,tmpl) self.ConfigSetServerSetup(CallbackC.serverSetup) self.otherCtx = OtherServerC("World") ; # just for test purpose # package-main if __name__ == "__main__": # create the "Callback" factory… and the object srv = MqFactoryC.Add(CallbackC).New() try: srv.LinkCreate(sys.argv) srv.ProcessEvent(MqWaitOnEventE.FOREVER) except Exception as ex: srv.ErrorCatch(ex) finally: srv.Exit()