Class: Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Controller

Returns a new instance of Controller.



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/controller.rb', line 38

def initialize(params = {})
  @drb_server_host  = params[:drb_server_host]  || external_interface
  @drb_server_port  = params[:drb_server_port]  || 0
  @ring_server_host = params[:ring_server_host] || external_interface
  @ring_server_port = params[:ring_server_port] || Rinda::Ring_PORT
  @acls = params[:acls]

  logfile = params[:logfile] || STDOUT
  @log  = Logger.new(logfile, 'daily')
  @log.level = params[:loglevel] || Logger::INFO
  @log.datetime_format = "%Y-%m-%d %H:%M:%S "
end

Instance Attribute Details

#drb_server_uriObject

Returns the value of attribute drb_server_uri.



36
37
38
# File 'lib/controller.rb', line 36

def drb_server_uri
  @drb_server_uri
end

#ring_server_uriObject

Returns the value of attribute ring_server_uri.



36
37
38
# File 'lib/controller.rb', line 36

def ring_server_uri
  @ring_server_uri
end

Instance Method Details

#startObject

Start a new tuplespace on the ring server



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/controller.rb', line 53

def start
  # create a parent Tuple Space
  tuple_space = Rinda::TupleSpace.new

  # Setup the security--remember to call before DRb.start_service()
  DRb.install_acl(ACL.new(@acls))

  # start the DRb Server
  drb_server = DRb.start_service(
    "druby://#{@drb_server_host}:#{@drb_server_port}", tuple_space)

  # obtain DRb Server uri
  @drb_server_uri = drb_server.uri
  @log.info("Controller started on : #{@drb_server_uri}")

  # start the Ring Server
  ring_server = Rinda::RingServer.new(tuple_space,
    @ring_server_host, @ring_server_port)

  # obtain Ring Server uri
  @ring_server_uri = ring_server.uri
  @log.debug("Ring Server started   : #{@ring_server_uri}")

  # abort all threads on an exception
  Thread.abort_on_exception = true

  # wait for explicit stop via ctrl-c
  DRb.thread.join if __FILE__ == $0
end

#stopObject

Stop the controller by shutting down the DRb service



85
86
87
88
# File 'lib/controller.rb', line 85

def stop
  DRb.stop_service
  @log.info("Controller stopped on : #{@drb_server_uri}")
end