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 +4 -4
- data/README.md +12 -2
- data/lib/soar_sr/domain_perspectives.rb +1 -1
- data/lib/soar_sr/juddi_provider.rb +74 -35
- data/lib/soar_sr/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec45c38cad8927ab5da79c5299c9e156b58fdd1b
|
4
|
+
data.tar.gz: a8311d31ea3e24dae061d8220610e14963a0f489
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
52
|
-
|
53
|
-
|
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
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
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
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
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
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
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
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
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(
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
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
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
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)
|
data/lib/soar_sr/version.rb
CHANGED
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.
|
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-
|
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
|