Class: Bundesstrasse::Context

Inherits:
Object
  • Object
show all
Includes:
Errors
Defined in:
lib/bundesstrasse/context.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Errors

#errno, #error_check, #error_string

Constructor Details

#initialize(zmq_context) ⇒ Context

Returns a new instance of Context.



6
7
8
# File 'lib/bundesstrasse/context.rb', line 6

def initialize(zmq_context)
  @zmq_context = zmq_context
end

Class Method Details

.create(options = {}) ⇒ Object



27
28
29
# File 'lib/bundesstrasse/context.rb', line 27

def self.create(options={})
  new ZMQ::Context.create(options[:io_threads] || 1)
end

Instance Method Details

#socket(socket_class, options = {}) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/bundesstrasse/context.rb', line 10

def socket(socket_class, options={})
  raise ContextError.new("Context terminated") if terminated?
  zmq_socket = error_check { @zmq_context.socket(socket_class.type) }
  socket = socket_class.new(zmq_socket, options)
rescue ZMQError => e
  ContextError.raise_error(e)
end

#terminate!Object



18
19
20
21
# File 'lib/bundesstrasse/context.rb', line 18

def terminate!
  @zmq_context.terminate
  true
end

#terminated?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/bundesstrasse/context.rb', line 23

def terminated?
  @zmq_context.context.nil?
end