Class: Legion::Object
- Inherits:
-
Object
- Object
- Legion::Object
- Includes:
- MonitorMixin
- Defined in:
- lib/legion/object.rb
Instance Attribute Summary collapse
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
30 31 32 |
# File 'lib/legion/object.rb', line 30 def pid @pid end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
30 31 32 |
# File 'lib/legion/object.rb', line 30 def uri @uri end |
Class Method Details
.after_fork(&block) ⇒ Object
21 22 23 |
# File 'lib/legion/object.rb', line 21 def after_fork(&block) @after_fork = block end |
.fork_callback ⇒ Object
25 26 27 |
# File 'lib/legion/object.rb', line 25 def fork_callback @after_fork ||= lambda {} end |
.method_added(name) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/legion/object.rb', line 10 def method_added(name) return if name =~ /_async\z/i define_method "#{name}_async" do |*args| Thread.new do synchronize { @busy = true } send(name, *args) synchronize { @busy = false } end end end |
Instance Method Details
#busy? ⇒ Boolean
36 37 38 |
# File 'lib/legion/object.rb', line 36 def busy? !!@busy end |
#exit ⇒ Object
51 52 53 |
# File 'lib/legion/object.rb', line 51 def exit DRb.stop_service end |
#ok? ⇒ Boolean
32 33 34 |
# File 'lib/legion/object.rb', line 32 def ok? true end |
#start_remote_instance(port: nil) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/legion/object.rb', line 40 def start_remote_instance(port: nil) return unless pid.nil? @uri = "druby://localhost:#{port}" @pid = fork do DRb.start_service uri, self self.class.fork_callback.call DRb.thread.join end Process.detach pid end |