Class: Navy::Officer

Inherits:
Rank
  • Object
show all
Defined in:
lib/navy/officer.rb

Instance Attribute Summary collapse

Attributes inherited from Rank

#after_fork, #after_stop, #before_fork, #before_stop, #current_stderr, #current_stdout, #heartbeat, #options, #orders, #orig_stderr, #orig_stdout, #patience, #pid, #post_fork, #preload, #reexec_pid, #respawn_limit, #respawn_limit_seconds, #stderr_path, #stdout_path, #timeout

Instance Method Summary collapse

Constructor Details

#initialize(captain, number, job) ⇒ Officer

Returns a new instance of Officer.



4
5
6
# File 'lib/navy/officer.rb', line 4

def initialize(captain, number, job)
  @captain, @number, @job = captain, number, job
end

Instance Attribute Details

#captainObject (readonly)

Returns the value of attribute captain.



3
4
5
# File 'lib/navy/officer.rb', line 3

def captain
  @captain
end

#jobObject (readonly)

Returns the value of attribute job.



3
4
5
# File 'lib/navy/officer.rb', line 3

def job
  @job
end

#numberObject

Returns the value of attribute number.



2
3
4
# File 'lib/navy/officer.rb', line 2

def number
  @number
end

#officer_pidObject

Returns the value of attribute officer_pid.



2
3
4
# File 'lib/navy/officer.rb', line 2

def officer_pid
  @officer_pid
end

Instance Method Details

#==(other_number) ⇒ Object



8
9
10
# File 'lib/navy/officer.rb', line 8

def ==(other_number)
  @number == other_number
end

#loggerObject



12
13
14
# File 'lib/navy/officer.rb', line 12

def logger
  captain.logger
end

#startObject



16
17
18
19
20
21
22
23
# File 'lib/navy/officer.rb', line 16

def start
  self.officer_pid = $$
  proc_name "(#{captain.label}) officer[#{number}]"
  (job.respond_to?(:arity) && job.arity == 0) ? job.call : job.call(self)
rescue => e
  Navy.log_error(logger, "(#{captain.label}) officer[#{number}] loop error", e) rescue nil
  exit!
end