theLink 10.0
Loading...
Searching...
No Matches
Callback Signature List

List of all callback defined by rbmqmsgque

The callback have to be a Ruby proc or method

There a two different types of callback:

  1. A callback used to define a context
  2. A callback used to define a service

Callback signature

1. The *service-ctx* is the *context* for which the service was defined.
callback-args := service-ctx:MqContextC[in]
[static] def callback ( callback-args )
[instance] class YYY
def callback ( callback-args )
[class] class ZZZ
def self.callback ( callback-args )

There are 6 different types of callbacks :

type code self argument
procedure ... method(:callback) yes
other-class-method ... OtherClass.method(:callback) yes
other-instance-method ... OtherInstance.method(:callback) yes
own-class-method ... MyClass.method(:callback) yes
own-instance-method ... method(:callback) no
block ... block yes

Example from Callback.rb using MqServiceCreate with callback

require "rbmqmsgque"
include MqMsgque

# General rules for defining a callback in RUBY
# ---------------------------------------------
# 1.  A callback always begins with the "Object", either the "instanceObject" or the "classObject":
#       `Object.method(:Method)`
# 2.  If the callback is an "instanceMethod" of another instance, the callback is defined as:
#       `instanceObject.method(:instanceMethod)
# 3.  If the callback is an "instanceMethod" of its own instance, the callback is defined as:
#       `method(:instanceMethod)`
# 4.  If the callback is a "classMethod," the callback is defined as:
#       `classObject.method(classMethod)`

class OtherServerC
  @wht = ""
  def initialize(wht)
    @wht = wht
  end
  # The "otherInstanceService" require an extra argument, the "cbCtx".
  def otherInstanceService (cbCtx)
    cbCtx.Send("R","C",cbCtx.ReadSTR() + "-" + @wht + "-Other-Instance")
  end
  # The "otherClassService" require an extra argument, the "cbCtx".
  def self.otherClassService(cbCtx)
    cbCtx.Send("R","C",cbCtx.ReadSTR() + "-World-Other-Class")
  end
end 

# The "procService" require an extra argument, the "cbCtx".
def procService (cbCtx)
  cbCtx.Send("R","C",cbCtx.ReadSTR() + "-World-Proc")
end

# package-item
class CallbackC < MqContextC
  @otherCtx = nil

  # The "ownInstanceService" require no extra argument.
  def ownInstanceService
    Send("R","C",ReadSTR() + "-World-Own-Instance")
  end

  # The "ownClassService" require an extra argument, the "cbCtx".
  def self.ownClassService (cbCtx)
    cbCtx.Send("R","C",cbCtx.ReadSTR() + "-World-Own-Class")
  end

  # the "serverSetup" defines the test-services
  def serverSetup

    # 1. The "otherInstanceCallback" require an extra argument, the "otherCtx".
      ServiceCreate("HLW1",@otherCtx.method(:otherInstanceService))

    # 2. The "otherClassCallback" require NO extra argument.
      ServiceCreate("HLW2",OtherServerC.method(:otherClassService))

    # 3. The "ownInstanceCallback" require no extra argument.
      ServiceCreate("HLW3",method(:ownInstanceService))

    # 4. The "otherClassCallback" require NO extra argument.
      ServiceCreate("HLW4",CallbackC.method(:ownClassService))

    # 5. The "procCallback" require NO extra argument
      ServiceCreate("HLW5",method(:procService))
  end

  # factory startup (constructor)
  def initialize()
    super
    ConfigSetServerSetup(method(:serverSetup))
    @otherCtx = OtherServerC.new("World")   ; # just for test purpose
  end
end 

# ====================================================
# package-main

# create the "Callback" factory… and object
srv = MqFactoryC.Add(CallbackC).New()

begin
  srv.LinkCreate(ARGV)
  srv.ProcessEvent(MqWaitOnEventE::FOREVER)
rescue Exception => ex
  srv.ErrorCatch(ex)
ensure
  srv.Exit()
end

Example from MyServerCallback.rb using MqServiceCreate with a variation of callbacks

