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.



70
71
72
73
74
75
76
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 70

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.



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, options)
  command('create', {'context' => context, 'source' => source, 'options' => options})
end

#created(context, source, options) ⇒ Object



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

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

#createp(context, source, options) ⇒ Object



110
111
112
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 110

def createp(context, source, options)
  command('createp', {'context' => context, 'source' => source, 'options' => 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

#startObject

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

Returns:

  • (Boolean)


78
79
80
# File 'lib/isomorfeus/speednode/runtime/vm.rb', line 78

def started?
  @started
end

#stopObject



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