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.
31 32 33 |
# File 'lib/legion/object.rb', line 31 def pid @pid end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
31 32 33 |
# File 'lib/legion/object.rb', line 31 def uri @uri end |
Class Method Details
.before(name, &block) ⇒ Object
26 27 28 |
# File 'lib/legion/object.rb', line 26 def before(name, &block) callbacks[:before][name] = block end |
.callbacks ⇒ Object
22 23 24 |
# File 'lib/legion/object.rb', line 22 def callbacks @callbacks ||= {before: {}} end |
.method_added(name) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# 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 } self.class.callbacks[:before][name].call unless self.class.callbacks[:before][name].nil? send(name, *args) synchronize { @busy = false } end end end |
Instance Method Details
#busy? ⇒ Boolean
37 38 39 |
# File 'lib/legion/object.rb', line 37 def busy? !!@busy end |
#exit ⇒ Object
51 52 53 |
# File 'lib/legion/object.rb', line 51 def exit DRb.stop_service end |
#ok? ⇒ Boolean
33 34 35 |
# File 'lib/legion/object.rb', line 33 def ok? true end |
#start_remote_instance(port: nil) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/legion/object.rb', line 41 def start_remote_instance(port: nil) return unless pid.nil? @uri = "druby://localhost:#{port}" @pid = fork do DRb.start_service uri, self DRb.thread.join end Process.detach pid end |