Class: DTR::Configuration

Inherits:
Object show all
Includes:
Service::Rinda, Singleton
Defined in:
lib/dtr/shared/configuration.rb

Overview

DTR Configuration includes:

For both master & agent process:
  * broadcast_list: broadcast ip list for looking for dtr services(agent and DTR master rinda server).
  * group: grouping agents for specific usage, master process should specify same group for catching agents to work
For master process:
  * rinda_server_port: DTR would automatically detect unused port for master rinda server. The default port is 3344.
  * master_heartbeat_interval: master process heartbeat for keeping agents working. The default is 10 sec.
For agent process:
  * agent_listen_port: agent listen master process command port, the default port is 7788.
  * follower_listen_heartbeat_timeout: agents would be going to sleep if listening master heartbeat timeout. The default is 15 sec.

All configurations except rinda_server_port would be stored into pstore file .dtr_env_pstore in the DTR process launching directory.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Service::Rinda

#lookup, #lookup_ring, #start_service, #stop_service

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



47
48
49
# File 'lib/dtr/shared/configuration.rb', line 47

def initialize
  load
end

Instance Attribute Details

#agent_listen_portObject

Returns the value of attribute agent_listen_port.



44
45
46
# File 'lib/dtr/shared/configuration.rb', line 44

def agent_listen_port
  @agent_listen_port
end

#broadcast_listObject

Returns the value of attribute broadcast_list.



44
45
46
# File 'lib/dtr/shared/configuration.rb', line 44

def broadcast_list
  @broadcast_list
end

#follower_listen_heartbeat_timeoutObject

Returns the value of attribute follower_listen_heartbeat_timeout.



44
45
46
# File 'lib/dtr/shared/configuration.rb', line 44

def follower_listen_heartbeat_timeout
  @follower_listen_heartbeat_timeout
end

#groupObject

Returns the value of attribute group.



45
46
47
# File 'lib/dtr/shared/configuration.rb', line 45

def group
  @group
end

#master_heartbeat_intervalObject

Returns the value of attribute master_heartbeat_interval.



44
45
46
# File 'lib/dtr/shared/configuration.rb', line 44

def master_heartbeat_interval
  @master_heartbeat_interval
end

#rinda_server_portObject

Returns the value of attribute rinda_server_port.



44
45
46
# File 'lib/dtr/shared/configuration.rb', line 44

def rinda_server_port
  @rinda_server_port
end

Instance Method Details

#loadObject



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/dtr/shared/configuration.rb', line 51

def load
  store = EnvStore.new
  # always have 'localhost' in broadcast_list, for our master process would start rinda server locally,
  # and dtr should work well on local machine when the machine leaves dtr grid network environment.
  @broadcast_list = ['localhost'].concat(store[:broadcast_list] || []).uniq
  @rinda_server_port = 3344
  @agent_listen_port = store[:agent_listen_port] || 7788
  @master_heartbeat_interval = store[:master_heartbeat_interval] || 10
  @follower_listen_heartbeat_timeout =  store[:follower_listen_heartbeat_timeout] || 15
  @group = store[:group]
end

#lookup_ring_anyObject



94
95
96
# File 'lib/dtr/shared/configuration.rb', line 94

def lookup_ring_any
  @ring ||= __lookup_ring_any__
end

#saveObject



63
64
65
66
67
68
69
70
# File 'lib/dtr/shared/configuration.rb', line 63

def save
  store = EnvStore.new
  store[:broadcast_list] = @broadcast_list
  store[:agent_listen_port] = @agent_listen_port
  store[:master_heartbeat_interval] = @master_heartbeat_interval
  store[:follower_listen_heartbeat_timeout] = @follower_listen_heartbeat_timeout
  store[:group] = @group
end

#with_rinda_server(&block) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/dtr/shared/configuration.rb', line 76

def with_rinda_server(&block)
  DTR.do_println("Booting DTR service")
  start_service
  DTR.info {'-- Booting DTR Rinda server'}
  loop do
    begin
      Rinda::RingServer.new Rinda::TupleSpace.new, @rinda_server_port
      break
    rescue Errno::EADDRINUSE
      @rinda_server_port += 1
    end
  end
  DTR.info {"-- DTR Rinda server started on port #{@rinda_server_port}"}
  block.call
ensure
  stop_service rescue nil
end