Class: Isomorfeus::Speednode::Runtime::VM

Inherits:
Object
  • Object
show all
Defined in:
lib/isomorfeus/speednode/runtime/vm.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ VM

Returns a new instance of VM.



46
47
48
49
50
51
52
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 46

def initialize(options)
  @mutex = Thread::Mutex.new
  @socket_path = nil
  @options = options
  @started = false
  @socket = nil
end

Instance Attribute Details

#responderObject (readonly)

Returns the value of attribute responder.



44
45
46
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 44

def responder
  @responder
end

Class Method Details

.exit_node(socket, socket_dir, socket_path, pid) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 65

def self.exit_node(socket, socket_dir, socket_path, pid)
  VMCommand.new(socket, "exit", [0]).execute
  socket.close
  File.unlink(socket_path) if File.exist?(socket_path)
  Dir.rmdir(socket_dir) if socket_dir && Dir.exist?(socket_dir)
  if Gem.win_platform?
    # SIGINT or SIGKILL are unreliable on Windows, try native taskkill first

    unless system("taskkill /f /t /pid #{pid} >NUL 2>NUL")
      Process.kill('KILL', pid) rescue nil
    end
  else
    Process.kill('KILL', pid) rescue nil
  end
rescue
  nil
end

.finalize(socket, socket_dir, socket_path, pid) ⇒ Object



58
59
60
61
62
63
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 58

def self.finalize(socket, socket_dir, socket_path, pid)
  proc do
    Isomorfeus::Speednode::Runtime.responders[socket_path].kill if Isomorfeus::Speednode::Runtime.responders[socket_path]
    exit_node(socket, socket_dir, socket_path, pid)
  end
end

Instance Method Details

#attach(context, func) ⇒ Object



98
99
100
101
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 98

def attach(context, func)
  create_responder(context) unless responder
  command("attach", {'context' => context, 'func' => func })
end

#create(context, source, options) ⇒ Object



90
91
92
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 90

def create(context, source, options)
  command("create", {'context' => context, 'source' => source, 'options' => options})
end

#createp(context, source, options) ⇒ Object



94
95
96
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 94

def createp(context, source, options)
  command("createp", {'context' => context, 'source' => source, 'options' => options})
end

#delete_context(context) ⇒ Object



103
104
105
106
107
108
109
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 103

def delete_context(context)
  @mutex.synchronize do
    VMCommand.new(@socket, "deleteContext", [context]).execute rescue nil
  end
rescue ThreadError
  nil
end

#eval(context, source) ⇒ Object



82
83
84
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 82

def eval(context, source)
  command("eval", {'context' => context, 'source' => source})
end

#exec(context, source) ⇒ Object



86
87
88
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 86

def exec(context, source)
  command("exec", {'context' => context, 'source' => source})
end

#startObject

def context_options(context)

command('ctxo', {'context' => context })

end



115
116
117
118
119
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 115

def start
  @mutex.synchronize do
    start_without_synchronization
  end
end

#started?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 54

def started?
  @started
end