Class: Child
Instance Attribute Summary collapse
-
#from ⇒ Object
status is one of :idle, :connect, :close, :exit.
-
#pid ⇒ Object
status is one of :idle, :connect, :close, :exit.
-
#to ⇒ Object
status is one of :idle, :connect, :close, :exit.
Attributes inherited from Forkme
#child_count, #max_forks, #on_child_exit_blk, #on_child_start_blk, #suppress_exceptions
Instance Method Summary collapse
- #active? ⇒ Boolean
- #close ⇒ Object
- #event(s) ⇒ Object
- #exit ⇒ Object
- #idle? ⇒ Boolean
-
#initialize(pid, from, to) ⇒ Child
constructor
A new instance of Child.
Methods inherited from Forkme
#interrupt, logger, logger=, #on_child_exit, #on_child_start, start, #start, #stop, #terminate
Methods included from DefaultLogger
Constructor Details
#initialize(pid, from, to) ⇒ Child
Returns a new instance of Child.
2 3 4 5 |
# File 'lib/forkme/child.rb', line 2 def initialize(pid, from, to) @pid, @from, @to = pid, from, to @status = :idle end |
Instance Attribute Details
#from ⇒ Object
status is one of :idle, :connect, :close, :exit
8 9 10 |
# File 'lib/forkme/child.rb', line 8 def from @from end |
#pid ⇒ Object
status is one of :idle, :connect, :close, :exit
8 9 10 |
# File 'lib/forkme/child.rb', line 8 def pid @pid end |
#to ⇒ Object
status is one of :idle, :connect, :close, :exit
8 9 10 |
# File 'lib/forkme/child.rb', line 8 def to @to end |
Instance Method Details
#active? ⇒ Boolean
44 45 46 |
# File 'lib/forkme/child.rb', line 44 def active?() @status == :idle or @status == :connect end |
#close ⇒ Object
29 30 31 32 |
# File 'lib/forkme/child.rb', line 29 def close() @to.close unless @to.closed? @status = :close end |
#event(s) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/forkme/child.rb', line 10 def event(s) if s == nil then #Forkme.logger.debug "p: child #{pid} terminated" self.exit else case s.chomp when "connect" then @status = :connect when "disconnect" then @status = :idle else begin Forkme.logger.error "unknown status: #{s}" rescue NoMethodError end return "unknown status: #{s}" end end end |
#exit ⇒ Object
34 35 36 37 38 |
# File 'lib/forkme/child.rb', line 34 def exit() @from.close unless @from.closed? @to.close unless @to.closed? @status = :exit end |
#idle? ⇒ Boolean
40 41 42 |
# File 'lib/forkme/child.rb', line 40 def idle?() @status == :idle end |