bones-rpc-celluloid 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/bones-rpc-celluloid.gemspec +26 -0
- data/lib/bones-rpc-celluloid.rb +2 -0
- data/lib/bones/rpc/backend/celluloid.rb +32 -0
- data/lib/bones/rpc/celluloid.rb +3 -0
- data/lib/bones/rpc/celluloid/connection.rb +28 -0
- data/lib/bones/rpc/celluloid/connection/reader.rb +51 -0
- data/lib/bones/rpc/celluloid/connection/socket.rb +4 -0
- data/lib/bones/rpc/celluloid/connection/socket/ssl.rb +37 -0
- data/lib/bones/rpc/celluloid/connection/socket/tcp.rb +30 -0
- data/lib/bones/rpc/celluloid/connection/writer.rb +53 -0
- data/lib/bones/rpc/celluloid/future.rb +28 -0
- data/lib/bones/rpc/celluloid/node.rb +18 -0
- data/lib/bones/rpc/celluloid/version.rb +8 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ded1e004f22050133985b6f4c3f1c517bc5649fd
|
4
|
+
data.tar.gz: fcc3a51cc19caef047249e380bc478bfa1a1e5d1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4e9faae324925e1d36720e7c6295bc00eab33ffcb52af89e02ff6ef2aa56052863fda2f4ccc2829dbefe9c9e44157258a80849d7639182fa89aa57c992b79bac
|
7
|
+
data.tar.gz: e4cf65caf251b772f8e3cb87efc490e023385faebdfdc344e7aa8ef723f24739a575a01dba91e29f8cbdc90198773b397cfe9e7416951c6842e430949976e8fa
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
bones-rpc
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.0.0
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Andrew Bennett
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Bones::RPC::Celluloid
|
2
|
+
|
3
|
+
Bones::RPC asynchronous client for ruby
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'bones-rpc-celluloid'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install bones-rpc-celluloid
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bones/rpc/celluloid/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bones-rpc-celluloid"
|
8
|
+
spec.version = Bones::RPC::Celluloid::VERSION
|
9
|
+
spec.authors = ["Andrew Bennett"]
|
10
|
+
spec.email = ["andrew@pagodabox.com"]
|
11
|
+
spec.description = %q{Bones::RPC asynchronous client for ruby}
|
12
|
+
spec.summary = %q{Bones::RPC asynchronous client for ruby}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "bones-rpc"
|
22
|
+
spec.add_dependency "celluloid-io", ">= 0.14.1"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'bones/rpc/backend'
|
3
|
+
|
4
|
+
module Bones
|
5
|
+
module RPC
|
6
|
+
module Backend
|
7
|
+
module Celluloid
|
8
|
+
|
9
|
+
@backend_name = :celluloid
|
10
|
+
|
11
|
+
def setup
|
12
|
+
require 'celluloid/io'
|
13
|
+
require 'bones/rpc/celluloid/node'
|
14
|
+
end
|
15
|
+
|
16
|
+
def connection_class
|
17
|
+
::Bones::RPC::Celluloid::Connection
|
18
|
+
end
|
19
|
+
|
20
|
+
def future_class
|
21
|
+
::Bones::RPC::Celluloid::Future
|
22
|
+
end
|
23
|
+
|
24
|
+
def node_class
|
25
|
+
::Bones::RPC::Celluloid::Node
|
26
|
+
end
|
27
|
+
|
28
|
+
Backend.register self
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'bones/rpc/connection'
|
3
|
+
|
4
|
+
module Bones
|
5
|
+
module RPC
|
6
|
+
module Celluloid
|
7
|
+
|
8
|
+
# This class contains behaviour of Bones::RPC socket connections.
|
9
|
+
#
|
10
|
+
# @since 0.0.1
|
11
|
+
class Connection < ::Bones::RPC::Connection
|
12
|
+
|
13
|
+
require 'bones/rpc/celluloid/connection/reader'
|
14
|
+
require 'bones/rpc/celluloid/connection/socket'
|
15
|
+
require 'bones/rpc/celluloid/connection/writer'
|
16
|
+
|
17
|
+
writer_class ::Bones::RPC::Celluloid::Connection::Writer
|
18
|
+
|
19
|
+
def write(operations)
|
20
|
+
with_connection do |socket|
|
21
|
+
writer.write(operations)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Bones
|
3
|
+
module RPC
|
4
|
+
module Celluloid
|
5
|
+
class Connection
|
6
|
+
class Reader
|
7
|
+
include ::Celluloid::IO
|
8
|
+
|
9
|
+
execute_block_on_receiver :initialize
|
10
|
+
|
11
|
+
def initialize(connection, socket, adapter)
|
12
|
+
@connection = connection
|
13
|
+
@socket = socket
|
14
|
+
@adapter = adapter
|
15
|
+
@buffer = ""
|
16
|
+
async.read
|
17
|
+
end
|
18
|
+
|
19
|
+
def parse(data)
|
20
|
+
@buffer << data
|
21
|
+
if @buffer.empty?
|
22
|
+
async.read
|
23
|
+
else
|
24
|
+
parser = Bones::RPC::Parser.new(@buffer, @adapter)
|
25
|
+
begin
|
26
|
+
loop { async.send parser.read }
|
27
|
+
rescue EOFError
|
28
|
+
@buffer.replace(parser.buffer.to_str)
|
29
|
+
end
|
30
|
+
async.read
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def read
|
35
|
+
loop do
|
36
|
+
async.parse @socket.readpartial(4096)
|
37
|
+
end
|
38
|
+
rescue EOFError, Errors::ConnectionFailure => e
|
39
|
+
Loggable.warn(" BONES-RPC:", "#{@connection.node.address.resolved} Reader terminating: #{e.message}", "n/a")
|
40
|
+
terminate
|
41
|
+
end
|
42
|
+
|
43
|
+
def send(message)
|
44
|
+
@connection.node.handle_message(message)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'openssl'
|
3
|
+
|
4
|
+
module Bones
|
5
|
+
module RPC
|
6
|
+
module Celluloid
|
7
|
+
class Connection
|
8
|
+
module Socket
|
9
|
+
|
10
|
+
# This is a wrapper around a tcp socket.
|
11
|
+
class SSL < ::Celluloid::IO::SSLSocket
|
12
|
+
include ::Bones::RPC::Connection::Socket::Connectable
|
13
|
+
|
14
|
+
# Initialize the new TCPSocket with SSL.
|
15
|
+
#
|
16
|
+
# @example Initialize the socket.
|
17
|
+
# SSL.new("127.0.0.1", 27017)
|
18
|
+
#
|
19
|
+
# @param [ String ] host The host.
|
20
|
+
# @param [ Integer ] port The port.
|
21
|
+
#
|
22
|
+
# @since 1.2.0
|
23
|
+
def initialize(remote_host, remote_port, local_host = nil, local_port = nil)
|
24
|
+
@host, @port = remote_host, remote_port
|
25
|
+
handle_socket_errors do
|
26
|
+
socket = TCPSocket.new(remote_host, remote_port, local_host, local_port)
|
27
|
+
super(socket)
|
28
|
+
to_io.sync_close = true
|
29
|
+
connect
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Bones
|
3
|
+
module RPC
|
4
|
+
module Celluloid
|
5
|
+
class Connection
|
6
|
+
module Socket
|
7
|
+
|
8
|
+
# This is a wrapper around a tcp socket.
|
9
|
+
class TCP < ::Celluloid::IO::TCPSocket
|
10
|
+
include ::Bones::RPC::Connection::Socket::Connectable
|
11
|
+
|
12
|
+
# Initialize the new TCPSocket.
|
13
|
+
#
|
14
|
+
# @example Initialize the socket.
|
15
|
+
# TCP.new("127.0.0.1", 27017)
|
16
|
+
#
|
17
|
+
# @param [ String ] remote_host The host.
|
18
|
+
# @param [ Integer ] remote_port The port.
|
19
|
+
#
|
20
|
+
# @since 0.0.1
|
21
|
+
def initialize(remote_host, remote_port, local_host = nil, local_port = nil)
|
22
|
+
@host, @port = remote_host, remote_port
|
23
|
+
handle_socket_errors { super }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Bones
|
3
|
+
module RPC
|
4
|
+
module Celluloid
|
5
|
+
class Connection
|
6
|
+
class Writer
|
7
|
+
include ::Celluloid::IO
|
8
|
+
|
9
|
+
execute_block_on_receiver :initialize
|
10
|
+
finalizer :shutdown
|
11
|
+
trap_exit :reader_died
|
12
|
+
|
13
|
+
def initialize(connection, socket, adapter)
|
14
|
+
@connection = connection
|
15
|
+
@socket = socket
|
16
|
+
@adapter = adapter
|
17
|
+
@resolved = @connection.node.address.resolved
|
18
|
+
@buffer = ""
|
19
|
+
@reader = Reader.new_link(@connection, @socket, @adapter)
|
20
|
+
end
|
21
|
+
|
22
|
+
def write(operations)
|
23
|
+
operations.each do |message, future|
|
24
|
+
message.serialize(@buffer, @adapter)
|
25
|
+
message.attach(@connection.node, future) if future
|
26
|
+
end
|
27
|
+
@socket.write(@buffer)
|
28
|
+
@buffer = ""
|
29
|
+
return true
|
30
|
+
rescue EOFError, Errors::ConnectionFailure => e
|
31
|
+
Loggable.warn(" BONES-RPC:", "#{@resolved} Writer terminating: #{e.message}", "n/a")
|
32
|
+
terminate
|
33
|
+
end
|
34
|
+
|
35
|
+
def shutdown
|
36
|
+
if @reader && @reader.alive?
|
37
|
+
@reader.unlink
|
38
|
+
@reader.async.terminate
|
39
|
+
end
|
40
|
+
@connection.cleanup_socket(@socket)
|
41
|
+
end
|
42
|
+
|
43
|
+
def reader_died(actor, reason)
|
44
|
+
Loggable.warn(" BONES-RPC:", "#{@resolved} Writer terminating: #{reason}", "n/a")
|
45
|
+
@reader = nil
|
46
|
+
terminate
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Bones
|
3
|
+
module RPC
|
4
|
+
module Celluloid
|
5
|
+
class Future < ::Celluloid::Future
|
6
|
+
|
7
|
+
def initialize(*args, &block)
|
8
|
+
@start = Time.now
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def signal(*args, &block)
|
13
|
+
@stop = Time.now
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
def runtime
|
18
|
+
if @stop
|
19
|
+
@stop - @start
|
20
|
+
else
|
21
|
+
Time.now - @start
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'bones/rpc/node'
|
3
|
+
require 'bones/rpc/celluloid/connection'
|
4
|
+
require 'bones/rpc/celluloid/future'
|
5
|
+
|
6
|
+
module Bones
|
7
|
+
module RPC
|
8
|
+
module Celluloid
|
9
|
+
|
10
|
+
# Represents a client to a node in a server cluster.
|
11
|
+
#
|
12
|
+
# @since 0.0.1
|
13
|
+
class Node < ::Bones::RPC::Node
|
14
|
+
include ::Celluloid
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bones-rpc-celluloid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Bennett
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bones-rpc
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: celluloid-io
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.14.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.14.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Bones::RPC asynchronous client for ruby
|
70
|
+
email:
|
71
|
+
- andrew@pagodabox.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .ruby-gemset
|
78
|
+
- .ruby-version
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bones-rpc-celluloid.gemspec
|
84
|
+
- lib/bones-rpc-celluloid.rb
|
85
|
+
- lib/bones/rpc/backend/celluloid.rb
|
86
|
+
- lib/bones/rpc/celluloid.rb
|
87
|
+
- lib/bones/rpc/celluloid/connection.rb
|
88
|
+
- lib/bones/rpc/celluloid/connection/reader.rb
|
89
|
+
- lib/bones/rpc/celluloid/connection/socket.rb
|
90
|
+
- lib/bones/rpc/celluloid/connection/socket/ssl.rb
|
91
|
+
- lib/bones/rpc/celluloid/connection/socket/tcp.rb
|
92
|
+
- lib/bones/rpc/celluloid/connection/writer.rb
|
93
|
+
- lib/bones/rpc/celluloid/future.rb
|
94
|
+
- lib/bones/rpc/celluloid/node.rb
|
95
|
+
- lib/bones/rpc/celluloid/version.rb
|
96
|
+
homepage: ''
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.0.5
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: Bones::RPC asynchronous client for ruby
|
120
|
+
test_files: []
|