gomqmsgque 9.0
Loading...
Searching...
No Matches
Example: Filter6

Documentation of the Filter6 tool used for trans2.test.

INTRODUCTION

The Filer6 tool is used to test the filter-feature of gomqmsgque.

To run the filter test, a first client, one or more filters and a final server are created. All are connected to the gomqmsgque protocol.

The trans2.test carries out common filter tests and special stress tests. A stress test is performed by exiting one or more filters or servers and observing the response and behavior when reconnecting.

The GOAL for this test is:

CODE filter

/**
 *   @file         example/go/Filter6.go
 *   @brief        Filter6.go - 18 Apr 2023 - aotto1968
 *   @copyright    (C) NHI - #1 - Project - Group
 *                 This software has NO permissions to copy,
 *                 please contact AUTHOR for additional information
 *   @version      614a1e551abaa613cb635c95181a52afb9f8cf34
 *   @date         Tue Apr 18 23:23:15 2023 +0200
 *   @author       aotto1968 <aotto1968@t-online.de>
 */

package main

import (
  . "gomsgque/mkkernel"
  . "gomsgque/mqmsgque"
    "os"
    "regexp"
)

type Filter6 struct {
  MqContextC
  FH	*MkLogFileC
  rgx   *regexp.Regexp
}

func Filter6_Factory(tmpl MqContextCI) MqFactoryI {
  ret := new(Filter6)
  ret.Init(tmpl, ret)
  ret.rgx,_ = regexp.Compile("^(?:Filter6-1|Filter6|fs1.*)$")
  return ret
}

func (this *Filter6) ErrorWrite() {
  err := this.ErrorDEFAULT()
  this.FH.WriteC("ERROR: " + err.GetText())
  err.Reset_0()
}

type LOGF Filter6
  func (this *LOGF) Call() {
    ftr := this.SlaveGetFilter()
    if this.rgx.MatchString(ftr.ConfigGetName()) {
      this.FH = MkLogFileOpen(this,this.ReadC())
    } else {
      this.ProxyForward_1(ftr)
    }
    this.SendRETURN()
  }

type WRIT Filter6
  func (this *WRIT) Call(ctx *MqContextC) {
    master := ctx.SlaveGetMaster().GetSelf().(*Filter6)
    if master.rgx.MatchString(master.ConfigGetName()) {
      master.FH.WriteC(ctx.ReadC())
    } else {
      ctx.ProxyForward_1(master)
    }
    ctx.SendRETURN()
  }

type EXIT Filter6
  func (this *EXIT) Call() {
    this.Exit_0()
  }

type SOEX Filter6
  func (this *SOEX) Call() {
    this.ErrorDEFAULT().SetEXIT_0()
  }

type ALLS Filter6
  func (this *ALLS) Call() {
    this.StorageExport()
    this.SendRETURN()
  }

func (this *Filter6) proxyForward(ftr *MqContextC, Id int32) {
  defer func() {
    if x := recover(); x != nil {
      if _,ok := x.(*MkExceptionC); ok {
        errCnt := this.StorageErrCnt(Id)
        if errCnt <= 3 {
          this.StorageDecrRef(Id)
          return
        } else {
          panic(x)
        }
      } else {
        panic(x)
      }
    }
  }()
  this.ProxyForward_1(ftr)
  this.StorageDelete(&Id)
}

func (this *Filter6) Event() {
  if (this.StorageCount() <= 0) {
    this.ErrorDEFAULT().SetCONTINUE()
  } else {
    Id := this.StorageImport_0()
    defer func() {
      if x := recover(); x != nil {
	this.ErrorCatch_1(x)
        this.ErrorWrite()
        this.StorageDelete(&Id)
      }
    }()
    ftr := this.SlaveGetFilter()
    this.proxyForward(ftr, Id)
  }
}

func (this *Filter6) ServerCleanup() {
  if (this.FH != nil) {
    this.FH.Dispose()
    this.FH = nil
  }
}

/// [filter_service_example]
func (this *Filter6) ServerSetup() {
  ftr := this.SlaveGetFilter().GetSelf().(MqContextCI).GetMqContextC()
  this.ServiceCreate   ("LOGF",  (*LOGF)(this))
  this.ServiceCreate   ("EXIT",  (*EXIT)(this))
  this.ServiceCreate   ("SOEX",  (*SOEX)(this))
  this.ServiceCreate   ("+ALL",  (*ALLS)(this))
  this.ServiceStorage  ("PRNT")
  this.ServiceStorage  ("PRN2")
  ftr.ServiceCreate    ("WRIT",  (*WRIT)(this))
  this.ServiceCreate   ("WRIT",  (*WRIT)(this))
  ftr.ServiceProxy     ("WRT2",  MQ_SLAVE_MASTER)
}
/// [filter_service_example]

/// [error_example]
func main() {
  srv := MqFactoryAdd(Filter6_Factory, "Filter6").New()
  defer func() {
    if x := recover(); x != nil {
      srv.ErrorCatch_1(x)
    }
    srv.Exit_0()
  }()
  srv.ConfigSetIgnoreExit(true)
  srv.LinkCreateVC(os.Args)
  srv.ProcessEvent_1(MQ_WAIT_FOREVER)
}
/// [error_example]