soar_sr 1.1.21 → 1.1.22

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 617a32c56c8657120779c8984dd64e30c3aa33c5
4
- data.tar.gz: 85d0ece9ee75871b3a2a71b5fc7e11044c6458cb
3
+ metadata.gz: ec45c38cad8927ab5da79c5299c9e156b58fdd1b
4
+ data.tar.gz: a8311d31ea3e24dae061d8220610e14963a0f489
5
5
  SHA512:
6
- metadata.gz: 8f78bfe17fa64cd8b0bb32be9d5d02bb6c1531cd2c77426560cd2c97ef8a93b21f57361d7a4e5b448ba1c783c80f49a425ecb66664c9bc2610dc72eb377d0180
7
- data.tar.gz: 8bf59acbf23aa226059d3b4156f8a1deb3e0b6b54105a9f80cab4743a65546913975b49d39ba7413c22a101beeac1cb30abdd64a9598f75f0796371ee9b3bdea
6
+ metadata.gz: fe0624cd33ff382727c7a9115515ff6ee789f962bdce4ace07ef4dfe79ccabfcdd92b95c62a1ef25c338e5849dc9669d05ed91883c5d1757a43cca211a1da172
7
+ data.tar.gz: 14a2c86c5d25cebd7cb12df01e734353c8cf67b7c97afa1d9cdcccfe0c56f13349dd0819a4d57725430d6b9d3415cfcd40367ccc0b86ec5a707a0037e255cb33
data/README.md CHANGED
@@ -29,7 +29,17 @@ Or install it yourself as:
29
29
  ### Helpers
30
30
  require 'soar_sr'
31
31
  credentials = { 'username' => 'uddi', 'password' => 'uddi' }
32
- freshness = 0 # > 0 to enable cache
32
+
33
+ # Note: caching is pro-active, i.e. it will try and update once
34
+ # the entry half-life has been exceeded, at which point
35
+ # the entry freshness is reset. If update fails continuously or
36
+ # an update thread worker is not available to perform the update,
37
+ # or pro-active update is not triggered by a cache hit, once
38
+ # freshness is exceeded, the entry is forgotten and results in
39
+ # a new query to the registry on cache miss (potentially slow).
40
+ # Update worker threads have a concurrency upper limit of 10
41
+ freshness = 0 # > 0 to enable pro-active caching
42
+
33
43
  @soar_sr = SoarSr::ServiceRegistry.new('http://localhost:8080', 'hetzner.co.za', 'hetzner', credentials, freshness)
34
44
  ds = @soar_sr.domain_perspectives
35
45
  sv = @soar_sr.services
@@ -68,7 +78,7 @@ Or install it yourself as:
68
78
  sc.service_component_uri('my sc')
69
79
  sc.configure_meta_for_service_component('my sc', {'some' => 'meta'})
70
80
  sc.meta_for_service_component('my sc')
71
- sc.deregister_service_component('my sc')
81
+ sc.deregister_service_component('my sc') # This action can take up to a minute
72
82
 
73
83
  ### Service definitions
74
84
  sd.register_service_definition('my service', 'http://github.com/myservice/def.wadl')
@@ -25,7 +25,7 @@ module SoarSr
25
25
 
