Class: LS4::GatewayService

Inherits:
Service show all
Defined in:
lib/ls4/service/gateway.rb

Direct Known Subclasses

ReadOnlyGatewayService

Instance Method Summary collapse

Methods inherited from Service

init

Methods included from EventBus::SingletonMixin

#ebus_bind!, #ebus_connect, extended

Methods included from EventBus::BusMixin

#ebus_all_slots, #ebus_disconnect!

Methods included from EventBus::DeclarerBase::Methods

#connect, #ebus_all_slots, #ebus_call_log, #ebus_call_slots, #ebus_signal_error, #ebus_signal_log, #ebus_signal_slots

Methods included from EventBus::DeclarerBase

#call_slot, #signal_slot

Instance Method Details

#rpc_add(key, data, attrs) ⇒ Object



190
191
192
# File 'lib/ls4/service/gateway.rb', line 190

def rpc_add(key, data, attrs)
	rpc_add_impl(nil, key, data, attrs)
end

#rpc_add_data(key, data) ⇒ Object



194
195
196
# File 'lib/ls4/service/gateway.rb', line 194

def rpc_add_data(key, data)
	rpc_add_impl(nil, key, data, {})
end

#rpc_add_impl(vname, key, data, attrs) ⇒ Object



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/ls4/service/gateway.rb', line 208

def rpc_add_impl(vname, key, data, attrs)
	ar = MessagePack::RPC::AsyncResult.new
	CachedMDSBus.add(key, attrs, vname) {|okey,error|
		if error
			$log.warn("failed to set a key or attributes to MDS: key=#{key.inspect}: #{error}")
			$log.debug_backtrace error.backtrace if error.is_a?(Exception)
			ar.error(error.to_s)
		else
			DataClientBus.set(okey, data) {|_,error|
				if error
					ar.error(error.to_s)
				else
					ar.result(okey)
				end
			}
		end
	}
	ar
end

#rpc_addv(vname, key, data, attrs) ⇒ Object



199
200
201
# File 'lib/ls4/service/gateway.rb', line 199

def rpc_addv(vname, key, data, attrs)
	rpc_add_impl(vname, key, data, attrs)
end

#rpc_addv_data(vname, key, data) ⇒ Object



203
204
205
# File 'lib/ls4/service/gateway.rb', line 203

def rpc_addv_data(vname, key, data)
	rpc_add_impl(vname, key, data, {})
end

#rpc_delete(key) ⇒ Object



261
262
263
# File 'lib/ls4/service/gateway.rb', line 261

def rpc_delete(key)
	rpc_delete_impl(nil, key)
end

#rpc_delete_impl(version, key) ⇒ Object



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/ls4/service/gateway.rb', line 273

def rpc_delete_impl(version, key)
	ar = MessagePack::RPC::AsyncResult.new
	CachedMDSBus.delete(key, version) {|okey,error|
		if error
			$log.warn("failed delete a key from MDS: key=#{key.inspect}: #{error}")
			$log.debug_backtrace error.backtrace if error.is_a?(Exception)
			ar.error(error.to_s)
		elsif okey
			DataClientBus.delete(okey) {|deleted,error|
				if error
					ar.error(error.to_s)
				else
					ar.result(deleted)
				end
			}
		else
			ar.result(false)
		end
	}
	ar
end

#rpc_deletet(vtime, key) ⇒ Object



265
266
267
# File 'lib/ls4/service/gateway.rb', line 265

def rpc_deletet(vtime, key)
	rpc_delete_impl(vtime, key)
end

#rpc_deletev(vname, key) ⇒ Object



269
270
271
# File 'lib/ls4/service/gateway.rb', line 269

def rpc_deletev(vname, key)
	rpc_delete_impl(vname, key)
end

#rpc_get(key) ⇒ Object



22
23
24
# File 'lib/ls4/service/gateway.rb', line 22

def rpc_get(key)
	rpc_get_impl(nil, key)
end

#rpc_get_attrs(key) ⇒ Object



30
31
32
# File 'lib/ls4/service/gateway.rb', line 30

def rpc_get_attrs(key)
	rpc_get_attrs_impl(nil, key)
end

#rpc_get_attrs_impl(version, key) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/ls4/service/gateway.rb', line 119

def rpc_get_attrs_impl(version, key)
	ar = MessagePack::RPC::AsyncResult.new
	CachedMDSBus.get_attrs(key, version) {|attrs,error|
		if error
			$log.warn("failed to get attributes from MDS: key=#{key.inspect}: #{error}")
			$log.debug_backtrace error.backtrace if error.is_a?(Exception)
			ar.error(error.to_s)
		elsif attrs
			ar.result(attrs)
		else
			ar.result(nil)
		end
	}
	ar
