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

To run the filter test, a first client, one or more filters and a final server are created. All are connected to the rbmqmsgque 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/ruby/Filter6.rb
#:   @brief        Filter6.rb - 20 Oct 2022 - aotto1968
#:   @copyright    (C) NHI - #1 - Project - Group
#:                 This software has NO permissions to copy,
#:                 please contact AUTHOR for additional information
#:   @version      eca2a2ee05f368470d4127d36503bd9e26063147
#:   @date         Thu Oct 20 14:18:44 2022 +0200
#:   @author       aotto1968 <aotto1968@t-online.de>
#:

require "rbmqmsgque"
include PyMsgque::MkKernel
include PyMsgque::MqMsgque

class Filter6 < MqContextC
  #attr_accessor :fh
  def initialize()
    super()
    ConfigSetIgnoreExit(true)
    ConfigSetServerSetup(method(:ServerSetup))
    ConfigSetServerCleanup(method(:ServerCleanup))
    ConfigSetEvent(method(:Event))
    @fh = nil
  end
  def ServerCleanup
    @fh.Dispose if @fh != nil
    @fh = nil
  end
  # [filter_service_example]
  def ServerSetup
    ftr = SlaveGetFilter()
    ServiceCreate(      "LOGF",  method(:LOGF))
    ServiceCreate(      "EXIT",  method(:EXIT))
    ServiceCreate(      "SOEX",  method(:SOEX))
    ServiceCreate(      "+ALL",  method(:FilterIn))
    ServiceStorage(     "PRNT")
    ServiceStorage(     "PRN2")
    ftr.ServiceCreate(  "WRIT",  method(:WRIT))
    ServiceCreate(      "WRIT",  method(:WRIT))
    ftr.ServiceProxy(   "WRT2",  MqSlaveE::MASTER)
  end
  # [filter_service_example]
  def ErrorWrite
    err = ErrorDEFAULT();
    @fh.WriteC("ERROR: " + err.GetText())
    err.Reset()
  end
  def LOGF
    ftr = SlaveGetFilter()
    if ftr.ConfigGetName() =~ /^(?:Filter6-1|Filter6|fs1.*)$/ then
      @fh =  MkLogFileC.Open(self,ReadC())
    else
      ProxyForward(ftr)
    end
    SendRETURN()
  end
  def WRIT(ctx)
    if ConfigGetName() =~ /^(?:Filter6-1|Filter6|fs1.*)$/ then
      @fh.WriteC(ctx.ReadC())
    else
      ctx.ProxyForward(self)
    end
    ctx.SendRETURN()
  end
  def EXIT
    #exit()
    Exit()
  end
  def SOEX
    ErrorSetEXIT()
  end
  def FilterIn
    StorageExport()
    SendRETURN()
  end
  def Event
    if StorageCount() == 0 then
      ErrorDEFAULT().SetCONTINUE()
    else
      id = 0
      begin
	ftr = SlaveGetFilter()
	id = StorageImport()
        begin
          ProxyForward(ftr)
        rescue MkExceptionC => ex
          if StorageErrCnt(id) <= 3
            StorageDecrRef(id)
            return
          else
            raise
          end
        end
      rescue Exception => ex
        ErrorCatch(ex)
        ErrorWrite()
      end
      StorageDelete(id)
    end
  end
end

# [error_example]
srv = MqFactoryC.Add(Filter6).New()
begin
  srv.LinkCreate(ARGV)
  srv.ProcessEvent(MqWaitOnEventE::FOREVER)
rescue Exception => ex
  srv.ErrorCatch(ex)
ensure
  srv.Exit()
end
# [error_example]