Class: Pione::Front::BasicFront

Inherits:
PioneObject
  • Object
show all
Includes:
DRbUndumped
Defined in:
lib/pione/front/basic-front.rb

Overview

This is base class for all PIONE front classes. PIONE fronts exist in each command and behave as remote interface.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(port) ⇒ BasicFront

Creates a front server as druby’s service.



13
14
15
16
17
# File 'lib/pione/front/basic-front.rb', line 13

def initialize(port)
  @uri = start_service(port, {}) # port is number or range
  @attrs = {}
  @child = {}
end

Instance Attribute Details

#attrsObject (readonly)

Returns the value of attribute attrs.



9
10
11
# File 'lib/pione/front/basic-front.rb', line 9

def attrs
  @attrs
end

#childObject (readonly)

child process table



10
11
12
# File 'lib/pione/front/basic-front.rb', line 10

def child
  @child
end

#uriObject (readonly)

front server’s URI string



8
9
10
# File 'lib/pione/front/basic-front.rb', line 8

def uri
  @uri
end

Instance Method Details

#[](name) ⇒ Object



24
25
26
# File 'lib/pione/front/basic-front.rb', line 24

def [](name)
  @attrs[name]
end

#[]=(name, val) ⇒ Object



28
29
30
# File 'lib/pione/front/basic-front.rb', line 28

def []=(name, val)
  @attrs[name] = val
end

#add_child(pid, front_uri) ⇒ Object

Add child process.



33
34
35
# File 'lib/pione/front/basic-front.rb', line 33

def add_child(pid, front_uri)
  @child[pid] = front_uri
end

#pidObject

Return PID of the process.



20
21
22
# File 'lib/pione/front/basic-front.rb', line 20

def pid
  Process.pid
end

#remove_child(pid) ⇒ Object

Delete child process.



38
39
40
# File 'lib/pione/front/basic-front.rb', line 38

def remove_child(pid)
  @child.delete(pid)
end

#terminateObject

Terminate the front server. This method assumes to be not called from other process. Note that front servers have no responsibility of killing child processes.



45
46
47
# File 'lib/pione/front/basic-front.rb', line 45

def terminate
  DRb.stop_service
end

#terminate_commandObject

Terminate the command. This is a nonblocking method because callee process cannot tell its termination to caller, so it returns true immediately.



52
53
54
55
# File 'lib/pione/front/basic-front.rb', line 52

def terminate_command
  Thread.new {Global.command.terminate}
  return true
end