Class: ScoutAgent::Order

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_agent/order.rb,
lib/scout_agent/order/check_in_order.rb,
lib/scout_agent/order/snapshot_order.rb

Direct Known Subclasses

CheckInOrder, SnapshotOrder

Defined Under Namespace

Classes: CheckInOrder, SnapshotOrder

Constant Summary collapse

ORDERS_DIR =
LIB_DIR + "order"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, match_details) ⇒ Order

Returns a new instance of Order.



49
50
51
52
# File 'lib/scout_agent/order.rb', line 49

def initialize(message, match_details)
  @message       = message
  @match_details = match_details
end

Instance Attribute Details

#match_detailsObject (readonly)

Returns the value of attribute match_details.



54
55
56
# File 'lib/scout_agent/order.rb', line 54

def match_details
  @match_details
end

#messageObject (readonly)

Returns the value of attribute message.



54
55
56
# File 'lib/scout_agent/order.rb', line 54

def message
  @message
end

Class Method Details

.can_handle?(message, modified_body = nil) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
# File 'lib/scout_agent/order.rb', line 31

def self.can_handle?(message, modified_body = nil)
  subclasses.each do |order|
    if match_details = order.match?(message, modified_body)
      return order.new(message, match_details)
    end
  end
  nil
end

.inherited(order) ⇒ Object



20
21
22
# File 'lib/scout_agent/order.rb', line 20

def self.inherited(order)
  subclasses << order
end

.load_allObject



24
25
26
27
28
29
# File 'lib/scout_agent/order.rb', line 24

def self.load_all
  ORDERS_DIR.each_entry do |order|
    require ORDERS_DIR + order unless order.basename.to_s[0] == ?.
  end
  subclasses
end

.logObject



12
13
14
# File 'lib/scout_agent/order.rb', line 12

def self.log
  @log ||= WireTap.new(nil)
end

.log=(log) ⇒ Object



8
9
10
# File 'lib/scout_agent/order.rb', line 8

def self.log=(log)
  @log = log
end

.master_agentObject



45
46
47
# File 'lib/scout_agent/order.rb', line 45

def self.master_agent
  @master_agent ||= IDCard.new(:master)
end

.match?(message, modified_body = nil) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
# File 'lib/scout_agent/order.rb', line 40

def self.match?(message, modified_body = nil)
  const_defined?(:MATCH_RE) and
  const_get(:MATCH_RE).match(modified_body || message.body)
end

.subclassesObject



16
17
18
# File 'lib/scout_agent/order.rb', line 16

def self.subclasses
  @subclasses ||= Array.new
end

Instance Method Details

#executeObject

Raises:

  • (NotImplementedError)


60
61
62
63
# File 'lib/scout_agent/order.rb', line 60

def execute
  raise NotImplementedError,
        "Subclasses must override ScoutAgent::Order#execute()."
end

#logObject



56
57
58
# File 'lib/scout_agent/order.rb', line 56

def log
  Order.log
end

#notify_masterObject



65
66
67
68
69
70
# File 'lib/scout_agent/order.rb', line 65

def notify_master
  self.class.master_agent.signal("ALRM")
rescue Exception  # unable to signal process
  # do nothing:  process will catch up when it restarts
  log.warn("Unable to signal master process.")
end