vbmqmsgque 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 vbmqmsgque.

To run the filter test, a first client, one or more filters and a final server are created. All are connected to the vbmqmsgque 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

REM
REM   @file         example/vb/Filter6.vb
REM   @brief        Filter6.vb - 28 Dec 2022 - aotto1968
REM   @copyright    (C) NHI - #1 - Project - Group
REM                 This software has NO permissions to copy,
REM                 please contact AUTHOR for additional information
REM   @version      58c0906861433dfd14a652ce3c9dcc4185d054e6
REM   @date         Wed Dec 28 15:20:47 2022 +0100
REM   @author       aotto1968 <aotto1968@t-online.de>
REM

Option Infer On

Imports System
Imports System.IO
Imports System.Collections.Generic
Imports System.Text.RegularExpressions
Imports csmsgque.mkkernel
Imports csmsgque.mqmsgque

Public Module example
  Private Class Filter6
    Inherits MqContextC
    Implements IServerSetup
    Implements IServerCleanup
    Implements IEvent

    Dim rgx As Regex = Nothing
    Dim FH As MkLogFileC = Nothing

    ' constructor
    Public Sub New(Optional ByVal tmpl As MqContextC = Nothing)
      MyBase.New(tmpl)
      ConfigSetIgnoreExit(true)
      rgx = New Regex("^(?:Filter6-1|Filter6|fs1.*)$")
    End Sub

    Private Sub ErrorWrite()
      Dim err As MkErrorC = ErrorDEFAULT()
      FH.WriteC("ERROR: " + err.GetText())
      err.Reset()
    End Sub

    Private Sub LOGF()
      Dim ftr As Filter6 = SlaveGetFilter()
      If (rgx.IsMatch(ftr.ConfigGetName()))
        FH = MkLogFileC.Open(Me, ReadC())
      Else
        ProxyForward(ftr)
      End If
      SendRETURN()
    End Sub

    Private Shared Sub WRIT(ByVal ctx As MqContextC)
      Dim master As Filter6 = ctx.SlaveGetMaster()
      If (master.rgx.IsMatch(master.ConfigGetName()))
        master.FH.WriteC(ctx.ReadC())
      Else
        ctx.ProxyForward(master)
      End If
      ctx.SendRETURN()
    End Sub

    Private Sub EXI2()
      [Exit]()
    End Sub

    Private Sub SOEX()
      ErrorDEFAULT().SetEXIT()
    End Sub

    Private Sub FilterIn()
      StorageExport()
      SendRETURN()
    End Sub

    Private Sub EventF() Implements IEvent.Event
      If StorageCount() = 0 Then
	ErrorDEFAULT().SetCONTINUE()
      Else
        Dim Id As Integer = 0
        Try
          Dim ftr As MqContextC = SlaveGetFilter()
          Id = StorageImport()
          Try
            ProxyForward(ftr)
          Catch ex As MkExceptionC
            If (StorageErrCnt(Id) <= 3)
              StorageDecrRef(Id)
              return
            Else
              Throw ex
            End If
          Catch ex As Exception
            Throw ex
          End Try
        Catch ex As Exception
          ErrorCatch(ex)
          ErrorWrite()
        End Try
        Id = StorageDelete(Id)
      End If
    End Sub

    Private Sub ServerCleanup() Implements IServerCleanup.ServerCleanup
      If (FH Is Nothing) 
        return
      End If
      FH.Dispose()
      FH = Nothing
    End Sub

    ' [filter_service_example]
    Private Sub ServerSetup() Implements IServerSetup.ServerSetup
      Dim ftr As MqContextC = SlaveGetFilter()
      ServiceCreate      ("LOGF",  AddressOf LOGF)
      ServiceCreate      ("EXIT",  AddressOf EXI2)
      ServiceCreate      ("SOEX",  AddressOf SOEX)
      ServiceCreate      ("+ALL",  AddressOf FilterIn)
      ServiceStorage     ("PRNT")
      ServiceStorage     ("PRN2")
      ftr.ServiceCreate  ("WRIT",  AddressOf WRIT)
      ServiceCreate      ("WRIT",  AddressOf WRIT)
      ftr.ServiceProxy   ("WRT2",  CType(MqSlaveE.MASTER, Integer))
    End Sub
    ' [filter_service_example]
  End Class

  ' [error_example]
  Sub Main(ByVal argv() As String)
    Dim srv As MqContextC = MqFactoryC.Add(GetType(Filter6)).[New]()
    Try
      srv.LinkCreate(argv)
      srv.ProcessEvent(MqWaitOnEventE.FOREVER)
    Catch ex As Exception
      srv.ErrorCatch(ex)
    Finally
      srv.Exit()
    End Try
  End Sub
  ' [error_example]
End Module