bones-rpc 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-gemset +1 -1
  3. data/.ruby-version +1 -1
  4. data/bones-rpc.gemspec +1 -4
  5. data/lib/bones/rpc.rb +1 -1
  6. data/lib/bones/rpc/adapter.rb +44 -4
  7. data/lib/bones/rpc/adapter/json.rb +66 -0
  8. data/lib/bones/rpc/address.rb +6 -4
  9. data/lib/bones/rpc/backend.rb +31 -0
  10. data/lib/bones/rpc/backend/base.rb +30 -0
  11. data/lib/bones/rpc/backend/synchronous.rb +29 -0
  12. data/lib/bones/rpc/cluster.rb +18 -18
  13. data/lib/bones/rpc/connection.rb +19 -15
  14. data/lib/bones/rpc/connection/socket.rb +0 -2
  15. data/lib/bones/rpc/connection/socket/connectable.rb +15 -11
  16. data/lib/bones/rpc/context.rb +2 -2
  17. data/lib/bones/rpc/dns_resolver.rb +85 -0
  18. data/lib/bones/rpc/errors.rb +3 -0
  19. data/lib/bones/rpc/failover.rb +3 -3
  20. data/lib/bones/rpc/failover/disconnect.rb +2 -2
  21. data/lib/bones/rpc/failover/ignore.rb +2 -2
  22. data/lib/bones/rpc/failover/retry.rb +2 -2
  23. data/lib/bones/rpc/instrumentable.rb +3 -3
  24. data/lib/bones/rpc/instrumentable/log.rb +2 -2
  25. data/lib/bones/rpc/instrumentable/noop.rb +2 -2
  26. data/lib/bones/rpc/loggable.rb +8 -8
  27. data/lib/bones/rpc/node.rb +47 -37
  28. data/lib/bones/rpc/node/registry.rb +4 -0
  29. data/lib/bones/rpc/parser.rb +16 -5
  30. data/lib/bones/rpc/parser/buffer.rb +6 -2
  31. data/lib/bones/rpc/protocol/adapter_helper.rb +2 -2
  32. data/lib/bones/rpc/protocol/binary_helper.rb +2 -2
  33. data/lib/bones/rpc/read_preference.rb +3 -3
  34. data/lib/bones/rpc/read_preference/nearest.rb +3 -3
  35. data/lib/bones/rpc/read_preference/selectable.rb +4 -4
  36. data/lib/bones/rpc/readable.rb +4 -4
  37. data/lib/bones/rpc/session.rb +25 -16
  38. data/lib/bones/rpc/synchronous.rb +2 -0
  39. data/lib/bones/rpc/synchronous/connection.rb +36 -0
  40. data/lib/bones/rpc/synchronous/connection/reader.rb +59 -0
  41. data/lib/bones/rpc/synchronous/connection/socket.rb +4 -0
  42. data/lib/bones/rpc/synchronous/connection/socket/ssl.rb +57 -0
  43. data/lib/bones/rpc/synchronous/connection/socket/tcp.rb +30 -0
  44. data/lib/bones/rpc/synchronous/connection/writer.rb +86 -0
  45. data/lib/bones/rpc/synchronous/future.rb +91 -0
  46. data/lib/bones/rpc/synchronous/node.rb +45 -0
  47. data/lib/bones/rpc/uri.rb +20 -20
  48. data/lib/bones/rpc/version.rb +1 -1
  49. metadata +16 -52
  50. data/lib/bones/rpc/adapter/erlang.rb +0 -28
  51. data/lib/bones/rpc/adapter/msgpack.rb +0 -52
  52. data/lib/bones/rpc/connection/reader.rb +0 -49
  53. data/lib/bones/rpc/connection/socket/ssl.rb +0 -35
  54. data/lib/bones/rpc/connection/socket/tcp.rb +0 -28
  55. data/lib/bones/rpc/connection/writer.rb +0 -51
  56. data/lib/bones/rpc/future.rb +0 -26
