gisele-vm 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +46 -0
- data/LICENCE.md +22 -0
- data/Manifest.txt +15 -0
- data/README.md +10 -0
- data/Rakefile +11 -0
- data/bin/gvm +9 -0
- data/gisele-vm.gemspec +191 -0
- data/gisele-vm.noespec +31 -0
- data/lib/gisele-vm.rb +4 -0
- data/lib/gisele-vm/loader.rb +5 -0
- data/lib/gisele-vm/version.rb +16 -0
- data/lib/gisele/compiling.rb +3 -0
- data/lib/gisele/compiling/gisele2gts.rb +143 -0
- data/lib/gisele/compiling/gts.rb +74 -0
- data/lib/gisele/compiling/gts2bytecode.rb +127 -0
- data/lib/gisele/vm.rb +87 -0
- data/lib/gisele/vm/bytecode.rb +84 -0
- data/lib/gisele/vm/bytecode/builder.rb +77 -0
- data/lib/gisele/vm/bytecode/grammar.citrus +116 -0
- data/lib/gisele/vm/bytecode/grammar.rb +19 -0
- data/lib/gisele/vm/bytecode/grammar.sexp.yml +113 -0
- data/lib/gisele/vm/bytecode/printer.rb +35 -0
- data/lib/gisele/vm/command.rb +140 -0
- data/lib/gisele/vm/component.rb +91 -0
- data/lib/gisele/vm/console.rb +58 -0
- data/lib/gisele/vm/enacter.rb +29 -0
- data/lib/gisele/vm/errors.rb +26 -0
- data/lib/gisele/vm/event.rb +11 -0
- data/lib/gisele/vm/event_manager.rb +65 -0
- data/lib/gisele/vm/kernel.rb +58 -0
- data/lib/gisele/vm/kernel/macros.gvm +214 -0
- data/lib/gisele/vm/kernel/opcodes.rb +212 -0
- data/lib/gisele/vm/kernel/runner.rb +63 -0
- data/lib/gisele/vm/lifecycle.rb +72 -0
- data/lib/gisele/vm/logging.rb +18 -0
- data/lib/gisele/vm/null_object.rb +19 -0
- data/lib/gisele/vm/prog.rb +63 -0
- data/lib/gisele/vm/prog_list.rb +55 -0
- data/lib/gisele/vm/prog_list/memory.rb +74 -0
- data/lib/gisele/vm/prog_list/sqldb.rb +123 -0
- data/lib/gisele/vm/prog_list/storage.rb +31 -0
- data/lib/gisele/vm/proxy.rb +14 -0
- data/lib/gisele/vm/proxy/client.rb +64 -0
- data/lib/gisele/vm/proxy/server.rb +29 -0
- data/lib/gisele/vm/registry.rb +57 -0
- data/lib/gisele/vm/robustness.rb +31 -0
- data/lib/gisele/vm/simulator/resumer.rb +32 -0
- data/spec/command/gvm_compile.cmd +1 -0
- data/spec/command/gvm_compile.stdout +111 -0
- data/spec/command/gvm_gts.cmd +1 -0
- data/spec/command/gvm_gts.stdout +101 -0
- data/spec/command/gvm_help.cmd +1 -0
- data/spec/command/gvm_help.stdout +30 -0
- data/spec/command/gvm_version.cmd +1 -0
- data/spec/command/gvm_version.stdout +2 -0
- data/spec/command/test_command.rb +29 -0
- data/spec/fixtures/complete.gis +13 -0
- data/spec/fixtures/fake_component.rb +24 -0
- data/spec/fixtures/kernel.rb +39 -0
- data/spec/fixtures/ts.adl +11 -0
- data/spec/fixtures/ts.gts +20 -0
- data/spec/fixtures/ts.gvm +19 -0
- data/spec/spec_helper.rb +86 -0
- data/spec/test_examples.rb +29 -0
- data/spec/test_gisele-vm.rb +8 -0
- data/spec/unit/bytecode/builder/test_at.rb +56 -0
- data/spec/unit/bytecode/builder/test_helpers.rb +36 -0
- data/spec/unit/bytecode/builder/test_instruction.rb +35 -0
- data/spec/unit/bytecode/builder/test_to_a.rb +53 -0
- data/spec/unit/bytecode/bytecode.gvm +1 -0
- data/spec/unit/bytecode/grammar/fixtures/comments.gvm +16 -0
- data/spec/unit/bytecode/grammar/fixtures/every.gvm +46 -0
- data/spec/unit/bytecode/grammar/fixtures/singleblock.gvm +2 -0
- data/spec/unit/bytecode/grammar/fixtures/twoblocks.gvm +4 -0
- data/spec/unit/bytecode/grammar/fixtures/with_end.gvm +5 -0
- data/spec/unit/bytecode/grammar/test_array.rb +24 -0
- data/spec/unit/bytecode/grammar/test_block.rb +35 -0
- data/spec/unit/bytecode/grammar/test_boolean.rb +20 -0
- data/spec/unit/bytecode/grammar/test_constant.rb +20 -0
- data/spec/unit/bytecode/grammar/test_eol.rb +20 -0
- data/spec/unit/bytecode/grammar/test_eol_comment.rb +36 -0
- data/spec/unit/bytecode/grammar/test_file.rb +38 -0
- data/spec/unit/bytecode/grammar/test_hash.rb +33 -0
- data/spec/unit/bytecode/grammar/test_instruction.rb +32 -0
- data/spec/unit/bytecode/grammar/test_int.rb +24 -0
- data/spec/unit/bytecode/grammar/test_label.rb +24 -0
- data/spec/unit/bytecode/grammar/test_opcode.rb +23 -0
- data/spec/unit/bytecode/grammar/test_string.rb +25 -0
- data/spec/unit/bytecode/grammar/test_symbol.rb +30 -0
- data/spec/unit/bytecode/test_build.rb +36 -0
- data/spec/unit/bytecode/test_coerce.rb +41 -0
- data/spec/unit/bytecode/test_fetch.rb +20 -0
- data/spec/unit/bytecode/test_grammar.rb +30 -0
- data/spec/unit/bytecode/test_parse.rb +22 -0
- data/spec/unit/bytecode/test_plus.rb +27 -0
- data/spec/unit/bytecode/test_to_a.rb +19 -0
- data/spec/unit/bytecode/test_to_s.rb +32 -0
- data/spec/unit/command/code.gis +3 -0
- data/spec/unit/command/test_vm.rb +51 -0
- data/spec/unit/compiling/gisele2gts/test_on_par_st.rb +51 -0
- data/spec/unit/compiling/gisele2gts/test_on_seq_st.rb +46 -0
- data/spec/unit/compiling/gisele2gts/test_on_task_call_st.rb +37 -0
- data/spec/unit/compiling/gisele2gts/test_on_task_def.rb +49 -0
- data/spec/unit/compiling/gisele2gts/test_on_unit_def.rb +35 -0
- data/spec/unit/compiling/gts2bytecode/test_on_end.rb +31 -0
- data/spec/unit/compiling/gts2bytecode/test_on_event.rb +37 -0
- data/spec/unit/compiling/gts2bytecode/test_on_fork.rb +41 -0
- data/spec/unit/compiling/gts2bytecode/test_on_join.rb +42 -0
- data/spec/unit/compiling/gts2bytecode/test_on_listen.rb +36 -0
- data/spec/unit/compiling/gts2bytecode/test_on_nop.rb +30 -0
- data/spec/unit/component/test_component_name.rb +16 -0
- data/spec/unit/component/test_logging.rb +36 -0
- data/spec/unit/enacter/test_component.rb +11 -0
- data/spec/unit/event/test_to_s.rb +12 -0
- data/spec/unit/event_manager/test_component.rb +9 -0
- data/spec/unit/event_manager/test_subscribe.rb +40 -0
- data/spec/unit/event_manager/test_unsubscribe.rb +39 -0
- data/spec/unit/kernel/macros/test_fork.rb +37 -0
- data/spec/unit/kernel/macros/test_join.rb +43 -0
- data/spec/unit/kernel/macros/test_listen.rb +37 -0
- data/spec/unit/kernel/macros/test_notify.rb +57 -0
- data/spec/unit/kernel/macros/test_react.rb +47 -0
- data/spec/unit/kernel/macros/test_schedule_at.rb +30 -0
- data/spec/unit/kernel/opcodes/test_op_del.rb +42 -0
- data/spec/unit/kernel/opcodes/test_op_event.rb +25 -0
- data/spec/unit/kernel/opcodes/test_op_fetch.rb +27 -0
- data/spec/unit/kernel/opcodes/test_op_flip.rb +17 -0
- data/spec/unit/kernel/opcodes/test_op_fold.rb +29 -0
- data/spec/unit/kernel/opcodes/test_op_fork.rb +63 -0
- data/spec/unit/kernel/opcodes/test_op_forka.rb +51 -0
- data/spec/unit/kernel/opcodes/test_op_get.rb +62 -0
- data/spec/unit/kernel/opcodes/test_op_getr.rb +48 -0
- data/spec/unit/kernel/opcodes/test_op_ifenil.rb +41 -0
- data/spec/unit/kernel/opcodes/test_op_ifezero.rb +32 -0
- data/spec/unit/kernel/opcodes/test_op_invoke.rb +34 -0
- data/spec/unit/kernel/opcodes/test_op_nop.rb +18 -0
- data/spec/unit/kernel/opcodes/test_op_parent.rb +39 -0
- data/spec/unit/kernel/opcodes/test_op_pop.rb +22 -0
- data/spec/unit/kernel/opcodes/test_op_push.rb +17 -0
- data/spec/unit/kernel/opcodes/test_op_save.rb +32 -0
- data/spec/unit/kernel/opcodes/test_op_savea.rb +34 -0
- data/spec/unit/kernel/opcodes/test_op_self.rb +20 -0
- data/spec/unit/kernel/opcodes/test_op_send.rb +20 -0
- data/spec/unit/kernel/opcodes/test_op_set.rb +61 -0
- data/spec/unit/kernel/opcodes/test_op_then.rb +50 -0
- data/spec/unit/kernel/opcodes/test_op_unfold.rb +22 -0
- data/spec/unit/kernel/opcodes/test_op_uuid.rb +16 -0
- data/spec/unit/kernel/runner/test_pop.rb +26 -0
- data/spec/unit/kernel/runner/test_stack.rb +28 -0
- data/spec/unit/kernel/test_progress.rb +47 -0
- data/spec/unit/kernel/test_resume.rb +53 -0
- data/spec/unit/kernel/test_start.rb +36 -0
- data/spec/unit/prog/test_to_hash.rb +29 -0
- data/spec/unit/prog/test_waitlist_eq.rb +20 -0
- data/spec/unit/prog_list/memory/test_component.rb +9 -0
- data/spec/unit/prog_list/memory/test_fetch.rb +40 -0
- data/spec/unit/prog_list/memory/test_pick.rb +39 -0
- data/spec/unit/prog_list/memory/test_save.rb +91 -0
- data/spec/unit/prog_list/memory/test_to_relation.rb +17 -0
- data/spec/unit/prog_list/sqldb/test_component.rb +11 -0
- data/spec/unit/prog_list/sqldb/test_connect.rb +46 -0
- data/spec/unit/prog_list/test_memory.rb +9 -0
- data/spec/unit/prog_list/test_sqldb.rb +13 -0
- data/spec/unit/prog_list/test_storage.rb +51 -0
- data/spec/unit/registry/test_component.rb +9 -0
- data/spec/unit/registry/test_connect.rb +53 -0
- data/spec/unit/registry/test_disconnect.rb +51 -0
- data/spec/unit/registry/test_registration.rb +44 -0
- data/spec/unit/shared/a_component.rb +49 -0
- data/spec/unit/shared/a_storage.rb +114 -0
- data/spec/unit/test_logging.rb +46 -0
- data/spec/unit/test_prog.rb +57 -0
- data/spec/unit/test_prog_list.rb +22 -0
- data/spec/unit/vm/test_event_facace.rb +11 -0
- data/spec/unit/vm/test_initialize.rb +59 -0
- data/spec/unit/vm/test_proglist_facade.rb +21 -0
- data/tasks/debug_mail.rake +75 -0
- data/tasks/debug_mail.txt +13 -0
- data/tasks/gem.rake +73 -0
- data/tasks/spec_test.rake +71 -0
- data/tasks/unit_test.rake +76 -0
- data/tasks/yard.rake +51 -0
- metadata +493 -0
@@ -0,0 +1,55 @@
|
|
1
|
+
module Gisele
|
2
|
+
class VM
|
3
|
+
class ProgList < Component
|
4
|
+
extend Forwardable
|
5
|
+
|
6
|
+
def initialize(storage)
|
7
|
+
super()
|
8
|
+
@storage = storage
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.memory
|
12
|
+
ProgList.new storage("memory")
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.storage(options = nil)
|
16
|
+
options = {:uri => "memory"} unless options
|
17
|
+
options = {:uri => options } unless Hash===options
|
18
|
+
options[:uri] = "memory" unless options[:uri]
|
19
|
+
options[:uri] = "#{Sqldb.sqlite_protocol}:memory" if options[:uri]=='memory'
|
20
|
+
ProgList::Sqldb.new(options)
|
21
|
+
end
|
22
|
+
|
23
|
+
def registered(vm)
|
24
|
+
super
|
25
|
+
@storage.registered(vm)
|
26
|
+
end
|
27
|
+
|
28
|
+
def unregistered
|
29
|
+
super
|
30
|
+
@storage.unregistered
|
31
|
+
end
|
32
|
+
|
33
|
+
def connect
|
34
|
+
super
|
35
|
+
@storage.connect
|
36
|
+
end
|
37
|
+
|
38
|
+
def disconnect
|
39
|
+
super
|
40
|
+
@storage.disconnect
|
41
|
+
end
|
42
|
+
|
43
|
+
def_delegators :"@storage", :options,
|
44
|
+
:fetch,
|
45
|
+
:pick,
|
46
|
+
:save,
|
47
|
+
:clear,
|
48
|
+
:to_relation
|
49
|
+
|
50
|
+
end # class ProgList
|
51
|
+
end # class VM
|
52
|
+
end # module Gisele
|
53
|
+
require_relative 'prog_list/storage'
|
54
|
+
require_relative 'prog_list/memory'
|
55
|
+
require_relative 'prog_list/sqldb'
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Gisele
|
2
|
+
class VM
|
3
|
+
class ProgList
|
4
|
+
class Memory < Storage
|
5
|
+
|
6
|
+
def initialize(options = {})
|
7
|
+
super
|
8
|
+
@progs = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def fetch(puid)
|
12
|
+
@progs[is_a_valid_puid!(puid)].dup
|
13
|
+
end
|
14
|
+
|
15
|
+
def pick(restriction, &bl)
|
16
|
+
keys = restriction.keys
|
17
|
+
candidate = @progs.select{|p|
|
18
|
+
p.to_hash(keys) == restriction
|
19
|
+
}.sample
|
20
|
+
bl.call if bl and candidate.nil?
|
21
|
+
candidate
|
22
|
+
end
|
23
|
+
|
24
|
+
def clear
|
25
|
+
@progs = []
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_relation(restriction = nil)
|
29
|
+
progs = @progs
|
30
|
+
if restriction
|
31
|
+
keys = restriction.keys
|
32
|
+
progs = progs.select{|p| p.to_hash(keys) == restriction}
|
33
|
+
end
|
34
|
+
progs = progs.map{|p| p.to_hash}
|
35
|
+
Alf::Relation(progs)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def save_prog(prog)
|
41
|
+
prog.puid.tap{|puid|
|
42
|
+
@progs[is_a_valid_puid!(puid)] = prog.dup
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
def register_prog(prog)
|
47
|
+
@progs << prog.dup.tap{|d|
|
48
|
+
d.puid = @progs.size
|
49
|
+
d.parent = d.puid if d.parent.nil?
|
50
|
+
d.root = d.puid if d.root.nil?
|
51
|
+
}
|
52
|
+
@progs.last.puid
|
53
|
+
end
|
54
|
+
|
55
|
+
def is_a_valid_puid!(puid)
|
56
|
+
case puid
|
57
|
+
when /^\d+$/
|
58
|
+
is_a_valid_puid! Integer(puid)
|
59
|
+
else
|
60
|
+
unless valid_puid?(puid)
|
61
|
+
raise InvalidPUIDError, "Invalid puid: `#{puid.inspect}`"
|
62
|
+
end
|
63
|
+
puid
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def valid_puid?(puid)
|
68
|
+
(Integer===puid) and (0 <= puid) and (puid < @progs.size)
|
69
|
+
end
|
70
|
+
|
71
|
+
end # class Memory
|
72
|
+
end # class ProgList
|
73
|
+
end # class VM
|
74
|
+
end # module Gisele
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'sequel'
|
2
|
+
module Gisele
|
3
|
+
class VM
|
4
|
+
class ProgList
|
5
|
+
class Sqldb < Storage
|
6
|
+
|
7
|
+
attr_reader :sequel_db
|
8
|
+
|
9
|
+
def initialize(options = {})
|
10
|
+
super(default_options.merge(options))
|
11
|
+
end
|
12
|
+
|
13
|
+
def default_options
|
14
|
+
{ :table_name => :gvm_proglist }
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.sqlite_protocol
|
18
|
+
defined?(JRUBY_VERSION) ? "jdbc:sqlite" : "sqlite"
|
19
|
+
end
|
20
|
+
|
21
|
+
def connect
|
22
|
+
super
|
23
|
+
@sequel_db = Sequel.connect(connection_info)
|
24
|
+
@sequel_db.test_connection
|
25
|
+
ensure_schema(@sequel_db)
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
def disconnect
|
30
|
+
super
|
31
|
+
@sequel_db.disconnect if @sequel_db
|
32
|
+
end
|
33
|
+
|
34
|
+
def fetch(puid)
|
35
|
+
got = sequel_db[table_name].where(:puid => puid).first
|
36
|
+
raise InvalidPUIDError, "Invalid puid: `#{puid.inspect}`" unless got
|
37
|
+
decode(got)
|
38
|
+
end
|
39
|
+
|
40
|
+
def pick(restriction)
|
41
|
+
c = sequel_db[table_name].
|
42
|
+
where(encode(restriction)).limit(1).first
|
43
|
+
c && decode(c)
|
44
|
+
end
|
45
|
+
|
46
|
+
def clear
|
47
|
+
sequel_db[table_name].delete
|
48
|
+
end
|
49
|
+
|
50
|
+
def to_relation(restriction = nil)
|
51
|
+
tuples = sequel_db[table_name]
|
52
|
+
tuples = tuples.where(encode(restriction)) if restriction
|
53
|
+
tuples = tuples.map{|t| decode(t, false)}
|
54
|
+
Alf::Relation(tuples)
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def save_prog(prog)
|
60
|
+
sequel_db[table_name].
|
61
|
+
where(:puid => prog.puid).
|
62
|
+
update(encode(prog))
|
63
|
+
prog.puid
|
64
|
+
end
|
65
|
+
|
66
|
+
def register_prog(prog)
|
67
|
+
tuple = encode(prog)
|
68
|
+
tuple.delete(:puid) if tuple[:puid].nil?
|
69
|
+
puid = sequel_db[table_name].insert(tuple)
|
70
|
+
if prog.parent.nil? or prog.root.nil?
|
71
|
+
sequel_db[table_name].where(:puid => puid).
|
72
|
+
update(:root => prog.root || puid, :parent => prog.parent || puid)
|
73
|
+
end
|
74
|
+
puid
|
75
|
+
end
|
76
|
+
|
77
|
+
def decode(h, as_prog = true)
|
78
|
+
h[:pc] = h[:pc].to_sym if h.has_key?(:pc)
|
79
|
+
h[:pc] = -1 if h[:pc] == :"-1"
|
80
|
+
h[:waitfor] = h[:waitfor].to_sym if h.has_key?(:waitfor)
|
81
|
+
h[:waitlist] = ::Kernel.eval(h[:waitlist]) if h.has_key?(:waitlist)
|
82
|
+
h[:input] = ::Kernel.eval(h[:input]) if h.has_key?(:input)
|
83
|
+
as_prog ? Prog.new(h) : h
|
84
|
+
end
|
85
|
+
|
86
|
+
def encode(prog)
|
87
|
+
h = prog.to_hash
|
88
|
+
h[:pc] = h[:pc].to_s if h.has_key?(:pc)
|
89
|
+
h[:waitfor] = h[:waitfor].to_s if h.has_key?(:waitfor)
|
90
|
+
h[:waitlist] = h[:waitlist].inspect if h.has_key?(:waitlist)
|
91
|
+
h[:input] = h[:input].inspect if h.has_key?(:input)
|
92
|
+
h
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def connection_info
|
98
|
+
@options[:connection_info] || @options[:uri]
|
99
|
+
end
|
100
|
+
|
101
|
+
def table_name
|
102
|
+
@options[:table_name]
|
103
|
+
end
|
104
|
+
|
105
|
+
def ensure_schema(db)
|
106
|
+
return if db.table_exists?(tn = table_name)
|
107
|
+
db.create_table(tn) do
|
108
|
+
primary_key :puid
|
109
|
+
Integer :parent
|
110
|
+
Integer :root
|
111
|
+
String :pc
|
112
|
+
String :waitfor
|
113
|
+
String :waitlist
|
114
|
+
String :input
|
115
|
+
index :root
|
116
|
+
index :waitfor
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
end # class Sqldb
|
121
|
+
end # class ProgList
|
122
|
+
end # class VM
|
123
|
+
end # module Gisele
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Gisele
|
2
|
+
class VM
|
3
|
+
class ProgList
|
4
|
+
class Storage < Component
|
5
|
+
attr_reader :options
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
super()
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def save(prog)
|
13
|
+
if Array===prog
|
14
|
+
prog.map{|p| save(p)}
|
15
|
+
else
|
16
|
+
prog = is_a_prog!(prog)
|
17
|
+
prog.puid ? save_prog(prog) : register_prog(prog)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def is_a_prog!(prog)
|
24
|
+
raise ArgumentError, "Invalid prog: #{prog}", caller unless Prog===prog
|
25
|
+
prog
|
26
|
+
end
|
27
|
+
|
28
|
+
end # class Storage
|
29
|
+
end # class ProgList
|
30
|
+
end # class VM
|
31
|
+
end # module Gisele
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Gisele
|
2
|
+
class VM
|
3
|
+
module Proxy
|
4
|
+
|
5
|
+
def default_options
|
6
|
+
{ :uri => "druby://localhost:6789" }
|
7
|
+
end
|
8
|
+
module_function :default_options
|
9
|
+
|
10
|
+
end # module Proxy
|
11
|
+
end # class VM
|
12
|
+
end # module Gisele
|
13
|
+
require_relative 'proxy/server'
|
14
|
+
require_relative 'proxy/client'
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'drb'
|
2
|
+
module Gisele
|
3
|
+
class VM
|
4
|
+
module Proxy
|
5
|
+
class Client
|
6
|
+
extend Forwardable
|
7
|
+
|
8
|
+
attr_reader :options
|
9
|
+
attr_accessor :logger
|
10
|
+
attr_reader :registry
|
11
|
+
|
12
|
+
def initialize(options = {})
|
13
|
+
init_lifecycle
|
14
|
+
@options = Proxy.default_options.merge(options)
|
15
|
+
@registry = Registry.new(self)
|
16
|
+
yield(self) if block_given?
|
17
|
+
@logger ||= Logger.new($stdout, Logger::DEBUG)
|
18
|
+
end
|
19
|
+
|
20
|
+
include Robustness
|
21
|
+
include Logging
|
22
|
+
include Lifecycle
|
23
|
+
|
24
|
+
def run
|
25
|
+
DRb.start_service
|
26
|
+
@vm = DRbObject.new nil, options[:uri]
|
27
|
+
@vm.to_s
|
28
|
+
yield(@vm) if block_given?
|
29
|
+
super
|
30
|
+
end
|
31
|
+
|
32
|
+
def stop
|
33
|
+
DRb.stop_service
|
34
|
+
super
|
35
|
+
end
|
36
|
+
|
37
|
+
def_delegators :registry, :components,
|
38
|
+
:register,
|
39
|
+
:unregister,
|
40
|
+
:connect,
|
41
|
+
:disconnect,
|
42
|
+
:connected?
|
43
|
+
def_delegators :"@vm", :proglist,
|
44
|
+
:event_manager
|
45
|
+
def_delegators :"@vm", :start,
|
46
|
+
:resume,
|
47
|
+
:progress
|
48
|
+
def_delegators :"@vm", :pick,
|
49
|
+
:fetch,
|
50
|
+
:save,
|
51
|
+
:progs
|
52
|
+
def_delegators :"@vm", :event,
|
53
|
+
:subscribe,
|
54
|
+
:unsubscribe
|
55
|
+
|
56
|
+
end # Client
|
57
|
+
end # module Proxy
|
58
|
+
|
59
|
+
def self.drb_client(&bl)
|
60
|
+
Proxy::Client.new.run(&bl)
|
61
|
+
end
|
62
|
+
|
63
|
+
end # class VM
|
64
|
+
end # module Gisele
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'drb'
|
2
|
+
module Gisele
|
3
|
+
class VM
|
4
|
+
module Proxy
|
5
|
+
class Server < Component
|
6
|
+
|
7
|
+
attr_reader :options
|
8
|
+
|
9
|
+
def initialize(options = {})
|
10
|
+
super()
|
11
|
+
@options = Proxy.default_options.merge(options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def connect
|
15
|
+
super
|
16
|
+
DRb.start_service options[:uri], vm
|
17
|
+
info "VM proxy started at #{DRb.uri}."
|
18
|
+
end
|
19
|
+
|
20
|
+
def disconnect
|
21
|
+
DRb.stop_service
|
22
|
+
DRb.thread.join if DRb.thread
|
23
|
+
super
|
24
|
+
end
|
25
|
+
|
26
|
+
end # Server
|
27
|
+
end # module Proxy
|
28
|
+
end # class VM
|
29
|
+
end # module Gisele
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Gisele
|
2
|
+
class VM
|
3
|
+
class Registry < Component
|
4
|
+
|
5
|
+
attr_reader :components
|
6
|
+
|
7
|
+
def initialize(vm)
|
8
|
+
super()
|
9
|
+
@vm = vm
|
10
|
+
@components = []
|
11
|
+
@cconnected = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def register(component, prior = false)
|
15
|
+
raise NotImplementedError,
|
16
|
+
"Hot registration is not implemented." if connected?
|
17
|
+
if prior
|
18
|
+
@components.unshift component
|
19
|
+
else
|
20
|
+
@components.push component
|
21
|
+
end
|
22
|
+
component.registered(vm)
|
23
|
+
end
|
24
|
+
|
25
|
+
def unregister(component)
|
26
|
+
raise NotImplementedError,
|
27
|
+
"Hot unregistration is not implemented." if connected?
|
28
|
+
@components.delete(component)
|
29
|
+
component.unregistered
|
30
|
+
end
|
31
|
+
|
32
|
+
def connect
|
33
|
+
super
|
34
|
+
@components.each do |c|
|
35
|
+
c.connect
|
36
|
+
@cconnected << c
|
37
|
+
end
|
38
|
+
rescue Exception => ex
|
39
|
+
fatal error_message(ex, "Unable to connect VM:")
|
40
|
+
disconnect
|
41
|
+
raise
|
42
|
+
end
|
43
|
+
|
44
|
+
def disconnect
|
45
|
+
super
|
46
|
+
@cconnected.each do |c|
|
47
|
+
begin
|
48
|
+
c.disconnect
|
49
|
+
rescue Exception => ex
|
50
|
+
warn("Error when disconnecting #{c}: #{ex.message}") rescue nil
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end # class Registry
|
56
|
+
end # class VM
|
57
|
+
end # module Gisele
|