cocaine-framework 0.12.0.pre.rc11 → 0.12.0.pre.rc12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cocaine/cocaine.rb +34 -8
- data/lib/cocaine/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61ff9e8e94378b608589075a7eb84926d4e45b0d
|
4
|
+
data.tar.gz: 7c362ec4035cc9c4d86bb03b7e33ea427526b0ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b125012fe2b5cfc6764f2dc8b0295ad7635ab4b5af3e870ab3758caed08d134952f6ac1e2d2bba3dbc2ffd8116c1212a09dd639792677205045d96fb57e888e6
|
7
|
+
data.tar.gz: a05ec46783f26b660ff4773a79d03f77e36fa6b6415c416a9a6bb27779456ebc799a650fbb84cf4fdade56e7a2042830d65a4dcc777d109b0d2d663010cf5d27
|
data/lib/cocaine/cocaine.rb
CHANGED
@@ -75,7 +75,9 @@ module Cocaine
|
|
75
75
|
end
|
76
76
|
|
77
77
|
# [API]
|
78
|
-
# Read-only part for shared
|
78
|
+
# Read-only part for reader shared state.
|
79
|
+
# Allows to receive unpacked objects from the channel.
|
80
|
+
# Returns tuple with message id and payload.
|
79
81
|
class RxMailbox < Mailbox
|
80
82
|
def recv(timeout=30.0)
|
81
83
|
@queue.receive timeout
|
@@ -83,7 +85,7 @@ module Cocaine
|
|
83
85
|
end
|
84
86
|
|
85
87
|
# [Detail]
|
86
|
-
# Write-only part for shared
|
88
|
+
# Write-only part for reader shared state.
|
87
89
|
class TxMailbox < Mailbox
|
88
90
|
def initialize(queue, tree, session, &block)
|
89
91
|
super queue
|
@@ -106,10 +108,17 @@ module Cocaine
|
|
106
108
|
|
107
109
|
@queue << [method, payload]
|
108
110
|
end
|
111
|
+
|
112
|
+
def error(errno, reason)
|
113
|
+
@queue << [:error, [errno, reason]]
|
114
|
+
|
115
|
+
LOG.debug "Closing RX channel #{self} due to error: [#{errno}] #{reason}"
|
116
|
+
@close.call @session
|
117
|
+
end
|
109
118
|
end
|
110
119
|
|
111
120
|
# [Detail]
|
112
|
-
#
|
121
|
+
# Reader shared state, that acts like channel. Need for channel splitting between the library and a user.
|
113
122
|
class RxChannel
|
114
123
|
attr_reader :tx, :rx
|
115
124
|
|
@@ -166,7 +175,7 @@ module Cocaine
|
|
166
175
|
class ServiceError < IOError
|
167
176
|
end
|
168
177
|
|
169
|
-
# [
|
178
|
+
# [API]
|
170
179
|
# Service actor, which can define itself via its dispatch tree.
|
171
180
|
class DefinedService < Meta
|
172
181
|
include Celluloid::IO
|
@@ -202,6 +211,9 @@ module Cocaine
|
|
202
211
|
async.run
|
203
212
|
end
|
204
213
|
|
214
|
+
protected
|
215
|
+
def reinitialize; end
|
216
|
+
|
205
217
|
private
|
206
218
|
def run
|
207
219
|
LOG.debug "Service '#{@name}' is running"
|
@@ -212,6 +224,12 @@ module Cocaine
|
|
212
224
|
async.received *decoded
|
213
225
|
end
|
214
226
|
end
|
227
|
+
rescue EOFError => err
|
228
|
+
LOG.warn "Service '#{@name}' has lost connection with the Cloud"
|
229
|
+
@socket = nil
|
230
|
+
@sessions.each do |session, (tx, rx)|
|
231
|
+
rx.error 1, err.message
|
232
|
+
end
|
215
233
|
end
|
216
234
|
|
217
235
|
def received(session, id, payload)
|
@@ -225,6 +243,8 @@ module Cocaine
|
|
225
243
|
end
|
226
244
|
|
227
245
|
def invoke(id, *args)
|
246
|
+
reinitialize if @socket.nil?
|
247
|
+
|
228
248
|
method, txtree, rxtree = @dispatch[id]
|
229
249
|
LOG.debug "Invoking #{@name}[#{id}=#{method}] with #{args}"
|
230
250
|
|
@@ -233,13 +253,11 @@ module Cocaine
|
|
233
253
|
@sessions.delete session
|
234
254
|
end
|
235
255
|
|
236
|
-
@sessions[@counter] = [txchan, rxchan.tx]
|
237
|
-
|
238
256
|
LOG.debug "<- [#{@counter}, #{id}, #{args}]"
|
239
257
|
message = MessagePack.pack([@counter, id, args])
|
240
|
-
@counter += 1
|
241
|
-
|
242
258
|
@socket.write message
|
259
|
+
@sessions[@counter] = [txchan, rxchan.tx]
|
260
|
+
@counter += 1
|
243
261
|
return txchan, rxchan.rx
|
244
262
|
end
|
245
263
|
end
|
@@ -255,16 +273,24 @@ module Cocaine
|
|
255
273
|
# Service class. All you need is name and (optionally) locator endpoint.
|
256
274
|
class Service < DefinedService
|
257
275
|
def initialize(name, host=nil, port=nil)
|
276
|
+
@options = { host: host, port: port }
|
277
|
+
|
258
278
|
locator = Locator.new host, port
|
259
279
|
tx, rx = locator.resolve name
|
260
280
|
id, payload = rx.recv
|
261
281
|
if id == :error
|
262
282
|
raise ServiceError.new payload
|
263
283
|
end
|
284
|
+
locator.terminate
|
264
285
|
|
265
286
|
endpoints, version, dispatch = payload
|
266
287
|
super name, endpoints, dispatch
|
267
288
|
end
|
289
|
+
|
290
|
+
protected
|
291
|
+
def reinitialize
|
292
|
+
initialize @name, @options[:host], @options[:port]
|
293
|
+
end
|
268
294
|
end
|
269
295
|
|
270
296
|
# [Detail]
|
data/lib/cocaine/version.rb
CHANGED