zero-moo 0.1.0 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f0bab789674475cb28264d22f2a00921e0c67357
4
- data.tar.gz: 9c8bb11d05b8b355c666a5021546671aeac77075
3
+ metadata.gz: 1f0a8a0e9e7d4cc54976923a0a4540010c7db096
4
+ data.tar.gz: d827b73e8d9d834203aa693d8b1482725b7a45fb
5
5
  SHA512:
6
- metadata.gz: 81ac54f2f9ccf32ad7d46b36624ed52b25ad41e855e0fa42281851ebf6667bfa614af8885f53cef9d99837eee60cd674d71999b4d401ff3750984b84dd3ea7ed
7
- data.tar.gz: 32a28e22a66cad1ef50b7aa2679c75f6bf3b86fdc358d0172e2385709dadd57ac08b827fba63964bc5ff863447718fcc651e4babadcd23c4992778cc41b78572
6
+ metadata.gz: 2cd9011dfd67846d0efddfe20f6df7b1e51faa7d1ee0e3d9aef57f4427dffe740016202b56261805e0c1b290b0cf668e58dd31b0fbbb26fc1bf6414d99303dc5
7
+ data.tar.gz: 612c74eff5aaca1b4a8ab72e033c1991182095851ef8316df4222c9c4e1532ee6861df67e255a6295fc55cf714958261d03c5212137a9ffb06525ff58276c454
@@ -1,4 +1,5 @@
1
1
  require 'zero/moo'
2
+ require 'weakref'
2
3
  require 'ffi-rzmq'
3
4
 
4
5
  Thread.abort_on_exception
@@ -24,8 +25,11 @@ module Zero
24
25
  @context = ZMQ::Context.create(type)
25
26
  raise ContextError, "Zmq context couldn't created." unless @context
26
27
  logger.debug "Add finalizer for context termination."
27
- ObjectSpace.define_finalizer(self,
28
- proc{self.context.terminate if self.context})
28
+ ObjectSpace.define_finalizer(WeakRef.new(self),
29
+ proc{
30
+ logger.debug "terminating context ..."
31
+ self.context.terminate if self.context
32
+ })
29
33
  end
30
34
 
31
35
  protected
@@ -24,7 +24,7 @@ module Zero
24
24
  def initialize **kwargs
25
25
  @address = kwargs.delete(:address)
26
26
  kwargs[:type] = 1
27
- raise MissingAddressError,
27
+ raise Object.const_get("#{self.class.name}::MissingAddressError"),
28
28
  ":address for bind was not given" unless @address
29
29
  validate_address
30
30
  validate_port
@@ -36,6 +36,7 @@ module Zero
36
36
  #
37
37
  def push! message
38
38
  bind! unless socket
39
+ logger.debug "Push message: #{message}"
39
40
  error? socket.send_string(message), raize: MessageError
40
41
  message
41
42
  end
@@ -60,6 +61,7 @@ module Zero
60
61
  # @return [void]
61
62
  #
62
63
  def stop!
64
+ logger.debug "terminating socket ..."
63
65
  if socket.respond_to? :close
64
66
  error? socket.close, raize: SocketShutdownError
65
67
  end
@@ -82,7 +84,7 @@ module Zero
82
84
  ip = IPAddr.new(address) rescue nil
83
85
  Socket.gethostbyname(address) unless ip
84
86
  rescue SocketError => e
85
- raise InvalidAddressError,
87
+ raise Object.const_get("#{self.class.name}::InvalidAddressError"),
86
88
  "Address: #{@address.inspect} is invalid. - #{e.message}"
87
89
  end
88
90
 
@@ -92,11 +94,12 @@ module Zero
92
94
  # @return [void]
93
95
  #
94
96
  def validate_port
97
+ clazz = Object.const_get(self.class.name+"::InvalidAddressError")
95
98
  logger.debug "Validating port: #{@address.inspect}"
96
99
  port = @address.to_s[/[^:]+$/].to_s[/\d+/]
97
- raise InvalidAddressError, "Missing port in #{address}" if port.nil?
100
+ raise clazz, "Missing port in #{address}" if port.nil?
98
101
  unless (1024..65535).include? port.to_i
99
- raise InvalidAddressError,
102
+ raise clazz,
100
103
  "Out of range. Port must be between 1024 and 65535"
101
104
  end
102
105
  end
@@ -1,3 +1,4 @@
1
+ require 'weakref'
1
2
  require 'zero/moo/publisher'
2
3
 
3
4
  module Zero
@@ -31,7 +32,7 @@ module Zero
31
32
  def on_receive &block
32
33
  listen! unless thread.instance_of? Thread
33
34
  unless @receivers
34
- ObjectSpace.define_finalizer(self, proc{ stop! })
35
+ ObjectSpace.define_finalizer(WeakRef.new(self), proc{ stop! })
35
36
  end
36
37
  @receivers ||= []
37
38
  @receivers << block
@@ -64,6 +65,7 @@ module Zero
64
65
  # @return [void]
65
66
  #
66
67
  def handle_callbacks message
68
+ logger.debug "Received message: #{message}"
67
69
  receivers.to_a.each do |block|
68
70
  block.call message
69
71
  end
@@ -1,5 +1,5 @@
1
1
  module Zero
2
2
  module Moo
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zero-moo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Förster
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-16 00:00:00.000000000 Z
11
+ date: 2015-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -83,6 +83,7 @@ files:
83
83
  - bin/console
84
84
  - bin/setup
85
85
  - lib/zero/moo.rb
86
+ - lib/zero/moo/.subscriber.rb.swp
86
87
  - lib/zero/moo/communicator.rb
87
88
  - lib/zero/moo/logger.rb
88
89
  - lib/zero/moo/publisher.rb