bzmq 0.0.1-java

Sign up to get free protection for your applications and to get access to all the features.
data/lib/bzmq.rb ADDED
@@ -0,0 +1,6 @@
1
+
2
+ require 'ffi-rzmq'
3
+
4
+ require 'bzmq/context'
5
+ require 'bzmq/socket'
6
+ require 'bzmq/sockets'
@@ -0,0 +1,12 @@
1
+
2
+ module BZMQ
3
+ ContextError = Class.new(StandardError)
4
+
5
+ class Context
6
+ def self.context(io_threads=1)
7
+ @io_threads = io_threads unless @context
8
+ raise ContextError unless @io_threads == io_threads
9
+ @context ||= ZMQ::Context.create io_threads
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,56 @@
1
+
2
+ module BZMQ
3
+ class Socket
4
+ def initialize(type, options={})
5
+ context = Context.context(options[:io_threads] || 1)
6
+ @socket = context.socket(type)
7
+ raise SocketError unless @socket
8
+ error_check { @socket.setsockopt ZMQ::LINGER, options[:linger] || -1 }
9
+ error_check { @socket.setsockopt ZMQ::RCVTIMEO, options[:timeout] || -1 }
10
+ error_check { @socket.setsockopt ZMQ::SNDTIMEO, options[:timeout] || -1 }
11
+ end
12
+
13
+ def bind(address)
14
+ @connected = error_check { @socket.bind(address) }
15
+ end
16
+
17
+ def connect(address)
18
+ @connected = error_check { @socket.connect(address) }
19
+ end
20
+
21
+ def close
22
+ !(@connected = !error_check { @socket.close })
23
+ end
24
+
25
+ def read(buffer='')
26
+ connected_error_check { @socket.recv_string buffer }
27
+ buffer
28
+ end
29
+
30
+ def write(message)
31
+ connected_error_check { @socket.send_string message }
32
+ end
33
+
34
+ private
35
+
36
+ def connected_error_check(&block)
37
+ raise SocketError, 'Not connected' unless @connected
38
+ error_check(&block)
39
+ end
40
+
41
+ def error_check(&block)
42
+ unless ZMQ::Util.resultcode_ok? block.call
43
+ raise SocketError.new(ZMQ::Util.error_string, ZMQ::Util.errno)
44
+ end
45
+ true
46
+ end
47
+ end
48
+
49
+ class SocketError < StandardError
50
+ attr_reader :error_code
51
+ def initialize(message, error_code=-1)
52
+ @error_code = error_code
53
+ super(message)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,58 @@
1
+
2
+ module BZMQ
3
+ class ReqSocket < Socket
4
+ def initialize(options={})
5
+ super(ZMQ::REQ, options)
6
+ end
7
+ end
8
+
9
+ class RepSocket < Socket
10
+ def initialize(options={})
11
+ super(ZMQ::REP, options)
12
+ end
13
+ end
14
+
15
+ class DealerSocket < Socket
16
+ def initialize(options={})
17
+ super(ZMQ::DEALER, options)
18
+ end
19
+ end
20
+
21
+ class RouterSocket < Socket
22
+ def initialize(options={})
23
+ super(ZMQ::ROUTER, options)
24
+ end
25
+ end
26
+
27
+ class PushSocket < Socket
28
+ def initialize(options={})
29
+ super(ZMQ::PUSH, options)
30
+ end
31
+ end
32
+
33
+ class PullSocket < Socket
34
+ def initialize(options={})
35
+ super(ZMQ::PULL, options)
36
+ end
37
+ end
38
+
39
+ class PubSocket < Socket
40
+ def initialize(options={})
41
+ super(ZMQ::PUB, options)
42
+ end
43
+ end
44
+
45
+ class SubSocket < Socket
46
+ def initialize(options={})
47
+ super(ZMQ::SUB, options)
48
+ end
49
+
50
+ def subscribe(topic)
51
+ error_check { @socket.setsockopt(::ZMQ::SUBSCRIBE, topic) }
52
+ end
53
+
54
+ def unsubscribe(topic)
55
+ error_check { @socket.setsockopt(::ZMQ::UNSUBSCRIBE, topic) }
56
+ end
57
+ end
58
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bzmq
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: java
7
+ authors:
8
+ - Joel Segerlind
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: ffi-rzmq
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: !binary |-
21
+ MA==
22
+ none: false
23
+ requirement: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: !binary |-
28
+ MA==
29
+ none: false
30
+ prerelease: false
31
+ type: :runtime
32
+ - !ruby/object:Gem::Dependency
33
+ name: rspec
34
+ version_requirements: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: !binary |-
39
+ MA==
40
+ none: false
41
+ requirement: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: !binary |-
46
+ MA==
47
+ none: false
48
+ prerelease: false
49
+ type: :development
50
+ - !ruby/object:Gem::Dependency
51
+ name: ruby-debug
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: !binary |-
57
+ MA==
58
+ none: false
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: !binary |-
64
+ MA==
65
+ none: false
66
+ prerelease: false
67
+ type: :development
68
+ description: Basic ZeroMQ wrapper for JRuby
69
+ email:
70
+ - joel@kogito.se
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - lib/bzmq.rb
76
+ - lib/bzmq/context.rb
77
+ - lib/bzmq/socket.rb
78
+ - lib/bzmq/sockets.rb
79
+ homepage: ''
80
+ licenses: []
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: !binary |-
90
+ MA==
91
+ none: false
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: !binary |-
97
+ MA==
98
+ none: false
99
+ requirements: []
100
+ rubyforge_project: bzmq
101
+ rubygems_version: 1.8.24
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: A thin wrapper around ffi-rzmq, providing basic functionality
105
+ test_files: []