26
26
  def list_domain_perspectives(domain_types = SoarSr::DOMAIN_TYPES)_{
27
27
  result = @uddi.find_businesses
28
- result['data']['domain_perspectives'] = {}
28
+ result['data']['domain_perspectives'] ||= {}
29
29
 
30
30
  if has_data?(result, 'businesses')
31
31
  result['data']['businesses'].each do |business, detail|
@@ -4,13 +4,16 @@ require 'persistent-cache'
4
4
 
5
5
  module SoarSr
6
6
  class JUDDIProvider
7
+ MAX_THREADS = 10 unless defined? MAX_THREADS; MAX_THREADS.freeze
7
8
  attr_reader :broker
8
9
  attr_reader :urns
9
10
  attr_reader :cache
11
+ attr_reader :cache_freshness
10
12
 
11
13
  def initialize(urns, broker, cache_freshness)
12
14
  @urns = urns
13
15
  @broker = broker
16
+ @cache_freshness = cache_freshness
14
17
  @cache = Persistent::Cache.new("uddi-broker", cache_freshness, Persistent::Cache::STORAGE_RAM)
15
18
  end
16
19
 
@@ -29,10 +32,10 @@ module SoarSr
29
32
  end
30
33
 
31
34
  def get_service(name)
32
- cached = @cache["get_service:#{name}"]; return cached if cached
33
- value = @broker.get_service_element(name, @urns['services'])
34
- @cache["get_service:#{name}"] = value
35
- value
35
+ key = "get_service:#{name}"
36
+ lookup_and_cache(key) do
37
+ @broker.get_service_element(name, @urns['services'])
38
+ end
36
39
  end
37
40
 
38
41
  def save_service(name, description = nil, definition = nil)
@@ -47,11 +50,10 @@ module SoarSr
47
50
 
48
51
  def find_services(pattern = nil)
49
52
  pattern = pattern.nil? ? '%' : "%#{pattern}%"
50
-
51
- cached = @cache["find_services:#{pattern}"]; return cached if cached
52
- value = @broker.find_services(pattern)
53
- @cache["find_services:#{pattern}"] = value
54
- value
53
+ key = "find_services:#{pattern}"
54
+ lookup_and_cache(key) do
55
+ @broker.find_services(pattern)
56
+ end
55
57
  end
56
58
 
57
59
  def add_service_uri(service, uri)
@@ -69,17 +71,17 @@ module SoarSr
69
71
  end
70
72
 
71
73
  def service_uris(service)
72
- cached = @cache["service_uris:#{service}"]; return cached if cached
73
- value = @broker.find_element_bindings(service, @urns['services'])
74
- @cache["service_uris:#{service}"] = value
75
- value
74
+ key = "service_uris:#{service}"
75
+ lookup_and_cache(key) do
76
+ @broker.find_element_bindings(service, @urns['services'])
77
+ end
76
78
  end
77
79
 
78
80
  def get_service_component(name)
79
- cached = @cache["get_service_component:#{name}"]; return cached if cached
80
- value = @broker.get_service_element(name, @urns['service-components'])
81
- @cache["get_service_component:#{name}"] = value
82
- value
81
+ key = "get_service_component:#{name}"
82
+ lookup_and_cache(key) do
83
+ @broker.get_service_element(name, @urns['service-components'])
84
+ end
83
85
  end
84
86
 
85
87
  def save_service_component(name, description = nil, definition = nil)
@@ -94,11 +96,10 @@ module SoarSr
94
96
 
95
97
  def find_service_components(pattern = nil)
96
98
  pattern = pattern.nil? ? '%' : "%#{pattern}%"
97
- cached = @cache["find_service_components:#{pattern}"]; return cached if cached
98
-
99
- value = @broker.find_service_components(pattern)
100
- @cache["find_service_components:#{pattern}"] = value
101
- value
99
+ key = "find_service_components:#{pattern}"
100
+ lookup_and_cache(key) do
101
+ @broker.find_service_components(pattern)
102
+ end
102
103
  end
103
104
 
104
105
  def save_service_component_uri(service_component, uri)
@@ -110,10 +111,10 @@ module SoarSr
110
111
  end
111
112
 
112
113
  def find_service_component_uri(service_component)
113
- cached = @cache["find_service_component_uri:#{service_component}"]; return cached if cached
114
- value = @broker.find_element_bindings(service_component, @urns['service-components'])
115
- @cache["find_service_component_uri:#{service_component}"] = value
116
- value
114
+ key = "find_service_component_uri:#{service_component}"
115
+ lookup_and_cache(key) do
116
+ @broker.find_element_bindings(service_component, @urns['service-components'])
117
+ end
117
118
  end
118
119
 
119
120
  def save_business(key, name, description = nil, contacts = nil)
@@ -121,19 +122,19 @@ module SoarSr
121
122
  @broker.save_business(key, name, description, contacts)
122
123
  end
123
124
 
124
- def get_business(key)
125
- cached = @cache["get_business:#{key}"]; return cached if cached
126
- value = @broker.get_business(key)
127
- @cache["get_business:#{key}"] = value
128
- value
125
+ def get_business(business_key)
126
+ key = "get_business:#{business_key}"
127
+ lookup_and_cache(key) do
128
+ @broker.get_business(business_key)
129
+ end
129
130
  end
130
131
 
131
132
  def find_businesses(pattern = nil)
132
133
  pattern = pattern.nil? ? '%' : "%#{pattern}%"
133
- cached = @cache["find_businesses:#{pattern}"]; return cached if cached
134
- value = @broker.find_business(pattern)
135
- @cache["find_businesses:#{pattern}"] = value
136
- value
134
+ key = "find_businesses:#{pattern}"
135
+ lookup_and_cache(key) do
136
+ @broker.find_business(pattern)
137
+ end
137
138
  end
138
139
 
139
140
  def delete_business(key)
@@ -143,6 +144,44 @@ module SoarSr
143
144
 
144
145
  private
145
146
 
147
+ def lookup_and_cache(key, &block)
148
+ cached, refresh = lookup_and_refresh(key)
149
+ refresh_entry(key) do
150
+ block.call
151
+ end if refresh
152
+ return cached if cached
153
+ value = block.call
154
+ @cache[key] = value
155
+ value
156
+ end
157
+
158
+ def refresh_entry(key, &block)
159
+ return if Thread.list.size > MAX_THREADS
160
+ Thread.new do
161
+ begin
162
+ # thread-safety not important. no mutexes required
163
+ # we do not mind service stale cache values on
164
+ # race conditions, since we refresh on half-life
165
+ # of freshness on a best-effort basis
166
+ value = block.call
167
+ @cache[key] = value
168
+ rescue => ex
169
+ # do not update
170
+ end
171
+ end
172
+ end
173
+
174
+ def lookup_and_refresh(key)
175
+ timestamp = @cache.timestamp?(key)
176
+ halflife = @cache_freshness / 2
177
+ refresh = false
178
+ if (halflife > 0) and (timestamp)
179
+ refresh = (Time.now - timestamp) > halflife
180
+ end
181
+
182
+ return @cache[key], refresh
183
+ end
184
+
146
185
  def delete_existing_bindings(bindings)
147
186
  bindings.each do |binding, detail|
148
187
  @broker.delete_binding(binding)
@@ -1,3 +1,3 @@
1
1
  module SoarSr
2
- VERSION = "1.1.21"
2
+ VERSION = "1.1.22"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soar_sr
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.21
4
+ version: 1.1.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernst van Graan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-15 00:00:00.000000000 Z
11
+ date: 2016-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: persistent-cache-ram