Class: Isomorfeus::Speednode::Runtime::VM
- Inherits:
-
Object
- Object
- Isomorfeus::Speednode::Runtime::VM
- Defined in:
- lib/isomorfeus/speednode/runtime/vm.rb
Instance Attribute Summary collapse
-
#responder ⇒ Object
readonly
Returns the value of attribute responder.
Class Method Summary collapse
- .exit_node(socket, socket_dir, socket_path, pid) ⇒ Object
- .finalize(socket, socket_dir, socket_path, pid) ⇒ Object
Instance Method Summary collapse
- #attach(context, func) ⇒ Object
- #bench(context, source) ⇒ Object
- #create(context, source, options) ⇒ Object
- #created(context, source, options) ⇒ Object
- #createp(context, source, options) ⇒ Object
- #delete_context(context) ⇒ Object
- #eval(context, source) ⇒ Object
- #evsc(context, key) ⇒ Object
- #exec(context, source) ⇒ Object
-
#initialize(options) ⇒ VM
constructor
A new instance of VM.
- #scsc(context, key, source) ⇒ Object
-
#start ⇒ Object
def context_options(context) command(‘ctxo’, {‘context’ => context }) end.
- #started? ⇒ Boolean
- #stop ⇒ Object
Constructor Details
#initialize(options) ⇒ VM
Returns a new instance of VM.
70 71 72 73 74 75 76 |
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 70 def initialize() @mutex = ::Thread::Mutex.new @socket_path = nil @options = @started = false @socket = nil end |
Instance Attribute Details
#responder ⇒ Object (readonly)
Returns the value of attribute responder.
68 69 70 |
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 68 def responder @responder end |
Class Method Details
.exit_node(socket, socket_dir, socket_path, pid) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 51 def self.exit_node(socket, socket_dir, socket_path, pid) VMCommand.new(socket, "exit", 0).execute rescue nil 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
44 45 46 47 48 49 |
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 44 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
114 115 116 117 |
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 114 def attach(context, func) create_responder(context) unless responder command('attach', {'context' => context, 'func' => func }) end |
#bench(context, source) ⇒ Object
98 99 100 |
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 98 def bench(context, source) command('bench', {'context' => context, 'source' => source}) end |
#create(context, source, options) ⇒ Object
102 103 104 |
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 102 def create(context, source, ) command('create', {'context' => context, 'source' => source, 'options' => }) end |
#created(context, source, options) ⇒ Object
106 107 108 |
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 106 def created(context, source, ) command('created', {'context' => context, 'source' => source, 'options' => }) end |
#createp(context, source, options) ⇒ Object
110 111 112 |
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 110 def createp(context, source, ) command('createp', {'context' => context, 'source' => source, 'options' => }) end |
#delete_context(context) ⇒ Object
119 120 121 122 123 124 125 |
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 119 def delete_context(context) @mutex.synchronize do VMCommand.new(@socket, "deleteContext", context).execute rescue nil end rescue ThreadError nil end |
#eval(context, source) ⇒ Object
90 91 92 |
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 90 def eval(context, source) command('eval', {'context' => context, 'source' => source}) end |
#evsc(context, key) ⇒ Object
82 83 84 |
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 82 def evsc(context, key) command('evsc', { 'context' => context, 'key' => key }) end |
#exec(context, source) ⇒ Object
94 95 96 |
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 94 def exec(context, source) command('exec', {'context' => context, 'source' => source}) end |
#scsc(context, key, source) ⇒ Object
86 87 88 |
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 86 def scsc(context, key, source) command('scsc', { 'context' => context, 'key' => key, 'source' => source }) end |
#start ⇒ Object
def context_options(context)
command('ctxo', {'context' => context })
end
131 132 133 134 135 |
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 131 def start @mutex.synchronize do start_without_synchronization end end |
#started? ⇒ Boolean
78 79 80 |
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 78 def started? @started end |
#stop ⇒ Object
137 138 139 140 141 142 143 144 145 |
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 137 def stop return unless @started @mutex.synchronize do self.class.exit_node(@socket, @socket_dir, @socket_path, @pid) @socket_path = nil @started = false @socket = nil end end |