@@ -1,49 +0,0 @@
1
- # encoding: utf-8
2
- module Bones
3
- module RPC
4
- class Connection
5
- class Reader
6
- include Celluloid::IO
7
-
8
- execute_block_on_receiver :initialize
9
-
10
- def initialize(connection, socket, adapter)
11
- @connection = connection
12
- @socket = socket
13
- @adapter = adapter
14
- @buffer = ""
15
- async.read
16
- end
17
-
18
- def parse(data)
19
- @buffer << data
20
- if @buffer.empty?
21
- async.read
22
- else
23
- parser = Bones::RPC::Parser.new(@buffer, @adapter)
24
- begin
25
- loop { async.send parser.read }
26
- rescue EOFError
27
- @buffer.replace(parser.buffer.to_str)
28
- end
29
- async.read
30
- end
31
- end
32
-
33
- def read
34
- loop do
35
- async.parse @socket.readpartial(4096)
36
- end
37
- rescue EOFError, Errors::ConnectionFailure => e
38
- Loggable.warn(" BONES-RPC:", "#{@connection.node.address.resolved} Reader terminating: #{e.message}", "n/a")
39
- terminate
40
- end
41
-
42
- def send(message)
43
- @connection.node.handle_message(message)
44
- end
45
-
46
- end
47
- end
48
- end
49
- end
@@ -1,35 +0,0 @@
1
- # encoding: utf-8
2
- require 'openssl'
3
-
4
- module Bones
5
- module RPC
6
- class Connection
7
- module Socket
8
-
9
- # This is a wrapper around a tcp socket.
10
- class SSL < ::Celluloid::IO::SSLSocket
11
- include Connectable
12
-
13
- # Initialize the new TCPSocket with SSL.
14
- #
15
- # @example Initialize the socket.
16
- # SSL.new("127.0.0.1", 27017)
17
- #
18
- # @param [ String ] host The host.
19
- # @param [ Integer ] port The port.
20
- #
21
- # @since 1.2.0
22
- def initialize(remote_host, remote_port, local_host = nil, local_port = nil)
23
- @host, @port = remote_host, remote_port
24
- handle_socket_errors do
25
- socket = TCPSocket.new(remote_host, remote_port, local_host, local_port)
26
- super(socket)
27
- to_io.sync_close = true
28
- connect
29
- end
30
- end
31
- end
32
- end
33
- end
34
- end
35
- end
@@ -1,28 +0,0 @@
1
- # encoding: utf-8
2
- module Bones
3
- module RPC
4
- class Connection
5
- module Socket
6
-
7
- # This is a wrapper around a ssl socket.
8
- class TCP < ::Celluloid::IO::TCPSocket
9
- include Connectable
10
-
11
- # Initialize the new TCPSocket.
12
- #
13
- # @example Initialize the socket.
14
- # TCP.new("127.0.0.1", 27017)
15
- #
16
- # @param [ String ] remote_host The host.
17
- # @param [ Integer ] remote_port The port.
18
- #
19
- # @since 1.2.0
20
- def initialize(remote_host, remote_port, local_host = nil, local_port = nil)
21
- @host, @port = remote_host, remote_port
22
- handle_socket_errors { super }
23
- end
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,51 +0,0 @@
1
- # encoding: utf-8
2
- module Bones
3
- module RPC
4
- class Connection
5
- class Writer
6
- include Celluloid::IO
7
-
8
- execute_block_on_receiver :initialize
9
- finalizer :shutdown
10
- trap_exit :reader_died
11
-
12
- def initialize(connection, socket, adapter)
13
- @connection = connection
14
- @socket = socket
15
- @adapter = adapter
16
- @resolved = @connection.node.address.resolved
17
- @buffer = ""
18
- @reader = Reader.new_link(@connection, @socket, @adapter)
19
- end
20
-
21
- def write(operations)
22
- operations.each do |message, future|
23
- message.serialize(@buffer, @adapter)
24
- message.attach(@connection.node, future) if future
25
- end
26
- @socket.write(@buffer)
27
- @buffer = ""
28
- return true
29
- rescue EOFError, Errors::ConnectionFailure => e
30
- Loggable.warn(" BONES-RPC:", "#{@resolved} Writer terminating: #{e.message}", "n/a")
31
- terminate
32
- end
33
-
34
- def shutdown
35
- if @reader && @reader.alive?
36
- @reader.unlink
37
- @reader.async.terminate
38
- end
39
- @connection.cleanup_socket(@socket)
40
- end
41
-
42
- def reader_died(actor, reason)
43
- Loggable.warn(" BONES-RPC:", "#{@resolved} Writer terminating: #{reason}", "n/a")
44
- @reader = nil
45
- terminate
46
- end
47
-
48
- end
49
- end
50
- end
51
- end
@@ -1,26 +0,0 @@
1
- # encoding: utf-8
2
- module Bones
3
- module RPC
4
- class Future < ::Celluloid::Future
5
-
6
- def initialize(*args, &block)
7
- @start = Time.now
8
- super
9
- end
10
-
11
- def signal(*args, &block)
12
- @stop = Time.now
13
- super
14
- end
15
-
16
- def runtime
17
- if @stop
18
- @stop - @start
19
- else
20
- Time.now - @start
21
- end
22
- end
23
-
24
- end
25
- end
26
- end