javamqmsgque 9.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 javamqmsgque.

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

The GOAL for this setup is:

CODE server

/**
 *   @file         example/java/MyRouter.java
 *   @brief        MyRouter.java - 02 May 2023 - aotto1968
 *   @copyright    (C) NHI - #1 - Project - Group
 *                 This software has NO permissions to copy,
 *                 please contact AUTHOR for additional information
 *   @version      d2cd8f6ec2179f5e5583ae98faed11359996631d
 *   @date         Tue May 2 21:28:46 2023 +0200
 *   @author       aotto1968 <aotto1968@t-online.de>
 */

package example;

import javamsgque.mqmsgque.*;
import javamsgque.mkkernel.*;

// F1 **********************************************************

abstract class Basic extends MqContextC implements IServerSetup {
  static int  id1 = 11;
  static int  id2 = 12;

  public Basic(MqContextC tmpl) {
    super(tmpl);
  }

  protected void CreateWorker(int master_id, String factory) {
    SlaveWorker(master_id, factory,
      "--prefix", "cl" + factory + "-" + master_id,
        "@",
          "--prefix", "sv" + factory + "-" + master_id
    );
  }

  protected static class HLWO implements ICallback {
    public void Callback(MqContextC ctx) {
      ctx.Send("R", "C", ctx.ConfigGetName());
    }
  }

  protected static class FOID implements ICallback {
    public void Callback(MqContextC ctx) {
      ctx.Send("R", "C", ctx.ClassOriginalIdentGet() + "-" + ctx.LinkGetCtxId());
    }
  }

  protected static class PATH implements ICallback {
    public void Callback(MqContextC ctx) {
      ctx.Send("R", "C", ctx.RouteGetPath());
    }
  }

  protected static class TREE implements ICallback {
    public void Callback(MqContextC ctx) {
      ctx.Send("R", "L", ctx.RouteGetTree());
    }
  }

  protected static class HLWS implements ICallback {
    public void Callback(MqContextC ctx) {
      Basic master = (Basic) ctx.SlaveGetMaster();
      master.Setup();
      ctx.SendRETURN();
    }
  }

  public void Setup() {
    ServiceCreate("HLWO", new HLWO()); 
    ServiceCreate("FOID", new FOID()); 
    ServiceCreate("PATH", new PATH()); 
    ServiceCreate("TREE", new TREE()); 
    ServiceCreate("HLWS", new Basic.HLWS()); 
  }
}

class WO1 extends Basic {
  public WO1(MqContextC tmpl) {
    super(tmpl);
  }

  public void ServerSetup() {
    if (LinkIsParent()) {
      CreateWorker (id1, "WO2");
      CreateWorker (id2, "WO2");
    }
    Setup();
  }
}

class WO2 extends Basic {
  public WO2(MqContextC tmpl) {
    super(tmpl);
  }

  public void ServerSetup() {
    if (LinkIsParent()) {
      CreateWorker (id1, "WO3");
      CreateWorker (id2, "WO3");
    }
    Setup();
  }
}

class WO3 extends Basic {
  public WO3(MqContextC tmpl) {
    super(tmpl);
  }

  protected class FINL implements ICallback {
    public void Callback(MqContextC ctx) {
      ctx.Send("R", "C", "FINL-" + ctx.ConfigGetName());
    }
  }

  public void ServerSetup() {
    Setup();
    ServiceCreate("FINL", new FINL()); 
  }
}

// main ********************************************************

final class MyRouter {

  public static void main(String[] argv) {
    MkBufferListC largs = new MkBufferListC(argv);
    MqFactoryC.Add(WO1.class, "WO1").Default();
    MqFactoryC.Add(WO2.class, "WO2");
    MqFactoryC.Add(WO3.class, "WO3");
    MqContextC srv = MqFactoryC.GetCalled(largs).New();
    try {
      srv.LinkCreate(largs);
      srv.ProcessEvent(MqWaitOnEventE.FOREVER);
    } catch (Throwable e) {
      srv.ErrorCatch(e);
    } finally {
      srv.Exit();
    }
  }
}