Class: ZContext

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Class Method Details

.create_socket(type) ⇒ Object



73
74
75
# File 'lib/liquid/zmq.rb', line 73

def self.create_socket(type)
  instance.create_socket(type)
end

.dealer(opts = {}) ⇒ Object



112
113
114
# File 'lib/liquid/zmq.rb', line 112

def self.dealer(opts = {})
  instance.dealer(opts)
end

.destroyObject

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 …



84
85
86
87
88
# File 'lib/liquid/zmq.rb', line 84

def self.destroy
  instance.destroy
rescue Java::JavaLang::IllegalStateException, Java::JavaLang::NullPointerException
  # ignore broken shutdown in zeromq
end

.destroy_exception?(e) ⇒ Boolean

Returns:

  • (Boolean)


101
102
103
104
105
106
# File 'lib/liquid/zmq.rb', line 101

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



77
78
79
# File 'lib/liquid/zmq.rb', line 77

def self.destroy_socket(socket)
  instance.destroy_socket(socket)
end

.instanceObject



67
68
69
70
71
# File 'lib/liquid/zmq.rb', line 67

def self.instance
  @mutex.synchronize do
    @context ||= new
  end
end

.pub(opts = {}) ⇒ Object



124
125
126
# File 'lib/liquid/zmq.rb', line 124

def self.pub(opts = {})
  instance.pub(opts)
end

.pull(opts = {}) ⇒ Object



120
121
122
# File 'lib/liquid/zmq.rb', line 120

def self.pull(opts = {})
  instance.pull(opts)
end

.push(opts = {}) ⇒ Object



116
117
118
# File 'lib/liquid/zmq.rb', line 116

def self.push(opts = {})
  instance.push(opts)
end

.router(opts = {}) ⇒ Object



108
109
110
# File 'lib/liquid/zmq.rb', line 108

def self.router(opts = {})
  instance.router(opts)
end

.sub(opts = {}) ⇒ Object



128
129
130
# File 'lib/liquid/zmq.rb', line 128

def self.sub(opts = {})
  instance.sub(opts)
end

Instance Method Details

#create_socket_with_opts(type, opts = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/liquid/zmq.rb', line 28

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



43
44
45
# File 'lib/liquid/zmq.rb', line 43

def dealer(opts = {})
  create_socket_with_opts(ZMQ::DEALER, opts)
end

#pub(opts = {}) ⇒ Object



55
56
57
# File 'lib/liquid/zmq.rb', line 55

def pub(opts = {})
  create_socket_with_opts(ZMQ::PUB, opts)
end

#pull(opts = {}) ⇒ Object



51
52
53
# File 'lib/liquid/zmq.rb', line 51

def pull(opts = {})
  create_socket_with_opts(ZMQ::PULL, opts)
end

#push(opts = {}) ⇒ Object



47
48
49
# File 'lib/liquid/zmq.rb', line 47

def push(opts = {})
  create_socket_with_opts(ZMQ::PUSH, opts)
end

#router(opts = {}) ⇒ Object



39
40
41
# File 'lib/liquid/zmq.rb', line 39

def router(opts = {})
  create_socket_with_opts(ZMQ::ROUTER, opts)
end

#sub(opts = {}) ⇒ Object



59
60
61
# File 'lib/liquid/zmq.rb', line 59

def sub(opts = {})
  create_socket_with_opts(ZMQ::SUB, opts)
end