end

#rpc_get_data(key) ⇒ Object



26
27
28
# File 'lib/ls4/service/gateway.rb', line 26

def rpc_get_data(key)
	rpc_get_data_impl(nil, key)
end

#rpc_get_data_impl(version, key) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/ls4/service/gateway.rb', line 96

def rpc_get_data_impl(version, key)
	ar = MessagePack::RPC::AsyncResult.new
	CachedMDSBus.get_okey(key, version) {|okey,error|
		if error
			$log.warn("failed to get a key from MDS: key=#{key.inspect}: #{error}")
			$log.debug_backtrace error.backtrace if error.is_a?(Exception)
			ar.error(error.to_s)
		elsif okey
			DataClientBus.get(okey, true) {|data,error|
				if error
					$log.warn(error)
					$log.debug_backtrace error.backtrace if error.is_a?(Exception)
				end
				#data ||= ""
				ar.result(data, nil)
			}
		else
			ar.result(nil)
		end
	}
	ar
end

#rpc_get_impl(version, key) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/ls4/service/gateway.rb', line 73

def rpc_get_impl(version, key)
	ar = MessagePack::RPC::AsyncResult.new
	CachedMDSBus.get_okey_attrs(key, version) {|(okey,attrs),error|
		if error
			$log.warn("failed to get a key or attributes from MDS: key=#{key.inspect}: #{error}")
			$log.debug_backtrace error.backtrace if error.is_a?(Exception)
			ar.error(error.to_s)
		elsif okey
			DataClientBus.get(okey, true) {|data,error|
				if error
					$log.warn(error)
					$log.debug_backtrace error.backtrace if error.is_a?(Exception)
				end
				#data ||= ""
				ar.result([data,attrs])
			}
		else
			ar.result([nil,nil])
		end
	}
	ar
end

#rpc_getd_data(okey) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/ls4/service/gateway.rb', line 159

def rpc_getd_data(okey)
	ar = MessagePack::RPC::AsyncResult.new
	DataClientBus.get(okey, true) {|data,error|
		if error
			$log.warn("failed to get data from DS: okey=#{okey}: #{error} rsid=#{okey.rsid}")
			$log.debug_backtrace error.backtrace if error.is_a?(Exception)
			ar.error(error.to_s)
		else
			#data ||= ""
			ar.result(data)
		end
	}
	ar
end

#rpc_gett(vtime, key) ⇒ Object



39
40
41
# File 'lib/ls4/service/gateway.rb', line 39

def rpc_gett(vtime, key)
	rpc_get_impl(vtime, key)
end

#rpc_gett_attrs(vtime, key) ⇒ Object



47
48
49
# File 'lib/ls4/service/gateway.rb', line 47

def rpc_gett_attrs(vtime, key)
	rpc_get_attrs_impl(vtime, key)
end

#rpc_gett_data(vtime, key) ⇒ Object



43
44
45
# File 'lib/ls4/service/gateway.rb', line 43

def rpc_gett_data(vtime, key)
	rpc_get_data_impl(vtime, key)
end

#rpc_getv(vname, key) ⇒ Object



56
57
58
# File 'lib/ls4/service/gateway.rb', line 56

def rpc_getv(vname, key)
	rpc_get_impl(vname, key)
end

#rpc_getv_attrs(vname, key) ⇒ Object



64
65
66
# File 'lib/ls4/service/gateway.rb', line 64

def rpc_getv_attrs(vname, key)
	rpc_get_attrs_impl(vname, key)
end

#rpc_getv_data(vname, key) ⇒ Object



60
61
62
# File 'lib/ls4/service/gateway.rb', line 60

def rpc_getv_data(vname, key)
	rpc_get_data_impl(vname, key)
end

#rpc_read(key, offset, size) ⇒ Object



34
35
36
# File 'lib/ls4/service/gateway.rb', line 34

def rpc_read(key, offset, size)
	rpc_read_impl(nil, key, offset, size)
end

#rpc_read_impl(version, key, offset, size) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/ls4/service/gateway.rb', line 135

