Module: ModernTimes::JMS::RequestWorker

Includes:
Worker
Defined in:
lib/modern_times/jms/request_worker.rb

Overview

Base Worker Class for any class that will be processing requests from queues and replying

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Attributes included from Worker

#destination_options, #error_count, #message, #session, #time_track

Attributes included from Base::Worker

#index, #name, #options, #thread

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Worker

#log_backtrace, #message_count, #start, #status, #stop, #to_s

Methods included from Base::Worker

#join, #setup, #start, #status, #stop

Instance Attribute Details

#marshalerObject (readonly)

Dummy requesting needs access to this



8
9
10
# File 'lib/modern_times/jms/request_worker.rb', line 8

def marshaler
  @marshaler
end

Class Method Details

.included(base) ⇒ Object



27
28
29
30
31
32
# File 'lib/modern_times/jms/request_worker.rb', line 27

def self.included(base)
  # The price we pay for including rather than extending
  base.extend(ModernTimes::Base::Worker::ClassMethods)
  base.extend(Worker::ClassMethods)
  base.extend(ClassMethods)
end

Instance Method Details

#initialize(opts = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/modern_times/jms/request_worker.rb', line 34

def initialize(opts={})
  super
  response_options = self.class.response_options || {}
  @marshal_type = (response_options[:marshal] || :ruby).to_s
  @marshaler    = MarshalStrategy.find(@marshal_type)
  # Time in msec until the message gets discarded, should be more than the timeout on the requestor side
  @time_to_live = response_options[:time_to_live]
  @persistent   = response_options[:persistent]
end

#perform(object) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/modern_times/jms/request_worker.rb', line 44

def perform(object)
  begin
    response = request(object)
  rescue Exception => e
    on_exception(e)
  else
    send_response(@marshal_type, @marshaler, response)
  end
  post_request(object)
rescue Exception => e
  ModernTimes.logger.error("Exception in send_response or post_request: #{e.message}")
  log_backtrace(e)
end

#post_request(object) ⇒ Object

Handle any processing that you want to perform after the reply



63
64
# File 'lib/modern_times/jms/request_worker.rb', line 63

def post_request(object)
end

#request(object) ⇒ Object



58
59
60
# File 'lib/modern_times/jms/request_worker.rb', line 58

def request(object)
  raise "#{self}: Need to override request method in #{self.class.name} in order to act on #{object}"
end