theLink 10.0 NHI1 - theKernel - theLink - theConfig - theSq3Lite - theCompiler - theBrain - theGuard
c - tcl - cs - py - rb - jv - cc
Loading...
Searching...
No Matches
Example: MyRouter

Documentation of the MyRouter tool used for route2.test.

INTRODUCTION

The MyRouter tool is used to test the routing-feature of pymqmsgque.

To perform the test multiple classes are created and connected using the pymqmsgque protocol.
The following class-hierarchie is used:

       Base
   |----|----|
  WO1  WO2  WO3       

The routing-test is perfomed by connecting multiple context.

  • The client connect to the WO1-context.
  • On WO1-ServerSetup the WO1-context create two WO2-context using the CreateWorker methode from Base.
  • On WO2-ServerSetup the W02-context create two WO3-context using the CreateWorker methode from Base.
                           |-> WO3#1
                |-> WO2#1 -|-> WO3#2
 client -> WO1 -|
                |-> W02#2 -|-> WO3#1
                           |-> WO3#2

All context created, 1x client and 7x server, are connected using the pymqmsgque protocoll and build together a tree-like structure.

The GOAL for this setup is:

CODE server

#+
#:   -*- coding: utf8 -*-
#:
#:   @file         NHI1/example/py/MyRouter.py
#:   @brief        MyRouter.py - 26 Jun 2024 - aotto1968
#:   @copyright    (C) NHI - #1 - Project - Group
#:                 This software has NO permission to copy,
#:                 please contact AUTHOR for additional information
#:   @version      08a242faddae5101924d8fe811888e78892a82d9
#:   @date         Wed Jun 26 14:26:21 2024 +0200
#:   @author       aotto1968 <aotto1968@t-online.de>
#:

import sys
from pymkkernel import *
from pymqmsgque import *

class Basic(MqContextC):

  id1 = 11
  id2 = 12

  def __init__(self, tmpl=None):
    super().__init__()

  def CreateWorker(self, master_id, factory):
    self.SlaveWorker( master_id, factory,                                          \
                        "--prefix", "cl" + factory + "-" + str(master_id), "@",    \
                          "--prefix", "sv" + factory + "-" + str(master_id)        \
    )

  def HLWO(self):
    self.Send("R", "C", self.ConfigGetName())

  def FOID(self):
    self.Send("R", "C", self.ClassOriginalIdentGet() + "-" + str(self.LinkGetCtxId()))

  def PATH(self):
    self.Send("R", "C", self.RouteGetPath())

  def TREE(self):
    self.Send("R", "L", self.RouteGetTree())

  def HLWS(self):
    self.SlaveGetMaster().Setup()
    self.SendRETURN()

  def Setup(self):
    self.ServiceCreate("HLWO",Basic.HLWO)
    self.ServiceCreate("FOID",Basic.FOID)
    self.ServiceCreate("PATH",Basic.PATH)
    self.ServiceCreate("TREE",Basic.TREE)
    self.ServiceCreate("HLWS",Basic.HLWS)

class WO1(Basic):

  def __init__(self, tmpl=None):
    self.ConfigSetServerSetup(self.ServerSetup)
    super().__init__()

  def ServerSetup(self):
    if (self.LinkIsParent()):
      self.CreateWorker(Basic.id1, "WO2")
      self.CreateWorker(Basic.id2, "WO2")
    super().Setup()

class WO2(Basic):

  def __init__(self, tmpl=None):
    self.ConfigSetServerSetup(self.ServerSetup)
    super().__init__()

  def ServerSetup(self):
    if (self.LinkIsParent()):
      self.CreateWorker(Basic.id1, "WO3")
      self.CreateWorker(Basic.id2, "WO3")
    super().Setup()

class WO3(Basic):

  def __init__(self, tmpl=None):
    self.ConfigSetServerSetup(self.ServerSetup)
    super().__init__()

  def FINL(self):
    self.Send("R", "C", "FINL-" + self.ConfigGetName())

  def ServerSetup(self):
    super().Setup()
    self.ServiceCreate("FINL",WO3.FINL)

if __name__ == "__main__":

  # create buffer-list of the application arguments
  largv = MkBufferListC.CreateLA(sys.argv)

  # create the factories…
  MqFactoryC.Add(WO1).Default()
  MqFactoryC.Add(WO2)
  MqFactoryC.Add(WO3)

  # select factory using the !first! application argument
  # and create a new server
  srv = MqFactoryC.GetCalledL(largv).New()

  try:
    # configure and start the server
    srv.LinkCreate(largv)

    # start event-loop and wait forever
    srv.ProcessEvent(MqWaitOnEventE.FOREVER)

  except Exception as ex:
    srv.ErrorCatch(ex)

  finally:
    srv.Exit()