celluloid-zmq 0.16.1 → 0.17.0

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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +13 -7
  3. data/Gemfile +2 -8
  4. data/celluloid-zmq.gemspec +2 -5
  5. data/culture/CODE_OF_CONDUCT.md +28 -0
  6. data/culture/Gemfile +9 -0
  7. data/culture/README.md +22 -0
  8. data/culture/Rakefile +5 -0
  9. data/culture/SYNC.md +70 -0
  10. data/culture/celluloid-culture.gemspec +18 -0
  11. data/culture/gems/README.md +39 -0
  12. data/culture/gems/dependencies.yml +84 -0
  13. data/culture/gems/loader.rb +101 -0
  14. data/culture/rubocop/README.md +38 -0
  15. data/culture/rubocop/lint.yml +8 -0
  16. data/culture/rubocop/metrics.yml +15 -0
  17. data/culture/rubocop/rubocop.yml +4 -0
  18. data/culture/rubocop/style.yml +48 -0
  19. data/culture/spec/gems_spec.rb +2 -0
  20. data/culture/spec/spec_helper.rb +0 -0
  21. data/culture/spec/sync_spec.rb +2 -0
  22. data/culture/sync.rb +56 -0
  23. data/culture/tasks/rspec.rake +5 -0
  24. data/culture/tasks/rubocop.rake +2 -0
  25. data/examples/publish_subscribe.rb +8 -6
  26. data/lib/celluloid/zmq.rb +17 -3
  27. data/lib/celluloid/zmq/current.rb +2 -0
  28. data/lib/celluloid/zmq/deprecate.rb +15 -0
  29. data/lib/celluloid/zmq/mailbox.rb +1 -1
  30. data/lib/celluloid/zmq/reactor.rb +4 -3
  31. data/lib/celluloid/zmq/socket.rb +75 -0
  32. data/lib/celluloid/zmq/socket/readable.rb +46 -0
  33. data/lib/celluloid/zmq/socket/types.rb +104 -0
  34. data/lib/celluloid/zmq/socket/writable.rb +30 -0
  35. data/lib/celluloid/zmq/version.rb +1 -1
  36. data/lib/celluloid/zmq/waker.rb +4 -2
  37. data/log/test.log +23785 -0
  38. data/spec/celluloid/zmq/actor_spec.rb +1 -1
  39. data/spec/celluloid/zmq/socket_spec.rb +1 -1
  40. data/spec/celluloid/zmq_spec.rb +4 -4
  41. data/spec/spec_helper.rb +23 -0
  42. metadata +287 -35
  43. data/lib/celluloid/zmq/sockets.rb +0 -222
