class Batsir::Acceptors::Acceptor

Attributes

cancellator[RW]
stage_name[RW]
transformer_queue[RW]

Public Class Methods

new(options = {}) click to toggle source
# File lib/batsir/acceptors/acceptor.rb, line 10
def initialize(options = {})
  options.each do |option, value|
    self.send("#{option}=", value)
  end
  @transformer_queue = []
end

Public Instance Methods

add_transformer(transformer) click to toggle source
# File lib/batsir/acceptors/acceptor.rb, line 17
def add_transformer(transformer)
  @transformer_queue << transformer
end
process_message_error(message, error) click to toggle source

This method is called after an error is thrown. Can be overridden to implement error handling. Returns a message

# File lib/batsir/acceptors/acceptor.rb, line 66
def process_message_error(message, error)
  message
end
start() click to toggle source

This method is called automatically when the stage is started, it is here that you set up the accepting logic. Make sure that somewhere within this logic the start_filter_chain(msg) is called to start actual processing.

Note that this method will be invoked asynchronously using the Celluloid actor semantics.

# File lib/batsir/acceptors/acceptor.rb, line 31
def start
  raise NotImplementedError.new
end
start_filter_chain(message) click to toggle source

When a message is accepted by an Acceptor, this method should be invoked with the received payload to start processing of the filter chain.

# File lib/batsir/acceptors/acceptor.rb, line 40
def start_filter_chain(message)
  klazz = Batsir::Registry.get(stage_name)
  message = transform(message)
  klazz.perform_async(message) if klazz
end
transform(message) click to toggle source

Call each of the transformers in the transformer_queue on the message, in order

# File lib/batsir/acceptors/acceptor.rb, line 50
def transform(message)
  transformer_queue.each do |transformer|
    begin
      message = transformer.transform(message)
    rescue Batsir::Errors::TransformError => e
      message = process_message_error(message, e)
    end
  end
  message
end