cocaine-framework 0.12.0.pre.rc15 → 0.12.0.pre.rc21
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 +77 -10
- data/lib/cocaine/version.rb +2 -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: a4a179f9745f3965fb70ae9220bdb64dec34a21c
|
4
|
+
data.tar.gz: 1c431053029bdbc7ecbb1ac8bd956aee17130253
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: edecbd8db23a9f4966483fd7949734fe77a2b8baec126344275c468ba153cab8d73e01b0e001e4de8ea3f0c0a25651c521318b3477c6320b0586260a661e5a7d
|
7
|
+
data.tar.gz: 20b553e34d3323e86b9b21be2e4340e30e489393a9b871a8b7245ed0004a3a37884e80d3eae299f35f9e0943a3ee712a948a46f712dd61542feea56baefe19de
|
data/lib/cocaine/cocaine.rb
CHANGED
@@ -39,7 +39,15 @@ module Cocaine
|
|
39
39
|
@port = port
|
40
40
|
end
|
41
41
|
|
42
|
-
|
42
|
+
def endpoints
|
43
|
+
@endpoints || ['::', 10053]
|
44
|
+
end
|
45
|
+
|
46
|
+
def endpoints=(endpoints)
|
47
|
+
@endpoints = endpoints
|
48
|
+
end
|
49
|
+
|
50
|
+
module_function :host, :host=, :port, :port=, :endpoints, :endpoints=
|
43
51
|
|
44
52
|
API = {
|
45
53
|
0 => [
|
@@ -56,7 +64,18 @@ module Cocaine
|
|
56
64
|
end
|
57
65
|
|
58
66
|
module RPC
|
59
|
-
|
67
|
+
CONTROL_CHANNEL = 1
|
68
|
+
|
69
|
+
HANDSHAKE = 0
|
70
|
+
|
71
|
+
HEARTBEAT = 0
|
72
|
+
TERMINATE = 1
|
73
|
+
|
74
|
+
INVOKE = 0
|
75
|
+
|
76
|
+
CHUNK = 0
|
77
|
+
ERROR = 1
|
78
|
+
CHOKE = 2
|
60
79
|
|
61
80
|
RXTREE = {
|
62
81
|
CHUNK => ['write', nil, {}],
|
@@ -200,6 +219,7 @@ module Cocaine
|
|
200
219
|
end
|
201
220
|
end
|
202
221
|
|
222
|
+
# TODO: I can check for common single-shot protocol here.
|
203
223
|
dispatch.each do |id, (method, txtree, rxtree)|
|
204
224
|
LOG.debug "Defined '#{method}' method for service #{self}"
|
205
225
|
self.metaclass.send(:define_method, method) do |*args|
|
@@ -323,6 +343,13 @@ module Cocaine
|
|
323
343
|
@endpoint = endpoint
|
324
344
|
@actors = Hash.new
|
325
345
|
@sessions = Hash.new
|
346
|
+
|
347
|
+
timeout = 60.0
|
348
|
+
@disown = after(60.0) do
|
349
|
+
LOG.debug "Terminating due to disown timer expiration (#{timeout} sec)"
|
350
|
+
# TODO: Hardcoded errno.
|
351
|
+
exit 1
|
352
|
+
end
|
326
353
|
end
|
327
354
|
|
328
355
|
def on(event, &block)
|
@@ -340,11 +367,11 @@ module Cocaine
|
|
340
367
|
private
|
341
368
|
def handshake
|
342
369
|
LOG.debug '<- Handshake'
|
343
|
-
@socket.write MessagePack::pack([
|
370
|
+
@socket.write MessagePack::pack([RPC::CONTROL_CHANNEL, RPC::HANDSHAKE, [@uuid]])
|
344
371
|
end
|
345
372
|
|
346
373
|
def health
|
347
|
-
heartbeat = MessagePack::pack([
|
374
|
+
heartbeat = MessagePack::pack([RPC::CONTROL_CHANNEL, RPC::HEARTBEAT, []])
|
348
375
|
loop do
|
349
376
|
LOG.debug '<- Heartbeat'
|
350
377
|
@socket.write heartbeat
|
@@ -364,13 +391,49 @@ module Cocaine
|
|
364
391
|
|
365
392
|
def received(session, id, payload)
|
366
393
|
LOG.debug "-> Message(#{session}, #{id}, #{payload})"
|
394
|
+
|
395
|
+
if session == RPC::CONTROL_CHANNEL
|
396
|
+
control session, id, payload
|
397
|
+
else
|
398
|
+
rpc session, id, payload
|
399
|
+
end
|
400
|
+
end
|
401
|
+
|
402
|
+
def control(session, id, payload)
|
403
|
+
LOG.debug "Processing control [#{session}, #{id}, #{payload}] message"
|
404
|
+
|
367
405
|
case id
|
368
|
-
when RPC::HANDSHAKE
|
369
406
|
when RPC::HEARTBEAT
|
407
|
+
@disown.reset
|
370
408
|
when RPC::TERMINATE
|
371
409
|
terminate *payload
|
372
|
-
|
373
|
-
|
410
|
+
else
|
411
|
+
LOG.warn "Received unknown message: [#{session}, #{id}, #{payload}]"
|
412
|
+
end
|
413
|
+
end
|
414
|
+
|
415
|
+
def rpc(session, id, payload)
|
416
|
+
LOG.debug "Processing RPC [#{session}, #{id}, #{payload}] message"
|
417
|
+
|
418
|
+
channels = @sessions.keys
|
419
|
+
if channels.empty?
|
420
|
+
min = max = 1
|
421
|
+
else
|
422
|
+
min, max = channels.min, channels.max
|
423
|
+
end
|
424
|
+
|
425
|
+
if session < min
|
426
|
+
LOG.debug "Dropping session #{session} as unexpected"
|
427
|
+
return
|
428
|
+
end
|
429
|
+
|
430
|
+
if session > max
|
431
|
+
LOG.debug "Invoking new channel #{session}"
|
432
|
+
invoke session, *payload
|
433
|
+
return
|
434
|
+
end
|
435
|
+
|
436
|
+
case id
|
374
437
|
when RPC::CHUNK, RPC::ERROR
|
375
438
|
push session, id, *payload
|
376
439
|
when RPC::CHOKE
|
@@ -411,6 +474,7 @@ module Cocaine
|
|
411
474
|
|
412
475
|
def terminate(errno, reason)
|
413
476
|
LOG.warn "Terminating [#{errno}]: #{reason}"
|
477
|
+
@socket.write MessagePack::pack([RPC::CONTROL_CHANNEL, RPC::TERMINATE, [errno, reason]])
|
414
478
|
exit errno
|
415
479
|
end
|
416
480
|
|
@@ -443,6 +507,10 @@ module Cocaine
|
|
443
507
|
opts.on('--endpoint ENDPOINT', 'Worker endpoint') do |endpoint|
|
444
508
|
options[:endpoint] = endpoint
|
445
509
|
end
|
510
|
+
|
511
|
+
opts.on('--protocol VERSION', 'Worker protocol version') do |protocol|
|
512
|
+
options[:protocol] = protocol
|
513
|
+
end
|
446
514
|
end.parse!
|
447
515
|
|
448
516
|
Cocaine::LOG.debug "Options: #{options}"
|
@@ -452,10 +520,9 @@ module Cocaine
|
|
452
520
|
exit 1
|
453
521
|
end
|
454
522
|
|
455
|
-
Default::Locator.
|
456
|
-
Default::Locator.port = Default::Locator::port.to_i
|
523
|
+
Default::Locator.endpoints = options[:locator].split(',')
|
457
524
|
|
458
|
-
Cocaine::LOG.debug "Setting default Locator
|
525
|
+
Cocaine::LOG.debug "Setting default Locator endpoints to #{Default::Locator.endpoints}"
|
459
526
|
return Worker.new(options[:app], options[:uuid], options[:endpoint])
|
460
527
|
end
|
461
528
|
end
|
data/lib/cocaine/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cocaine-framework
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.0.pre.
|
4
|
+
version: 0.12.0.pre.rc21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evgeny Safronov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|