javamqmsgque 9.0
Loading...
Searching...
No Matches
Example: perfserver

Documentation of the perfserver tool used for example.test.

INTRODUCTION

The perfserver tool is used server-part of the performance-test

To perform the test the perfclient send various service request to the perfserver. The perfclient is written in C and finally create a report.

All context created, are connected using the javamqmsgque protocoll and build together a flat-like structure.

The GOAL for this setup is:

CODE server

/**
 *   @file         example/java/perfserver.java
 *   @brief        perfserver.java - 03 May 2023 - aotto1968
 *   @copyright    (C) NHI - #1 - Project - Group
 *                 This software has NO permissions to copy,
 *                 please contact AUTHOR for additional information
 *   @version      1c3a8f89f6bbd5c146252125f8a426400f6e1300
 *   @date         Wed May 3 12:28:13 2023 +0200
 *   @author       aotto1968 <aotto1968@t-online.de>
 */

package example;
import java.util.stream.IntStream;
import javamsgque.mqmsgque.*;
import javamsgque.mkkernel.*;

final class perfserver extends MqContextC implements IServerSetup {

  // Factory Constructor
  public perfserver(MqContextC tmpl) {
    super(tmpl);
  }

  class ECOU implements ICallback {
    public void Callback(MqContextC ctx) {
      ctx.SendSTART();
      ctx.SendU(ctx.ReadU());
      ctx.SendRETURN();
    }
  }

  class ECOI implements ICallback {
    public void Callback(MqContextC ctx) {
      ctx.SendSTART();
      int i = ctx.ReadI();
      ctx.SendI(i);
      ctx.SendRETURN();
    }
  }

  class ECUL implements ICallback {
    public void Callback(MqContextC ctx) {
      ctx.SendSTART();
      ctx.SendY(ctx.ReadY());
      ctx.SendS(ctx.ReadS());
      ctx.SendI(ctx.ReadI());
      ctx.SendD(ctx.ReadD());
      ctx.ProxyItem(ctx);
      ctx.SendRETURN();
    }
  }

  class RDUL implements ICallback {
    public void Callback(MqContextC ctx) {
      ctx.ReadY();
      ctx.ReadS();
      ctx.ReadI();
      ctx.ReadD();
      ctx.ReadU();
    }
  }

  class RDUC implements ICallback {
    public void Callback(MqContextC ctx) {
      ctx.ReadC();
      ctx.ReadC();
      ctx.ReadC();
      ctx.ReadC();
      ctx.ReadC();
    }
  }

  class STDB implements ICallback {
    public void Callback(MqContextC ctx) {
      ctx.SendSTART();
      ctx.StorageOpen(ReadC());
      ctx.SendRETURN();
    }
  }

  class STDC implements ICallback {
    public void Callback(MqContextC ctx) {
      ctx.SendSTART();
      ctx.StorageClose();
      ctx.SendRETURN();
    }
  }

  // [BufferStream-Create-TLS]
  class BUST implements ICallback {
    public void Callback(MqContextC ctx) {
      MkBufferStreamC bus = MkBufferStreamC.CreateTLS(0);
      while (ReadItemExists()) {
        bus.WriteU(ReadU());
      }
      bus.PosToStart();
      SendSTART();
      while (bus.ReadItemExists()) {
        SendU(bus.ReadU());
      }
      SendRETURN();
    }
  }
  // [BufferStream-Create-TLS]

  // [BufferList-Create-TLS]
  class BFLT implements ICallback {
    public void Callback(MqContextC ctx) {
      MkBufferListC bfl = MkBufferListC.CreateTLS(0);
      while (ReadItemExists()) {
        bfl.AppendU(ReadU());
      }
      SendSTART();
      IntStream.range(0, bfl.Size()).forEach(
        i -> {
          SendU(bfl.IndexGet(i));
        }
      );
      SendRETURN();
    }
  }
  // [BufferList-Create-TLS]

  class BINT implements ICallback {
    public void Callback(MqContextC ctx) {
      ctx.ReadB();
    }
  }

  class STRT implements ICallback {
    public void Callback(MqContextC ctx) {
      ctx.ReadC();
    }
  }

  // define a service as link between the token "HLWO" and the class "MyFirstService"
  public void ServerSetup() {
    ServiceCreate("ECOU", new ECOU());
    ServiceCreate("ECOI", new ECOI());
    ServiceCreate("ECUL", new ECUL());
    ServiceCreate("RDUL", new RDUL());
    ServiceCreate("RDUC", new RDUC());
    ServiceCreate("STDB", new STDB());
    ServiceCreate("STDC", new STDC());
    ServiceCreate("BUST", new BUST());
    ServiceCreate("BFLT", new BFLT());
    ServiceCreate("BINT", new BINT());
    ServiceCreate("STRT", new STRT());
  }

  // -------------------------------------------------------------

  public static void main(String[] argv) {
    // setup commandline arguments for later use
    MkBufferListC largs = new MkBufferListC(argv);
  
    // [factory-item]
    // create "perfserver" factory… and make it to the default.
    MqFactoryC.Add(perfserver.class).Default();
    // [factory-item]

    // inspect commandline-argument for the "factory" to choose… and create a object
    MqContextC srv = MqFactoryC.GetCalled(largs).New();

    try {
      srv.LinkCreate(largs);
      srv.ProcessEvent(MqWaitOnEventE.FOREVER);
    } catch (Throwable e) {
      srv.ErrorCatch(e);
    }
    srv.Exit();
  }
}