Documentation of the MyRouter tool used for route2.test
.
The MyRouter tool is used to test the routing-feature of csmqmsgque.
To perform the test multiple classes are created and connected using the csmqmsgque protocol.
The following class-hierarchie is used:
Base |----|----| WO1 WO2 WO3
The routing-test is perfomed by connecting multiple context.
|-> 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 csmqmsgque protocoll and build together a tree-like structure.
The GOAL for this setup is:
/** * @file NHI1/example/cs/MyRouter.cs * @brief MyRouter.cs - 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> */ using System; using System.Collections.Generic; using csmkkernel; using csmqmsgque; namespace example { // F1 ******************************************************** abstract class Basis : MqContextC, MqServerSetupIF { protected static readonly int id1 = 11; protected static readonly int id2 = 12; public Basis(MqContextC tmpl=null) : base(tmpl) { } protected void CreateWorker(int master_id, string factory) { SlaveWorker(master_id, factory, "--prefix", "cl" + factory + "-" + master_id, "@", "--prefix", "sv" + factory + "-" + master_id ); } protected void HLWO() { Send("R", "C", ConfigGetName()); } protected void FOID() { Send("R", "C", ClassOriginalIdentGet() + "-" + LinkGetCtxId()); } protected void PATH() { Send("R", "C", RouteGetPath()); } protected void TREE() { Send("R", "L", RouteGetTree()); } static protected void HLWS(MqContextC ctx) { ((Basis)ctx.SlaveGetMaster()).Setup(); ctx.SendRETURN(); } protected void Setup () { ServiceCreate("HLWO", HLWO); ServiceCreate("FOID", FOID); ServiceCreate("PATH", PATH); ServiceCreate("TREE", TREE); ServiceCreate("HLWS", HLWS); } public abstract void ServerSetup (); } // ******************************************************** sealed class WO1 : Basis { public WO1(MqContextC tmpl=null) : base(tmpl) { } public override void ServerSetup () { if (LinkIsParent()) { CreateWorker (id1, "WO2"); CreateWorker (id2, "WO2"); } Setup(); } } // ******************************************************** sealed class WO2 : Basis { public WO2(MqContextC tmpl=null) : base(tmpl) { } public override void ServerSetup () { if (LinkIsParent()) { CreateWorker (id1, "WO3"); CreateWorker (id2, "WO3"); } Setup(); } } // ******************************************************** sealed class WO3 : Basis { public WO3(MqContextC tmpl=null) : base(tmpl) { } void FINL () { Send("R", "C", "FINL-" + ConfigGetName()); } public override void ServerSetup () { Setup(); ServiceCreate("FINL", FINL); } } // Main ****************************************************** sealed class MyRouter : MqContextC { public static void Main(string[] argv) { // create buffer-list of the application arguments MkBufferListC largv = new MkBufferListC(argv); // add factories MqFactoryCT<WO1>.Add().Default(); MqFactoryCT<WO2>.Add(); MqFactoryCT<WO3>.Add(); // select factory using the !first! application argument // and create a new server MqContextC srv = MqFactoryCT<MqContextC>.GetCalled(largv).New(); try { // configure and start the server srv.LinkCreate(largv); // start event-loop and wait forever srv.ProcessEvent(MqWaitOnEventE.FOREVER); } catch (Exception ex) { // set the libmqmsgque error from the csharp error srv.ErrorCatch (ex); } // exit aplication and cleanup the environment srv.Exit(); } } }