theLink 10.0 NHI1 - theKernel - theLink - theConfig - theSq3Lite - theCompiler - theBrain - theGuard
c - tcl - 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 jvmqmsgque.

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

The GOAL for this setup is:

CODE server

/**
 *   @file         NHI1/example/jv/MyRouter.java
 *   @brief        MyRouter.java - 19 Aug 2024 - aotto1968
 *   @copyright    (C) NHI - #1 - Project - Group
 *                 This software has NO permissions to copy,
 *                 please contact AUTHOR for additional information
 *   @version      a5cb9f916df9a2d44f91871d69b296ab9a9d1e68
 *   @date         Mon Aug 19 14:57:57 2024 +0200
 *   @author       aotto1968 <aotto1968@t-online.de>
 */

package example;

import jvmsgque.mqmsgque.*;
import jvmsgque.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 MqServiceIF {
    public void Callback(MqContextC ctx) {
      ctx.Send("R", "C", ctx.ConfigGetName());
    }
  }

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

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

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

  protected static class HLWS implements MqServiceIF {
    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 MqServiceIF {
    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();
    }
  }
}