Class: Rubyang::Database::ComponentManager::Component

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyang/database/component_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, hook, path) ⇒ Component

Returns a new instance of Component.



14
15
16
17
18
19
# File 'lib/rubyang/database/component_manager.rb', line 14

def initialize name, hook, path
  @name = name
  @hook = hook
  @path = path
  @sock = "/tmp/rubyang/component/#{@name}.sock"
end

Instance Attribute Details

#hookObject (readonly)

Returns the value of attribute hook.



12
13
14
# File 'lib/rubyang/database/component_manager.rb', line 12

def hook
  @hook
end

#instanceObject (readonly)

Returns the value of attribute instance.



12
13
14
# File 'lib/rubyang/database/component_manager.rb', line 12

def instance
  @instance
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/rubyang/database/component_manager.rb', line 12

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



12
13
14
# File 'lib/rubyang/database/component_manager.rb', line 12

def path
  @path
end

#sockObject (readonly)

Returns the value of attribute sock.



12
13
14
# File 'lib/rubyang/database/component_manager.rb', line 12

def sock
  @sock
end

#threadObject (readonly)

Returns the value of attribute thread.



12
13
14
# File 'lib/rubyang/database/component_manager.rb', line 12

def thread
  @thread
end

Instance Method Details

#runObject



37
38
39
40
41
42
43
# File 'lib/rubyang/database/component_manager.rb', line 37

def run
  begin
    @instance.run
  rescue => e
    puts "Error: #{e}"
  end
end

#startObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rubyang/database/component_manager.rb', line 21

def start
  begin
    @thread = Thread.new( @path ) do |path|
      stdout, stderr, status = Open3.capture3( "#{RUBY_ENGINE} #{path}" )
    end
    10.times{ |i|
      break if File.socket? @sock
      sleep 1
      raise "Load failed: #{@name} : #{@path}" if i == 9
    }
    @instance = DRbObject.new_with_uri( "drbunix:#{@sock}" )
  rescue => e
    puts "Error: #{e}"
  end
end