hutch-xamplr 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +2 -2
- data/examples/random-people/batch-load-users.rb +2 -2
- data/examples/random-people/optimise.rb +2 -2
- data/examples/random-people/query.rb +2 -2
- data/examples/random-people/query2.rb +2 -2
- data/examples/random-people-shared-addresses/find-people-by-address.rb +1 -4
- data/lib/xamplr/README-POSSIBLE-PROBLEMS +5 -0
- data/lib/xamplr/from-xml.rb +10 -4
- data/lib/xamplr/indexed-array.rb +12 -10
- data/lib/xamplr/persistence.rb +5 -4
- data/lib/xamplr/persister/caches.rb +10 -10
- data/lib/xamplr/persister/caching.rb +37 -20
- data/lib/xamplr/xampl-object.rb +2 -1
- metadata +3 -2
data/VERSION.yml
CHANGED
@@ -5,8 +5,8 @@ require 'RandomPeople'
|
|
5
5
|
require 'people'
|
6
6
|
|
7
7
|
Xampl.set_default_persister_kind(:tokyo_cabinet)
|
8
|
-
|
9
|
-
Xampl.set_default_persister_format(:ruby_format)
|
8
|
+
Xampl.set_default_persister_format(:xml_format)
|
9
|
+
#Xampl.set_default_persister_format(:ruby_format)
|
10
10
|
|
11
11
|
module RandomPeople
|
12
12
|
|
@@ -4,8 +4,8 @@ require 'RandomPeople'
|
|
4
4
|
require 'people'
|
5
5
|
|
6
6
|
Xampl.set_default_persister_kind(:tokyo_cabinet)
|
7
|
-
|
8
|
-
Xampl.set_default_persister_format(:ruby_format)
|
7
|
+
Xampl.set_default_persister_format(:xml_format)
|
8
|
+
#Xampl.set_default_persister_format(:ruby_format)
|
9
9
|
|
10
10
|
module RandomPeople
|
11
11
|
|
@@ -4,8 +4,8 @@ require 'RandomPeople'
|
|
4
4
|
require 'people'
|
5
5
|
|
6
6
|
Xampl.set_default_persister_kind(:tokyo_cabinet)
|
7
|
-
|
8
|
-
Xampl.set_default_persister_format(:ruby_format)
|
7
|
+
Xampl.set_default_persister_format(:xml_format)
|
8
|
+
#Xampl.set_default_persister_format(:ruby_format)
|
9
9
|
|
10
10
|
module RandomPeople
|
11
11
|
|
@@ -4,8 +4,8 @@ require 'RandomPeople'
|
|
4
4
|
require 'people'
|
5
5
|
|
6
6
|
Xampl.set_default_persister_kind(:tokyo_cabinet)
|
7
|
-
|
8
|
-
Xampl.set_default_persister_format(:ruby_format)
|
7
|
+
Xampl.set_default_persister_format(:xml_format)
|
8
|
+
#Xampl.set_default_persister_format(:ruby_format)
|
9
9
|
|
10
10
|
module RandomPeople
|
11
11
|
|
data/lib/xamplr/from-xml.rb
CHANGED
@@ -137,9 +137,9 @@ module Xampl
|
|
137
137
|
end
|
138
138
|
|
139
139
|
unless @is_realising then
|
140
|
-
@attributeValue.size.times
|
140
|
+
@attributeValue.size.times do |i|
|
141
141
|
FromXML.tokenise_string @attributeValue[i]
|
142
|
-
|
142
|
+
end
|
143
143
|
end
|
144
144
|
|
145
145
|
if target then
|
@@ -150,7 +150,7 @@ module Xampl
|
|
150
150
|
element.note_attributes_initialised(@is_realising)
|
151
151
|
else
|
152
152
|
if klasses[0].persisted? then
|
153
|
-
@attributeName.each_index
|
153
|
+
@attributeName.each_index do |i|
|
154
154
|
if @attributeName[i] == klasses[0].persisted?.to_s then
|
155
155
|
existing_element = Xampl.find_known(klasses[0], @attributeValue[i])
|
156
156
|
if existing_element then
|
@@ -178,10 +178,16 @@ module Xampl
|
|
178
178
|
# existing_element.reset_contents
|
179
179
|
# element = existing_element
|
180
180
|
# existing_element = nil
|
181
|
+
# puts "#{File.basename(__FILE__)} #{__LINE__} EXISTING ELEMENT: #{ existing_element }"
|
182
|
+
# puts "#{File.basename(__FILE__)} #{__LINE__} WOW, must handle the existing element correctly"
|
183
|
+
element = existing_element #TODO -- IS THIS RIGHT????????????????????????
|
181
184
|
end
|
182
185
|
unless element then
|
183
186
|
element = klasses[0].new
|
184
187
|
requires_caching = @recovering
|
188
|
+
# puts "#{File.basename(__FILE__)} #{__LINE__} WOW, what about recovering????"
|
189
|
+
#TODO -- IS THIS RIGHT????????????????????????
|
190
|
+
requires_caching = true #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
185
191
|
unless @recovering then
|
186
192
|
element.force_load if parent
|
187
193
|
end
|
@@ -190,7 +196,7 @@ module Xampl
|
|
190
196
|
|
191
197
|
break
|
192
198
|
end
|
193
|
-
|
199
|
+
end
|
194
200
|
end
|
195
201
|
|
196
202
|
unless element then
|
data/lib/xamplr/indexed-array.rb
CHANGED
@@ -79,35 +79,37 @@ class IndexedArray
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def each
|
82
|
-
@store.each
|
82
|
+
@store.each do |obj |
|
83
|
+
yield(obj)
|
84
|
+
end
|
83
85
|
end
|
84
86
|
|
85
87
|
def each_index
|
86
|
-
@store.each_index{ | i | yield(i) }
|
88
|
+
@store.each_index { | i | yield(i) }
|
87
89
|
end
|
88
90
|
|
89
91
|
def each_key_value
|
90
|
-
@map.each{ | k, v | yield(k, @store[v]) }
|
92
|
+
@map.each { | k, v | yield(k, @store[v]) }
|
91
93
|
end
|
92
94
|
|
93
95
|
def sort
|
94
|
-
@store.sort{ | a, b | yield(a, b) }
|
96
|
+
@store.sort { | a, b | yield(a, b) }
|
95
97
|
end
|
96
98
|
|
97
99
|
def sort!
|
98
100
|
arr = []
|
99
|
-
@map.each
|
101
|
+
@map.each do |index, pos|
|
100
102
|
arr << [index, @store[pos]]
|
101
|
-
|
102
|
-
arr.sort!
|
103
|
+
end
|
104
|
+
arr.sort! do |a, b|
|
103
105
|
yield(a[1], b[1])
|
104
|
-
|
106
|
+
end
|
105
107
|
@map = {}
|
106
108
|
@store = []
|
107
|
-
arr.each
|
109
|
+
arr.each do |pair|
|
108
110
|
@map[pair[0]] = @store.size
|
109
111
|
@store << pair[1]
|
110
|
-
|
112
|
+
end
|
111
113
|
end
|
112
114
|
end
|
113
115
|
|
data/lib/xamplr/persistence.rb
CHANGED
@@ -63,7 +63,7 @@ module Xampl
|
|
63
63
|
@@persister = @@known_persisters[name]
|
64
64
|
|
65
65
|
if @@persister then
|
66
|
-
# @@persister.open # this won't work
|
66
|
+
# @@persister.open # this won't work
|
67
67
|
# TODO -- if we know the persister, why are we being so anal about kind and format???
|
68
68
|
|
69
69
|
kind = @@persister.kind || kind
|
@@ -691,8 +691,7 @@ module Xampl
|
|
691
691
|
|
692
692
|
def lookup(klass, pid)
|
693
693
|
#raise XamplException.new(:live_across_rollback) if @rolled_back
|
694
|
-
|
695
|
-
# puts "LOOKUP:: klass: #{klass} pid: #{pid}"
|
694
|
+
#puts "#{File.basename(__FILE__)} #{__LINE__} LOOKUP:: klass: #{klass} pid: #{pid}"
|
696
695
|
|
697
696
|
begin
|
698
697
|
busy(true)
|
@@ -701,6 +700,8 @@ module Xampl
|
|
701
700
|
busy(false)
|
702
701
|
end
|
703
702
|
|
703
|
+
#puts "#{File.basename(__FILE__)} #{__LINE__} ---> #{ xampl }"
|
704
|
+
|
704
705
|
return xampl
|
705
706
|
end
|
706
707
|
|
@@ -713,7 +714,7 @@ module Xampl
|
|
713
714
|
end
|
714
715
|
|
715
716
|
def lazy_load(target, klass, pid)
|
716
|
-
#
|
717
|
+
# puts "#{File.basename(__FILE__)} #{__LINE__} LAZY_LOAD:: klass: #{klass} pid: #{pid} target: #{target}"
|
717
718
|
|
718
719
|
xampl = read(klass, pid, target)
|
719
720
|
|
@@ -37,7 +37,7 @@ module Xampl
|
|
37
37
|
actual_victim = nil
|
38
38
|
min = 1 + @now
|
39
39
|
@size = 0
|
40
|
-
@cache.each
|
40
|
+
@cache.each do |key, pair|
|
41
41
|
possibility = pair[0]
|
42
42
|
if (not possibility.load_needed) and pair[1] < min then
|
43
43
|
@size += 1
|
@@ -45,7 +45,7 @@ module Xampl
|
|
45
45
|
actual_victim = possibility
|
46
46
|
min = pair[1]
|
47
47
|
end
|
48
|
-
|
48
|
+
end
|
49
49
|
#puts
|
50
50
|
#puts
|
51
51
|
#puts "REMOVE FROM CACHE(XamplCache): victim: #{victim}, actual: #{actual_victim}"
|
@@ -84,11 +84,11 @@ module Xampl
|
|
84
84
|
end
|
85
85
|
|
86
86
|
def print(out = "")
|
87
|
-
out << "Cache with capacity: #{@capacity}, current size: #{@size}\n"
|
88
|
-
@cache.each
|
87
|
+
out << "Cache (standard) with capacity: #{@capacity}, current size: #{@size}\n"
|
88
|
+
@cache.each do |key, pair|
|
89
89
|
out << sprintf(" key: '%s', value: '%s', accessed: %s\n",
|
90
90
|
key, pair[0], pair[1])
|
91
|
-
|
91
|
+
end
|
92
92
|
out
|
93
93
|
end
|
94
94
|
|
@@ -122,7 +122,7 @@ module Xampl
|
|
122
122
|
actual_victim = nil
|
123
123
|
min = 1 + @accesses
|
124
124
|
live = 0
|
125
|
-
@cache.each
|
125
|
+
@cache.each do |key, pair|
|
126
126
|
pair[1] -= 1
|
127
127
|
possibility = pair[0]
|
128
128
|
if (not possibility.load_needed) and pair[1] < min then
|
@@ -131,7 +131,7 @@ module Xampl
|
|
131
131
|
actual_victim = possibility
|
132
132
|
min = pair[1]
|
133
133
|
end
|
134
|
-
|
134
|
+
end
|
135
135
|
#puts
|
136
136
|
#puts
|
137
137
|
#puts "REMOVE FROM CACHE(XamplCacheLFU): victim: #{victim}, actual: #{actual_victim} -- live: #{live}, size: #{@size}"
|
@@ -172,11 +172,11 @@ module Xampl
|
|
172
172
|
end
|
173
173
|
|
174
174
|
def print(out = "")
|
175
|
-
out << "Cache with capacity: #{@capacity}, current size: #{@size}\n"
|
176
|
-
@cache.each
|
175
|
+
out << "Cache (LFU) with capacity: #{@capacity}, current size: #{@size}\n"
|
176
|
+
@cache.each do |key, pair|
|
177
177
|
out << sprintf(" key: '%s', value: '%s', count: %s\n",
|
178
178
|
key, pair[0], pair[1])
|
179
|
-
|
179
|
+
end
|
180
180
|
out
|
181
181
|
end
|
182
182
|
|
@@ -25,45 +25,45 @@ module Xampl
|
|
25
25
|
|
26
26
|
def sync_done
|
27
27
|
if @new_cache then
|
28
|
-
@new_cache.each
|
28
|
+
@new_cache.each do |name1, map1|
|
29
29
|
if map1 then
|
30
30
|
cache_map1 = @cache[name1]
|
31
31
|
@cache[name1] = cache_map1 = {} unless cache_map1
|
32
|
-
map1.each
|
32
|
+
map1.each do |name2, map2|
|
33
33
|
if map2 then
|
34
34
|
cache_map2 = cache_map1[name2]
|
35
35
|
#cache_map1[name2] = cache_map2 = {} unless cache_map2
|
36
36
|
cache_map1[name2] = cache_map2 = fresh_cache unless cache_map2
|
37
37
|
|
38
38
|
#cache_map2.merge!(map2)
|
39
|
-
map2.each
|
39
|
+
map2.each do |pid, xampl|
|
40
40
|
cache_map2[pid] = xampl
|
41
|
-
|
41
|
+
end
|
42
42
|
end
|
43
|
-
|
43
|
+
end
|
44
44
|
end
|
45
|
-
|
45
|
+
end
|
46
46
|
end
|
47
47
|
@new_cache = {}
|
48
48
|
end
|
49
49
|
|
50
50
|
def rollback_cleanup
|
51
|
-
@new_cache.each
|
51
|
+
@new_cache.each do |name, map|
|
52
52
|
if map then
|
53
|
-
map.each
|
53
|
+
map.each do |name2, map2|
|
54
54
|
if map2 then
|
55
|
-
map2.each
|
55
|
+
map2.each do |pid, xampl|
|
56
56
|
@changed.delete(xampl)
|
57
|
-
|
57
|
+
end
|
58
58
|
end
|
59
|
-
|
59
|
+
end
|
60
60
|
end
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
61
|
+
@changed.each do |xampl, ignore|
|
62
|
+
xampl.force_load
|
63
|
+
end
|
64
|
+
@new_cache = {}
|
65
|
+
super
|
66
|
+
end
|
67
67
|
end
|
68
68
|
|
69
69
|
def cache(xampl)
|
@@ -91,6 +91,11 @@ module Xampl
|
|
91
91
|
xampl = Xampl.lookup_in_map(@cache, klass, pid)
|
92
92
|
if xampl then
|
93
93
|
if target and target != xampl then
|
94
|
+
|
95
|
+
puts "#{File.basename(__FILE__)} #{__LINE__} CACHE CONFLICT:: klass: #{ klass }, pid: #{ pid }, target: #{ target }, cached: #{ xampl }"
|
96
|
+
dump(@cache)
|
97
|
+
caller(0).each { | trace | puts " #{trace}"}
|
98
|
+
|
94
99
|
target.invalidate
|
95
100
|
raise XamplException.new(:cache_conflict)
|
96
101
|
end
|
@@ -117,8 +122,19 @@ module Xampl
|
|
117
122
|
return nil, target
|
118
123
|
end
|
119
124
|
|
125
|
+
def dump(cache)
|
126
|
+
puts "DUMP CACHE"
|
127
|
+
cache.each do | k, v |
|
128
|
+
puts "--- [[#{k}]]"
|
129
|
+
v.each do | kk, vv |
|
130
|
+
puts "--- --- [[#{kk}]]"
|
131
|
+
puts vv.print
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
120
136
|
def read(klass, pid, target=nil)
|
121
|
-
#puts "
|
137
|
+
# puts "#{File.basename(__FILE__)} #{__LINE__} READ:: klass: #{klass} pid: #{pid} target: [[#{target}]], PM: #{ self }"
|
122
138
|
|
123
139
|
xampl, target = read_from_cache(klass, pid, target)
|
124
140
|
return xampl if xampl and !target
|
@@ -139,6 +155,9 @@ module Xampl
|
|
139
155
|
raise e
|
140
156
|
end
|
141
157
|
|
158
|
+
# puts "#{File.basename(__FILE__)} #{__LINE__} STORE IN CACHE:: xampl: #{xampl }, persister: #{ self }"
|
159
|
+
# dump(@cache)
|
160
|
+
|
142
161
|
Xampl.store_in_cache(@cache, xampl, self) { xampl }
|
143
162
|
xampl.introduce_persister(self)
|
144
163
|
|
@@ -146,8 +165,6 @@ module Xampl
|
|
146
165
|
xampl.changes_accepted
|
147
166
|
@changed.delete(xampl)
|
148
167
|
|
149
|
-
#puts " READ [#{xampl}]"
|
150
|
-
#puts " READ [#{xampl}]" if ('1145881653_1' == pid)
|
151
168
|
return xampl
|
152
169
|
end
|
153
170
|
end
|
data/lib/xamplr/xampl-object.rb
CHANGED
@@ -216,7 +216,8 @@ module Xampl
|
|
216
216
|
end
|
217
217
|
|
218
218
|
def XamplObject.realise_from_xml_string(xml_string, target=nil, tokenise=true)
|
219
|
-
|
219
|
+
xampl = FromXML.new.realise_string(xml_string, tokenise, target)
|
220
|
+
return xampl
|
220
221
|
end
|
221
222
|
|
222
223
|
def XamplObject.from_xml_string(xml_string, tokenise=true)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hutch-xamplr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Hutchison
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-04-
|
12
|
+
date: 2009-04-27 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- lib/xampl.rb
|
72
72
|
- lib/xamplr-generator.rb
|
73
73
|
- lib/xamplr.rb
|
74
|
+
- lib/xamplr/README-POSSIBLE-PROBLEMS
|
74
75
|
- lib/xamplr/TODO
|
75
76
|
- lib/xamplr/from-xml.rb
|
76
77
|
- lib/xamplr/gen-elements.xml
|