Module: Celluloid::ZMQ

Defined in:
lib/celluloid/zmq.rb,
lib/celluloid/zmq/waker.rb,
lib/celluloid/zmq/mailbox.rb,
lib/celluloid/zmq/reactor.rb,
lib/celluloid/zmq/sockets.rb,
lib/celluloid/zmq/version.rb

Overview

Actors which run alongside 0MQ sockets

Defined Under Namespace

Modules: ReadableSocket, WritableSocket Classes: DealerSocket, Mailbox, PubSocket, PullSocket, PushSocket, Reactor, RepSocket, ReqSocket, RouterSocket, Socket, SubSocket, Waker

Constant Summary collapse

DeadWakerError =

You can’t wake the dead

Class.new IOError
VERSION =
"0.15.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.context(worker_threads = 1) ⇒ Object Also known as: init

Obtain a 0MQ context (or lazily initialize it)



23
24
25
26
# File 'lib/celluloid/zmq.rb', line 23

def context(worker_threads = 1)
  return @context if @context
  @context = ::ZMQ::Context.new(worker_threads)
end

Class Method Details

.evented?Boolean

Is this a Celluloid::ZMQ evented actor?

Returns:

  • (Boolean)


35
36
37
38
# File 'lib/celluloid/zmq.rb', line 35

def self.evented?
  actor = Thread.current[:celluloid_actor]
  actor.mailbox.is_a?(Celluloid::ZMQ::Mailbox)
end

.included(klass) ⇒ Object

Included hook to pull in Celluloid



17
18
19
20
# File 'lib/celluloid/zmq.rb', line 17

def included(klass)
  klass.send :include, ::Celluloid
  klass.mailbox_class Celluloid::ZMQ::Mailbox
end

.terminateObject



29
30
31
# File 'lib/celluloid/zmq.rb', line 29

def terminate
  @context.terminate
end

.wait_readable(socket) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/celluloid/zmq.rb', line 40

def wait_readable(socket)
  if ZMQ.evented?
    mailbox = Thread.current[:celluloid_mailbox]
    mailbox.reactor.wait_readable(socket)
  else
    raise ArgumentError, "unable to wait for ZMQ sockets outside the event loop"
  end
  nil
end

.wait_writable(socket) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/celluloid/zmq.rb', line 51

def wait_writable(socket)
  if ZMQ.evented?
    mailbox = Thread.current[:celluloid_mailbox]
    mailbox.reactor.wait_writable(socket)
  else
    raise ArgumentError, "unable to wait for ZMQ sockets outside the event loop"
  end
  nil
end