Class: Zeus::Server::ForkedProcess
- Inherits:
-
Object
- Object
- Zeus::Server::ForkedProcess
- Defined in:
- lib/zeus/server/forked_process.rb
Overview
base class for Stage and Acceptor
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
Instance Method Summary collapse
- #after_notify ⇒ Object
- #after_setup ⇒ Object
- #before_setup ⇒ Object
- #descendent_acceptors ⇒ Object
-
#initialize(server) ⇒ ForkedProcess
constructor
A new instance of ForkedProcess.
- #newly_loaded_features ⇒ Object
- #notify_feature(feature) ⇒ Object
- #notify_new_features ⇒ Object
- #notify_started ⇒ Object
- #notify_terminated ⇒ Object
- #process_type ⇒ Object
-
#run(close_parent_sockets = false) ⇒ Object
TODO: This just got really ugly and needs a refactor more than ever.
- #runloop! ⇒ Object
- #setup_forked_process(close_parent_sockets) ⇒ Object
Constructor Details
#initialize(server) ⇒ ForkedProcess
Returns a new instance of ForkedProcess.
8 9 10 |
# File 'lib/zeus/server/forked_process.rb', line 8 def initialize(server) @server = server end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/zeus/server/forked_process.rb', line 6 def name @name end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
7 8 9 |
# File 'lib/zeus/server/forked_process.rb', line 7 def pid @pid end |
Instance Method Details
#after_notify ⇒ Object
75 76 |
# File 'lib/zeus/server/forked_process.rb', line 75 def after_notify end |
#after_setup ⇒ Object
63 64 |
# File 'lib/zeus/server/forked_process.rb', line 63 def after_setup end |
#before_setup ⇒ Object
60 61 |
# File 'lib/zeus/server/forked_process.rb', line 60 def before_setup end |
#descendent_acceptors ⇒ Object
16 17 18 |
# File 'lib/zeus/server/forked_process.rb', line 16 def descendent_acceptors raise NotImplementedError end |
#newly_loaded_features ⇒ Object
51 52 53 54 |
# File 'lib/zeus/server/forked_process.rb', line 51 def newly_loaded_features old_features = defined?($previously_loaded_features) ? $previously_loaded_features : [] ($LOADED_FEATURES + @server.extra_features) - old_features end |
#notify_feature(feature) ⇒ Object
12 13 14 |
# File 'lib/zeus/server/forked_process.rb', line 12 def notify_feature(feature) @server.__CHILD__stage_has_feature(@name, feature) end |
#notify_new_features ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/zeus/server/forked_process.rb', line 66 def notify_new_features new_features = newly_loaded_features() $previously_loaded_features ||= [] $previously_loaded_features |= new_features Thread.new { new_features.each { |f| notify_feature(f) } } end |
#notify_started ⇒ Object
24 25 26 27 |
# File 'lib/zeus/server/forked_process.rb', line 24 def notify_started @server.__CHILD__stage_starting_with_pid(@name, Process.pid) Zeus.ui.info("starting #{process_type} `#{@name}`") end |
#notify_terminated ⇒ Object
29 30 31 32 |
# File 'lib/zeus/server/forked_process.rb', line 29 def notify_terminated # @server.__CHILD__stage_terminating(@name) Zeus.ui.info("killing #{process_type} `#{@name}`") end |
#process_type ⇒ Object
20 21 22 |
# File 'lib/zeus/server/forked_process.rb', line 20 def process_type raise "NotImplementedError" end |
#run(close_parent_sockets = false) ⇒ Object
TODO: This just got really ugly and needs a refactor more than ever.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/zeus/server/forked_process.rb', line 79 def run(close_parent_sockets = false) @pid = fork { before_setup setup_forked_process(close_parent_sockets) Zeus.run_after_fork! after_setup notify_new_features after_notify runloop! } end |
#runloop! ⇒ Object
56 57 58 |
# File 'lib/zeus/server/forked_process.rb', line 56 def runloop! raise NotImplementedError end |
#setup_forked_process(close_parent_sockets) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/zeus/server/forked_process.rb', line 34 def setup_forked_process(close_parent_sockets) @server.__CHILD__close_parent_sockets if close_parent_sockets notify_started $0 = "zeus #{process_type}: #{@name}" trap("INT") { exit } trap("TERM") { notify_terminated exit } defined?(ActiveRecord::Base) and ActiveRecord::Base.clear_all_connections! end |