def rpc_read_impl(version, key, offset, size)
	ar = MessagePack::RPC::AsyncResult.new
	CachedMDSBus.get_okey(key, version) {|okey,error|
		if error
			$log.warn("failed to get a key from MDS: key=#{key.inspect}: #{error}")
			$log.debug_backtrace error.backtrace if error.is_a?(Exception)
			ar.error(error.to_s)
		elsif okey
			DataClientBus.read(okey, offset, size, true) {|data,error|
				if error
					$log.warn("failed to get data from DS: key=#{key.inspect}: #{error} rsid=#{okey.rsid}")
					$log.debug_backtrace error.backtrace if error.is_a?(Exception)
				end
				#data ||= ""
				ar.result(data)
			}
		else
			ar.result(nil)
		end
	}
	ar
end

#rpc_readd(okey, offset, size) ⇒ Object



174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/ls4/service/gateway.rb', line 174

def rpc_readd(okey, offset, size)
	ar = MessagePack::RPC::AsyncResult.new
	DataClientBus.read(okey, offset, size, true) {|data,error|
		if error
			$log.warn("failed to get data from DS: okey=#{okey}: #{error} rsid=#{okey.rsid}")
			$log.debug_backtrace error.backtrace if error.is_a?(Exception)
			ar.error(error.to_s)
		else
			#data ||= ""
			ar.result(data)
		end
	}
	ar
end

#rpc_readt(vtime, key, offset, size) ⇒ Object



51
52
53
# File 'lib/ls4/service/gateway.rb', line 51

def rpc_readt(vtime, key, offset, size)
	rpc_read_impl(vtime, key, offset, size)
end

#rpc_readv(vname, key, offset, size) ⇒ Object



68
69
70
# File 'lib/ls4/service/gateway.rb', line 68

def rpc_readv(vname, key, offset, size)
	rpc_read_impl(vname, key, offset, size)
end

#rpc_remove(key) ⇒ Object



244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/ls4/service/gateway.rb', line 244

def rpc_remove(key)
	ar = MessagePack::RPC::AsyncResult.new
	CachedMDSBus.remove(key) {|okey,error|
		if error
			$log.warn("failed remove a key from MDS: key=#{key.inspect}: #{error}")
			$log.debug_backtrace error.backtrace if error.is_a?(Exception)
			ar.error(error.to_s)
		elsif okey
			ar.result(true)
		else
			ar.result(false)
		end
	}
	ar
end

#rpc_update_attrs(key, attrs) ⇒ Object



229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/ls4/service/gateway.rb', line 229

def rpc_update_attrs(key, attrs)
	ar = MessagePack::RPC::AsyncResult.new
	CachedMDSBus.update_attrs(key, attrs) {|okey,error|
		if error
			$log.warn("failed to set a key or attributes to MDS: key=#{key.inspect}: #{error}")
			$log.debug_backtrace error.backtrace if error.is_a?(Exception)
			ar.error(error.to_s)
		else
			ar.result(okey)
		end
	}
	ar
end

#rpc_url(key) ⇒ Object



296
297
298
# File 'lib/ls4/service/gateway.rb', line 296

def rpc_url(key)
	rpc_url_impl(nil, key)
end

#rpc_url_impl(version, key) ⇒ Object



308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/ls4/service/gateway.rb', line 308

def rpc_url_impl(version, key)
	ar = MessagePack::RPC::AsyncResult.new
	CachedMDSBus.get_okey(key, version) {|okey,error|
		if error
			$log.warn("failed to get a key or attributes from MDS: key=#{key.inspect}: #{error}")
			$log.debug_backtrace error.backtrace if error.is_a?(Exception)
			ar.error(error.to_s)
		elsif okey
			DataClientBus.url(okey, true) {|url,error|
				if error
					$log.warn(error)
					$log.debug_backtrace error.backtrace if error.is_a?(Exception)
				end
				ar.result(url)
			}
		else
			ar.result(nil)
		end
	}
	ar
end

#rpc_urlt(vtime, key) ⇒ Object



300
301
302
# File 'lib/ls4/service/gateway.rb', line 300

def rpc_urlt(vtime, key)
	rpc_urlt_impl(vtime, key)
end

#rpc_urlv(vname, key) ⇒ Object



304
305
306
# File 'lib/ls4/service/gateway.rb', line 304

def rpc_urlv(vname, key)
	rpc_urlv_impl(vname, key)
end

#rpc_util_locate(key) ⇒ Object



330
331
332
333
334
335
336
337
338
339
340
341
342
# File 'lib/ls4/service/gateway.rb', line 330

def rpc_util_locate(key)
	ar = MessagePack::RPC::AsyncResult.new
	CachedMDSBus.util_locate(key) {|array,error|
		if error
			$log.warn(error)
			$log.debug_backtrace error.backtrace if error.is_a?(Exception)
			ar.error(error.to_s)
		else
			ar.result(array)
		end
	}
	ar
end