@@ -0,0 +1,38 @@
1
+ # About
2
+ [RuboCop](https://github.com/bbatsov/rubocop) is a ruby static code analyzer.
3
+ It's more than just a lint. It verifies the code against ruby best practices and performs code correctness analysis.
4
+ Celluloid culture doesn't always agree with all rubocop default policies and so we provide a rubocop configuration file that overrides its default behavior.
5
+
6
+ # Integration
7
+
8
+ [Integrate `celluloid/culture`](../README.md#integration), then include `culture/rupocop/.rubocop.yml` in your default rubocop config.
9
+
10
+ ##### Add celluloid/culture as GIT submodule:
11
+
12
+ * See instructions: [Integrate the `celluloid/culture` sub-module](../README.md#integration)
13
+
14
+ ##### Include `culture/rupocop/rubocop.yml` in the `.rubocop.yml` in the root of your project:
15
+ ```yml
16
+ inherit_from:
17
+ - culture/rubocop/rubocop.yml
18
+ ```
19
+
20
+ # How to add rubocop to your project
21
+
22
+ The `rubocop` gem is automatically included by `Celluloid::Sync.gems` when that is [implemented](../SYNC.md).
23
+
24
+ ##### Add a 'rubocop' target in your `Rakefile`
25
+
26
+ # Hints
27
+ It's possible to use rubocop for autocorrection of minor problems.
28
+
29
+ Always verify these changes by running:
30
+
31
+ ```sh
32
+ bundle exec rubocop
33
+ ```
34
+
35
+ Once you are ready to auto-corret the issues you are shown, run it with the `-a` option:
36
+ ```sh
37
+ bundle exec rubocop -a
38
+ ```
@@ -0,0 +1,8 @@
1
+ Lint/HandleExceptions:
2
+ Enabled: false
3
+
4
+ Lint/LiteralInCondition:
5
+ Enabled: false
6
+
7
+ Lint/UnusedBlockArgument:
8
+ Enabled: false
@@ -0,0 +1,15 @@
1
+ Metrics/MethodLength:
2
+ CountComments: false
3
+ Max: 20
4
+
5
+ Metrics/LineLength:
6
+ Max: 120
7
+
8
+ Metrics/CyclomaticComplexity:
9
+ Max: 9
10
+
11
+ Metrics/PerceivedComplexity:
12
+ Max: 9
13
+
14
+ Metrics/AbcSize:
15
+ Max: 20
@@ -0,0 +1,4 @@
1
+ inherit_from:
2
+ - lint.yml
3
+ - metrics.yml
4
+ - style.yml
@@ -0,0 +1,48 @@
1
+ Style/Documentation:
2
+ Enabled: false
3
+
4
+ Style/ModuleFunction:
5
+ Enabled: false
6
+
7
+ Style/AndOr:
8
+ Enabled: true
9
+
10
+ Style/StringLiterals:
11
+ Enabled: true
12
+ EnforcedStyle: double_quotes
13
+
14
+ Style/EachWithObject:
15
+ Enabled: true
16
+
17
+ Style/InfiniteLoop:
18
+ Enabled: false
19
+
20
+ Style/SpaceAroundEqualsInParameterDefault:
21
+ Enabled: false
22
+
23
+ Style/SpaceInsideBlockBraces:
24
+ Enabled: false
25
+
26
+ Style/AccessModifierIndentation:
27
+ Enabled: false
28
+
29
+ Style/TrailingComma:
30
+ Enabled: true
31
+ EnforcedStyleForMultiline: comma
32
+
33
+ Style/SpaceInsideBlockBraces:
34
+ Enabled: true
35
+ EnforcedStyle: space
36
+
37
+ Style/SpaceInsideHashLiteralBraces:
38
+ Enabled: true
39
+ EnforcedStyle: no_space
40
+
41
+ Style/EmptyLinesAroundAccessModifier:
42
+ Enabled: false
43
+
44
+ Style/RescueModifier:
45
+ Enabled: false
46
+
47
+ Style/GlobalVars:
48
+ Enabled: false
@@ -0,0 +1,2 @@
1
+ Rspec.describe Celluloid::Gems do
2
+ end
File without changes
@@ -0,0 +1,2 @@
1
+ Rspec.describe Celluloid::Sync do
2
+ end
data/culture/sync.rb ADDED
@@ -0,0 +1,56 @@
1
+ require "forwardable"
2
+
3
+ module Celluloid
4
+ module Sync
5
+ class << self
6
+ undef gem_path rescue nil
7
+ def gem_path
8
+ File.expand_path("../../", __FILE__)
9
+ end
10
+
11
+ undef gem_name rescue nil
12
+ def gem_name
13
+ Dir["#{File.expand_path('../../', __FILE__)}/*.gemspec"].first.gsub(".gemspec", "").split("/").last
14
+ end
15
+
16
+ undef gem_name? rescue nil
17
+ def gem_name?
18
+ !gem_name.nil?
19
+ end
20
+
21
+ undef lib_path rescue nil
22
+ def lib_path
23
+ File.expand_path("../../lib", __FILE__)
24
+ end
25
+
26
+ undef lib_gempath rescue nil
27
+ def lib_gempath
28
+ "#{lib_path}/#{gem_name.split('-').join('/')}"
29
+ end
30
+
31
+ undef scenario rescue nil
32
+ def scenario
33
+ File.basename($PROGRAM_NAME)
34
+ end
35
+
36
+ undef bundler? rescue nil
37
+ def bundler?
38
+ scenario == "bundle"
39
+ end
40
+ end
41
+
42
+ fail "Missing gemspec." unless gem_name?
43
+ $LOAD_PATH.push(gem_path)
44
+ $LOAD_PATH.push(lib_path)
45
+
46
+ # TODO: This will likely need to be done differently if INSIDE a cut gem.
47
+ if scenario == "bundle"
48
+ `cd #{gem_path}/culture; git pull origin master` if ARGV.first == "update"
49
+ end
50
+
51
+ require("#{gem_path}/culture/gems/loader")
52
+ if File.exist?(version = "#{lib_gempath}/version.rb")
53
+ require(version)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,5 @@
1
+ require "rspec/core/rake_task"
2
+
3
+ RSpec::Core::RakeTask.new(:rcov) do |task|
4
+ task.rcov = true
5
+ end
@@ -0,0 +1,2 @@
1
+ require "rubocop/rake_task"
2
+ RuboCop::RakeTask.new
@@ -1,4 +1,6 @@
1
- require 'celluloid/zmq'
1
+ require 'celluloid/zmq/current'
2
+
3
+ Celluloid::ZMQ.init
2
4
 
3
5
  class PublishSubscribe
4
6
  include Celluloid::ZMQ
@@ -6,11 +8,11 @@ class PublishSubscribe
6
8
  def run
7
9
  link = "tcp://127.0.0.1:5555"
8
10
 
9
- s1 = PubSocket.new
10
- s2 = SubSocket.new
11
- s3 = SubSocket.new
12
- s4 = SubSocket.new
13
- s5 = SubSocket.new
11
+ s1 = Socket::Pub.new
12
+ s2 = Socket::Sub.new
13
+ s3 = Socket::Sub.new
14
+ s4 = Socket::Sub.new
15
+ s5 = Socket::Sub.new
14
16
 
15
17
  s1.linger = 100
16
18
  s2.subscribe('') # receive all
data/lib/celluloid/zmq.rb CHANGED
@@ -1,16 +1,23 @@
1
1
  require 'ffi-rzmq'
2
2
 
3
- require 'celluloid'
3
+ $CELLULOID_ZMQ_BACKPORTED = (ENV["CELLULOID_ZMQ_BACKPORTED"] != "false") unless defined?($CELLULOID_ZMQ_BACKPORTED)
4
+
5
+ require ($CELLULOID_ZMQ_BACKPORTED) ? 'celluloid' : 'celluloid/current'
6
+
4
7
  require 'celluloid/zmq/mailbox'
5
8
  require 'celluloid/zmq/reactor'
6
- require 'celluloid/zmq/sockets'
9
+ require 'celluloid/zmq/socket'
7
10
  require 'celluloid/zmq/version'
8
11
  require 'celluloid/zmq/waker'
9
12
 
13
+ require 'celluloid/zmq/socket/readable'
14
+ require 'celluloid/zmq/socket/writable'
15
+ require 'celluloid/zmq/socket/types'
16
+
10
17
  module Celluloid
11
18
  # Actors which run alongside 0MQ sockets
12
19
  module ZMQ
13
- UninitializedError = Class.new StandardError
20
+ class UninitializedError < Celluloid::Error; end
14
21
 
15
22
  class << self
16
23
  attr_writer :context
@@ -65,5 +72,12 @@ module Celluloid
65
72
  end
66
73
  module_function :wait_writable
67
74
 
75
+ def result_ok?(result)
76
+ ::ZMQ::Util.resultcode_ok?(result)
77
+ end
78
+ module_function :result_ok?
79
+
68
80
  end
69
81
  end
82
+
83
+ require 'celluloid/zmq/deprecate' unless $CELLULOID_BACKPORTED == false || $CELLULOID_ZMQ_BACKPORTED == false
@@ -0,0 +1,2 @@
1
+ $CELLULOID_ZMQ_BACKPORTED = false
2
+ require "celluloid/zmq"
@@ -0,0 +1,15 @@
1
+ module Celluloid
2
+ module ZMQ
3
+ ReadableSocket = Socket::Readable
4
+ WritableSocket = Socket::Writable
5
+ RepSocket = Socket::Rep
6
+ ReqSocket = Socket::Req
7
+ DealerSocket = Socket::Dealer
8
+ RouterSocket = Socket::Router
9
+ PushSocket = Socket::Push
10
+ PullSocket = Socket::Pull
11
+ PubSocket = Socket::Pub
12
+ XPubSocket = Socket::XPub
13
+ SubSocket = Socket::Sub
14
+ end
15
+ end
@@ -1,7 +1,7 @@
1
1
  module Celluloid
2
2
  module ZMQ
3
3
  # Replacement mailbox for Celluloid::ZMQ actors
4
- class Mailbox < Celluloid::EventedMailbox
4
+ class Mailbox < Celluloid::Mailbox::Evented
5
5
  def initialize
6
6
  super(Reactor)
7
7
  end
@@ -3,10 +3,11 @@ module Celluloid
3
3
  # React to incoming 0MQ and Celluloid events. This is kinda sorta supposed
4
4
  # to resemble the Reactor design pattern.
5
5
  class Reactor
6
- extend Forwardable
7
6
 
7
+ extend Forwardable
8
8
  def_delegator :@waker, :signal, :wakeup
9
9
  def_delegator :@waker, :cleanup, :shutdown
10
+ def_delegator ZMQ, :result_ok?
10
11
 
11
12
  def initialize
12
13
  @waker = Waker.new
@@ -15,7 +16,7 @@ module Celluloid
15
16
  @writers = {}
16
17
 
17
18
  rc = @poller.register @waker.socket, ::ZMQ::POLLIN
18
- unless ::ZMQ::Util.resultcode_ok? rc
19
+ unless result_ok? rc
19
20
  raise "0MQ poll error: #{::ZMQ::Util.error_string}"
20
21
  end
21
22
  end
@@ -55,7 +56,7 @@ module Celluloid
55
56
 
56
57
  rc = @poller.poll(timeout)
57
58
 
58
- unless ::ZMQ::Util.resultcode_ok? rc
59
+ unless result_ok? rc
59
60
  raise IOError, "0MQ poll error: #{::ZMQ::Util.error_string}"
60
61
  end
61
62
 
@@ -0,0 +1,75 @@
1
+ module Celluloid
2
+ module ZMQ
3
+ class Socket
4
+ extend Forwardable
5
+ def_delegator ZMQ, :result_ok?
6
+ # Create a new socket
7
+ def initialize(type)
8
+ @socket = Celluloid::ZMQ.context.socket ::ZMQ.const_get(type.to_s.upcase)
9
+ @linger = 0
10
+ end
11
+ attr_reader :linger
12
+
13
+ # Connect to the given 0MQ address
14
+ # Address should be in the form: tcp://1.2.3.4:5678/
15
+ def connect(addr)
16
+ unless result_ok? @socket.connect addr
17
+ raise IOError, "error connecting to #{addr}: #{::ZMQ::Util.error_string}"
18
+ end
19
+ true
20
+ end
21
+
22
+ def linger=(value)
23
+ @linger = value || -1
24
+
25
+ unless result_ok? @socket.setsockopt(::ZMQ::LINGER, value)
26
+ raise IOError, "couldn't set linger: #{::ZMQ::Util.error_string}"
27
+ end
28
+ end
29
+
30
+ def identity=(value)
31
+ unless result_ok? @socket.setsockopt(::ZMQ::IDENTITY, "#{value}")
32
+ raise IOError, "couldn't set identity: #{::ZMQ::Util.error_string}"
33
+ end
34
+ #de @socket.identity = value
35
+ end
36
+
37
+ def identity
38
+ #de @socket.identity
39
+ get(::ZMQ::IDENTITY)
40
+ end
41
+
42
+ def set(option, value, length = nil)
43
+ unless result_ok? @socket.setsockopt(option, value, length)
44
+ raise IOError, "couldn't set value for option #{option}: #{::ZMQ::Util.error_string}"
45
+ end
46
+ end
47
+
48
+ def get(option)
49
+ option_value = []
50
+
51
+ unless result_ok? @socket.getsockopt(option, option_value)
52
+ raise IOError, "couldn't get value for option #{option}: #{::ZMQ::Util.error_string}"
53
+ end
54
+
55
+ option_value[0]
56
+ end
57
+
58
+ # Bind to the given 0MQ address
59
+ # Address should be in the form: tcp://1.2.3.4:5678/
60
+ def bind(addr)
61
+ unless result_ok? @socket.bind(addr)
62
+ raise IOError, "couldn't bind to #{addr}: #{::ZMQ::Util.error_string}"
63
+ end
64
+ end
65
+
66
+ # Close the socket
67
+ def close
68
+ @socket.close
69
+ end
70
+
71
+ # Hide ffi-rzmq internals
72
+ alias_method :inspect, :to_s
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,46 @@
1
+ module Celluloid
2
+ module ZMQ
3
+ class Socket
4
+ # Readable 0MQ sockets have a read method
5
+ module Readable
6
+ extend Forwardable
7
+ def_delegator ZMQ, :result_ok?
8
+
9
+ # always set LINGER on readable sockets
10
+ def bind(addr)
11
+ self.linger = @linger
12
+ super(addr)
13
+ end
14
+
15
+ def connect(addr)
16
+ self.linger = @linger
17
+ super(addr)
18
+ end
19
+
20
+ # Read a message from the socket
21
+ def read(buffer = '')
22
+ ZMQ.wait_readable(@socket) if ZMQ.evented?
23
+
24
+ unless result_ok? @socket.recv_string buffer
25
+ raise IOError, "error receiving ZMQ string: #{::ZMQ::Util.error_string}"
26
+ end
27
+ buffer
28
+ end
29
+
30
+ # Multiparts message ?
31
+ def_delegator :@socket, :more_parts?
32
+
33
+ # Reads a multipart message, stores it into the given buffer and returns
34
+ # the buffer.
35
+ def read_multipart(buffer = [])
36
+ ZMQ.wait_readable(@socket) if ZMQ.evented?
37
+
38
+ unless result_ok? @socket.recv_strings buffer
39
+ raise IOError, "error receiving ZMQ string: #{::ZMQ::Util.error_string}"
40
+ end
41
+ buffer
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end