Class: Speednode::Runtime::VM
- Inherits:
-
Object
- Object
- Speednode::Runtime::VM
- Defined in:
- lib/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.
69 70 71 72 73 74 75 |
# File 'lib/speednode/runtime/vm.rb', line 69 def initialize() @mutex = ::Thread::Mutex.new @socket_path = nil = @started = false @socket = nil end |
Instance Attribute Details
#responder ⇒ Object (readonly)
Returns the value of attribute responder.
67 68 69 |
# File 'lib/speednode/runtime/vm.rb', line 67 def responder @responder end |
Class Method Details
.exit_node(socket, socket_dir, socket_path, pid) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/speednode/runtime/vm.rb', line 50 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
43 44 45 46 47 48 |
# File 'lib/speednode/runtime/vm.rb', line 43 def self.finalize(socket, socket_dir, socket_path, pid) proc do ::Speednode::Runtime.responders[socket_path].kill if ::Speednode::Runtime.responders[socket_path] exit_node(socket, socket_dir, socket_path, pid) end end |
Instance Method Details
#attach(context, func) ⇒ Object
113 114 115 116 |
# File 'lib/speednode/runtime/vm.rb', line 113 def attach(context, func) create_responder(context) unless responder command('attach', {'context' => context, 'func' => func }) end |
#bench(context, source) ⇒ Object
97 98 99 |
# File 'lib/speednode/runtime/vm.rb', line 97 def bench(context, source) command('bench', {'context' => context, 'source' => source}) end |
#create(context, source, options) ⇒ Object
101 102 103 |
# File 'lib/speednode/runtime/vm.rb', line 101 def create(context, source, ) command('create', {'context' => context, 'source' => source, 'options' => }) end |
#created(context, source, options) ⇒ Object
105 106 107 |
# File 'lib/speednode/runtime/vm.rb', line 105 def created(context, source, ) command('created', {'context' => context, 'source' => source, 'options' => }) end |
#createp(context, source, options) ⇒ Object
109 110 111 |
# File 'lib/speednode/runtime/vm.rb', line 109 def createp(context, source, ) command('createp', {'context' => context, 'source' => source, 'options' => }) end |
#delete_context(context) ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/speednode/runtime/vm.rb', line 118 def delete_context(context) @mutex.synchronize do VMCommand.new(@socket, "deleteContext", context).execute rescue nil end rescue ThreadError nil end |
#eval(context, source) ⇒ Object
89 90 91 |
# File 'lib/speednode/runtime/vm.rb', line 89 def eval(context, source) command('eval', {'context' => context, 'source' => source}) end |
#evsc(context, key) ⇒ Object
81 82 83 |
# File 'lib/speednode/runtime/vm.rb', line 81 def evsc(context, key) command('evsc', { 'context' => context, 'key' => key }) end |
#exec(context, source) ⇒ Object
93 94 95 |
# File 'lib/speednode/runtime/vm.rb', line 93 def exec(context, source) command('exec', {'context' => context, 'source' => source}) end |
#scsc(context, key, source) ⇒ Object
85 86 87 |
# File 'lib/speednode/runtime/vm.rb', line 85 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
130 131 132 133 134 |
# File 'lib/speednode/runtime/vm.rb', line 130 def start @mutex.synchronize do start_without_synchronization end end |
#started? ⇒ Boolean
77 78 79 |
# File 'lib/speednode/runtime/vm.rb', line 77 def started? @started end |
#stop ⇒ Object
136 137 138 139 140 141 142 143 144 |
# File 'lib/speednode/runtime/vm.rb', line 136 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 |