require "rbmqmsgque"
include MqMsgque

# GLOBAL or NAMESPACE proc
# The proc require the extra argument (ctx), the calling context.
def globalCB(ctx)
  ctx.SendSTART()
  ctx.SendSTR(ctx.ReadSTR() + " World1")
  ctx.SendRETURN()
end

# other class
class MySuper
  # other STATIC callback
  # The class-method require an extra argument (ctx), the calling context.
  # The callback is a list of TWO items, the CLASS and the class-METHOD
  # The METHOD can be from the CLASS itself or from a superclass of the CLASS or from an other CLASS
  def self.staticCB(ctx)
    ctx.SendSTART()
    ctx.SendSTR(ctx.ReadSTR() + " World2")
    ctx.SendRETURN()
  end
  # other INSTANCE callback
  # The class-method require an extra argument (ctx), the calling context.
  # The callback is a list of TWO items, the INSTANCE and the instance-METHOD
  def instanceCB(ctx)
    ctx.SendSTART()
    ctx.SendSTR(ctx.ReadSTR() + " World3")
    ctx.SendRETURN()
  end
end

# other INSTANCE as GLOBAL variable
$otherInstance = MySuper.new

# ------------------------------------------------------------------------------------

class MyServer < MqContextC

  # factory startup
  def initialize()
    super
    ConfigSetServerSetup(method(:ServerSetup))
  end

  # own CLASS callback (static)
  # the class-method require an extra argument (ctx), the calling context
  def self.myClassCB(ctx)
    ctx.SendSTART()
    ctx.SendSTR(ctx.ReadSTR() + " World5")
    ctx.SendRETURN()
  end

  # own INSTANCE callback (dynamic)
  # the instance-method require NO extra argument
  def myInstanceCB
    SendSTART()
    SendSTR(ReadSTR() + " World6")
    SendRETURN()
  end

  # define a service as link between the token "HLW?" and a callback.
  def ServerSetup
    ServiceCreate("HLW1", method(:globalCB))
    ServiceCreate("HLW2", MySuper.method(:staticCB))
    ServiceCreate("HLW3", $otherInstance.method(:instanceCB))
    ServiceCreate("HLW4", Proc.new {  |ctx|
      ctx.SendSTART()
      ctx.SendSTR(ctx.ReadSTR() + " World4")
      ctx.SendRETURN()
    })
    ServiceCreate("HLW5",MyServer.method(:myClassCB))
    ServiceCreate("HLW6",method(:myInstanceCB))
  end
end

# ====================================================
# package-main

# create the "MyServer" factory… and object
srv = MqFactoryC.Add(MyServer).New()

begin
  srv.LinkCreate(ARGV)
  srv.ProcessEvent(MqWaitOnEventE::FOREVER)
rescue Exception => ex
  srv.ErrorCatch(ex)
ensure
  srv.Exit()
end

Callbacks defined by rbmqmsgque

Global MqSendEND_AND_CALLBACK_RT (MK_RT mkrt, MQ_CTX const ctx, MQ_TOK const token, MqServiceCallbackF const fCall, MK_CBP callback, MqDataFreeF fFree, MK_TIME_T const timeout)
MqSendEND_AND_CALLBACK
Global MqSendEND_AND_SUB_RT (MK_RT mkrt, MQ_CTX const ctx, MQ_TOK const token, MqServiceCallbackF const fCall, MK_CBP callback, MqDataFreeF fFree, MK_TIME_T timeout)
MqSendEND_AND_SUB
Global MqServiceCreate_RT (MK_RT mkrt, MQ_CTX const ctx, MQ_TOK const token, MqServiceCallbackF const fCall, MK_CBP callback, MqDataFreeF fFree, MkMarkF fMark)
MqServiceCreate
Global MqSetupS::BgError
ConfigApi_MqBgErrorIF
Global MqSetupS::Event
ConfigApi_MqEventIF
Global MqSetupS::ServerCleanup
ConfigApi_MqServerCleanupIF
Global MqSetupS::ServerSetup
ConfigApi_MqServerSetupIF