Class: ZContext
- Inherits:
-
Object
- Object
- ZContext
- Defined in:
- lib/liquid/zmq.rb
Constant Summary collapse
- DestroyExceptions =
[ Java::JavaNioChannels::AsynchronousCloseException, Java::JavaNioChannels::ClosedChannelException, Java::JavaNioChannels::ClosedSelectorException, ]
- Exceptions =
DestroyExceptions + [ Java::OrgZeromq::ZMQException, Java::Zmq::ZError::IOException, ]
Class Method Summary collapse
- .create_socket(type) ⇒ Object
- .dealer(opts = {}) ⇒ Object
-
.destroy ⇒ Object
really incredible how many exceptions a simple shutdown can throw all over the place.
- .destroy_exception?(e) ⇒ Boolean
- .destroy_socket(socket) ⇒ Object
-
.instance ⇒ Object
global context instance.
- .pub(opts = {}) ⇒ Object
- .pull(opts = {}) ⇒ Object
- .push(opts = {}) ⇒ Object
- .router(opts = {}) ⇒ Object
- .sub(opts = {}) ⇒ Object
Instance Method Summary collapse
- #create_socket_with_opts(type, opts = {}) ⇒ Object
- #dealer(opts = {}) ⇒ Object
- #pub(opts = {}) ⇒ Object
- #pull(opts = {}) ⇒ Object
- #push(opts = {}) ⇒ Object
- #router(opts = {}) ⇒ Object
- #sub(opts = {}) ⇒ Object
Class Method Details
.create_socket(type) ⇒ Object
53 54 55 |
# File 'lib/liquid/zmq.rb', line 53 def self.create_socket(type) instance.create_socket(type) end |
.dealer(opts = {}) ⇒ Object
92 93 94 |
# File 'lib/liquid/zmq.rb', line 92 def self.dealer(opts = {}) instance.dealer(opts) end |
.destroy ⇒ Object
really incredible how many exceptions a simple shutdown can throw all over the place. if it’s one thing ZMQ did never get right it is the shutdown logic …
64 65 66 67 68 |
# File 'lib/liquid/zmq.rb', line 64 def self.destroy instance.destroy rescue Java::JavaLang::IllegalStateException, Java::JavaLang::NullPointerException # ignore broken shutdown in zeromq end |
.destroy_exception?(e) ⇒ Boolean
81 82 83 84 85 86 |
# File 'lib/liquid/zmq.rb', line 81 def self.destroy_exception?(e) return true if e.is_a?(Java::OrgZeromq::ZMQException) && ZMQ::Error::ETERM.getCode == e.getErrorCode return true if e.is_a?(Java::Zmq::ZError::IOException) && DestroyExceptions.include?(e.cause.class) return true if DestroyExceptions.include?(e.class) return false end |
.destroy_socket(socket) ⇒ Object
57 58 59 |
# File 'lib/liquid/zmq.rb', line 57 def self.destroy_socket(socket) instance.destroy_socket(socket) end |
.instance ⇒ Object
global context instance
49 50 51 |
# File 'lib/liquid/zmq.rb', line 49 def self.instance @context ||= new end |
.pub(opts = {}) ⇒ Object
104 105 106 |
# File 'lib/liquid/zmq.rb', line 104 def self.pub(opts = {}) instance.pub(opts) end |
.pull(opts = {}) ⇒ Object
100 101 102 |
# File 'lib/liquid/zmq.rb', line 100 def self.pull(opts = {}) instance.pull(opts) end |
.push(opts = {}) ⇒ Object
96 97 98 |
# File 'lib/liquid/zmq.rb', line 96 def self.push(opts = {}) instance.push(opts) end |
.router(opts = {}) ⇒ Object
88 89 90 |
# File 'lib/liquid/zmq.rb', line 88 def self.router(opts = {}) instance.router(opts) end |
.sub(opts = {}) ⇒ Object
108 109 110 |
# File 'lib/liquid/zmq.rb', line 108 def self.sub(opts = {}) instance.sub(opts) end |
Instance Method Details
#create_socket_with_opts(type, opts = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/liquid/zmq.rb', line 12 def create_socket_with_opts(type, opts = {}) socket = create_socket(type) opts.each do |key, value| next if key == :bind || key == :connect socket.__send__("#{key}=", value) end socket.connect(opts[:connect]) if opts[:connect] socket.bind(opts[:bind]) if opts[:bind] socket end |
#dealer(opts = {}) ⇒ Object
27 28 29 |
# File 'lib/liquid/zmq.rb', line 27 def dealer(opts = {}) create_socket_with_opts(ZMQ::DEALER, opts) end |
#pub(opts = {}) ⇒ Object
39 40 41 |
# File 'lib/liquid/zmq.rb', line 39 def pub(opts = {}) create_socket_with_opts(ZMQ::PUB, opts) end |
#pull(opts = {}) ⇒ Object
35 36 37 |
# File 'lib/liquid/zmq.rb', line 35 def pull(opts = {}) create_socket_with_opts(ZMQ::PULL, opts) end |
#push(opts = {}) ⇒ Object
31 32 33 |
# File 'lib/liquid/zmq.rb', line 31 def push(opts = {}) create_socket_with_opts(ZMQ::PUSH, opts) end |
#router(opts = {}) ⇒ Object
23 24 25 |
# File 'lib/liquid/zmq.rb', line 23 def router(opts = {}) create_socket_with_opts(ZMQ::ROUTER, opts) end |
#sub(opts = {}) ⇒ Object
43 44 45 |
# File 'lib/liquid/zmq.rb', line 43 def sub(opts = {}) create_socket_with_opts(ZMQ::SUB, opts) end |