theLink 10.0
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 atlmqmsgque.

To perform the test multiple classes are created and connected using the atlmqmsgque 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 atlmqmsgque protocoll and build together a tree-like structure.

The GOAL for this setup is:

CODE server

#!/usr/bin/env atlsh
#+
#:   @file         NHI1/example/atl/MyRouter.atl
#:   @brief        tag: nhi1-release-250425
#:   @copyright    (C) NHI - #1 - Project - Group
#:                 This software has NO permission to copy,
#:                 please contact AUTHOR for additional information
#:

#package require lib_debug

# [rooter_server_example]
package require lib_85
package require atlmqmsgque

::myooX::ClassN ::Basic {
  namespace export {[A-Z]*}
  SuperI ::MqContextC

  proc Basic {myNs {tmpl ""}} {
    MqContextC $myNs $tmpl
    namespace upvar $myNs my my
    set my(id1) 11
    set my(id2) 12
  }

  proc CreateWorker { myNs master_id factory } {
    SlaveWorker $myNs $master_id $factory \
      "--prefix" "cl$factory-$master_id" "@" "--prefix" "sv$factory-$master_id"

    SlaveGet $myNs $master_id
  }

  proc HLWO { myNs } {
    Send $myNs "R" "C" [ConfigGetName $myNs]
  }
  
  proc FOID { myNs } {
    SendSTART $myNs
    SendSTR $myNs "[ClassOriginalIdentGet $myNs]-[LinkGetCtxId $myNs]"
    SendRETURN $myNs
  }
  
  proc PATH { myNs } {
    Send $myNs "R" "C" [RouteGetPath $myNs]
  }

  proc TREE { myNs } {
    Send $myNs "R" "L" [RouteGetTree $myNs]
  }

  proc HLWS { myNs } {
    setup [SlaveGetMaster $myNs]
    Send $myNs "R"
  }
  
  proc setup { myNs } {
    ServiceCreate $myNs "HLWO"  HLWO
    ServiceCreate $myNs "FOID"  FOID
    ServiceCreate $myNs "PATH"  PATH
    ServiceCreate $myNs "TREE"  TREE
    ServiceCreate $myNs "HLWS"  HLWS
  }
}

# ************************************************************

::myooX::ClassN ::WO1 {
  SuperI ::Basic
  proc WO1 {myNs {tmpl ""}} {
    Basic $myNs $tmpl
    ConfigSetServerSetup $myNs serverSetup
  }
  proc serverSetup { myNs } {
    if {[LinkIsParent $myNs]} {
      namespace upvar $myNs my my
      CreateWorker $myNs $my(id1)  "WO2"
      CreateWorker $myNs $my(id2)  "WO2"
    }
    Basic::setup $myNs
  }
}

# ************************************************************

::myooX::ClassN ::WO2 {
  SuperI ::Basic
  proc WO2 {myNs {tmpl ""}} {
    Basic $myNs $tmpl
    ConfigSetServerSetup $myNs serverSetup
  }
  proc serverSetup { myNs } {
    if {[LinkIsParent $myNs]} {
      namespace upvar $myNs my my
      CreateWorker $myNs $my(id1)  "WO3"
      CreateWorker $myNs $my(id2)  "WO3"
    }
    Basic::setup $myNs
  }
}

# ************************************************************

::myooX::ClassN ::WO3 {
  SuperI ::Basic
  proc WO3 {myNs {tmpl ""}} {
    Basic $myNs $tmpl
    ConfigSetServerSetup $myNs serverSetup
  }
  proc FINL { myNs } {
    Send $myNs "R" "C" FINL-[ConfigGetName $myNs]
  }
  proc serverSetup { myNs } {
    ServiceCreate $myNs "FINL"  FINL
    Basic::setup $myNs
  }
}

MqMsgque::Main {

  # setup commandline arguments for later use
  set args  [MkBufferListC::CreateLA {*}$argv]

  # create factory... and default.
  MqFactoryC::Default [MqFactoryC::Add ::WO1]
  MqFactoryC::Add ::WO2
  MqFactoryC::Add ::WO3

  # inspect commandline-argument for the "factory" to choose... and create a object
  set srv   [MqFactoryC::New [MqFactoryC::GetCalledL $args]]

  try {
    MqContextC::LinkCreate $srv $args
    MqContextC::ProcessEvent $srv MQ_WAIT_FOREVER
  } on error {} {
    MqContextC::ErrorCatch $srv
  } finally {
    myooX::DestroyN $args
    MqContextC::Exit $srv
  }
}
# [rooter_server_example]