Class: RSMP::Node

Inherits:
Object
  • Object
show all
Includes:
EventSource, Logging, Task
Defined in:
lib/rsmp/node/node.rb

Overview

Base class for sites and supervisors.

Direct Known Subclasses

Site, Supervisor

Instance Attribute Summary collapse

Attributes included from EventSource

#event_receivers

Instance Method Summary collapse

Methods included from EventSource

#add_event_receiver, #initialize_event_source, #publish_event, #remove_event_receiver

Methods included from Task

#initialize_task, #restart, #run, #start, #stop, #stop_task, #task_status, #wait, #wait_for_condition, #wait_for_condition!, #wait_for_termination

Methods included from Logging

#initialize_logging, #log

Constructor Details

#initialize(options = {}) ⇒ Node



10
11
12
13
14
15
16
17
# File 'lib/rsmp/node/node.rb', line 10

def initialize(options = {})
  initialize_logging options
  initialize_task
  initialize_event_source
  @deferred = []
  @clock = Clock.new
  @collect = options[:collect]
end

Instance Attribute Details

#archiveObject (readonly)

Returns the value of attribute archive.



8
9
10
# File 'lib/rsmp/node/node.rb', line 8

def archive
  @archive
end

#clockObject (readonly)

Returns the value of attribute clock.



8
9
10
# File 'lib/rsmp/node/node.rb', line 8

def clock
  @clock
end

#collectorObject (readonly)

Returns the value of attribute collector.



8
9
10
# File 'lib/rsmp/node/node.rb', line 8

def collector
  @collector
end

#deferredObject (readonly)

Returns the value of attribute deferred.



8
9
10
# File 'lib/rsmp/node/node.rb', line 8

def deferred
  @deferred
end

#loggerObject (readonly)

Returns the value of attribute logger.



8
9
10
# File 'lib/rsmp/node/node.rb', line 8

def logger
  @logger
end

#taskObject (readonly)

Returns the value of attribute task.



8
9
10
# File 'lib/rsmp/node/node.rb', line 8

def task
  @task
end

Instance Method Details

#authorObject



60
61
62
# File 'lib/rsmp/node/node.rb', line 60

def author
  site_id
end

#check_required_settings(settings, required) ⇒ Object

Raises:

  • (ArgumentError)


52
53
54
55
56
57
58
# File 'lib/rsmp/node/node.rb', line 52

def check_required_settings(settings, required)
  raise ArgumentError, 'Settings is empty' unless settings

  required.each do |setting|
    raise ArgumentError, "Missing setting: #{setting}" unless settings.include? setting.to_s
  end
end

#clear_deferredObject



48
49
50
# File 'lib/rsmp/node/node.rb', line 48

def clear_deferred
  @deferred.clear
end

#defer(key, item = nil) ⇒ Object



34
35
36
# File 'lib/rsmp/node/node.rb', line 34

def defer(key, item = nil)
  @deferred << [key, item]
end

#do_deferred(key, item = nil) ⇒ Object



46
# File 'lib/rsmp/node/node.rb', line 46

def do_deferred(key, item = nil); end

#inspectObject



19
20
21
# File 'lib/rsmp/node/node.rb', line 19

def inspect
  "#<#{self.class.name}:#{object_id} id: #{site_id}}>"
end

#nowObject



23
24
25
# File 'lib/rsmp/node/node.rb', line 23

def now
  clock.now
end

#process_deferredObject



38
39
40
41
42
43
44
# File 'lib/rsmp/node/node.rb', line 38

def process_deferred
  cloned = @deferred.clone # clone in case do_deferred restarts the current task
  @deferred.clear
  cloned.each do |pair|
    do_deferred pair.first, pair.last
  end
end

#stop_subtasksObject

stop proxies, then call super



28
29
30
31
32
# File 'lib/rsmp/node/node.rb', line 28

def stop_subtasks
  @proxies.each(&:stop)
  @proxies.clear
  super
end