Class: Prosody::EventHandler

Inherits:
Object
  • Object
show all
Extended by:
ErrorClassification
Defined in:
lib/prosody/handler.rb

Overview

Abstract base class for handling incoming messages and timers from Prosody. Subclasses must implement ‘#on_message` to process received messages. Subclasses may implement `#on_timer` to process timer events. They may also use `permanent` or `transient` decorators to control retry logic.

Examples:

class MyHandler < Prosody::EventHandler
  extend Prosody::ErrorClassification

  permanent :on_message, ArgumentError
  transient :on_message, RuntimeError
  permanent :on_timer, ArgumentError
  transient :on_timer, RuntimeError

  def on_message(context, message)
    # Process message...
  end

  def on_timer(context, trigger)
    # Process timer event...
  end
end

Instance Method Summary collapse

Methods included from ErrorClassification

permanent, transient

Instance Method Details

#on_message(context, message) ⇒ void

This method returns an undefined value.

Process a single message received from Prosody. This method must be implemented by subclasses to define custom message handling logic.

Parameters:

  • context (Context)

    the message context

  • message (Message)

    the message payload

Raises:

  • (NotImplementedError)

    if not overridden by subclass



162
163
164
# File 'lib/prosody/handler.rb', line 162

def on_message(context, message)
  raise NotImplementedError, "Subclasses must implement #on_message"
end

#on_timer(context, timer) ⇒ void

This method returns an undefined value.

Process a timer event when it fires. This method must be implemented by subclasses to handle scheduled timer events if they can fire.

Parameters:

  • context (Context)

    the event context

  • timer (Timer)

    the timer containing key, time, and span

Raises:

  • (NotImplementedError)


173
174
175
# File 'lib/prosody/handler.rb', line 173

def on_timer(context, timer)
  raise NotImplementedError, "Subclasses must implement #on_timer"
end