Module: Celluloid::ZMQ

Defined in:
lib/celluloid/zmq.rb,
lib/celluloid/zmq/waker.rb,
lib/celluloid/zmq/socket.rb,
lib/celluloid/zmq/mailbox.rb,
lib/celluloid/zmq/reactor.rb,
lib/celluloid/zmq/version.rb,
lib/celluloid/zmq/deprecate.rb,
lib/celluloid/zmq/socket/types.rb,
lib/celluloid/zmq/socket/readable.rb,
lib/celluloid/zmq/socket/writable.rb

Overview

Actors which run alongside 0MQ sockets

Defined Under Namespace

Classes: Mailbox, Reactor, Socket, UninitializedError, Waker

Constant Summary collapse

DeadWakerError =

You can’t wake the dead

Class.new IOError
VERSION =
"0.17.2"
ReadableSocket =
Socket::Readable
WritableSocket =
Socket::Writable
RepSocket =
Socket::Rep
ReqSocket =
Socket::Req
DealerSocket =
Socket::Dealer
RouterSocket =
Socket::Router
PushSocket =
Socket::Push
PullSocket =
Socket::Pull
PubSocket =
Socket::Pub
XPubSocket =
Socket::XPub
SubSocket =
Socket::Sub

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.contextObject



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

def context
  fail UninitializedError, "you must initialize Celluloid::ZMQ by calling Celluloid::ZMQ.init" unless @context
  @context
end

Class Method Details

.evented?Boolean

Is this a Celluloid::ZMQ evented actor?

Returns:

  • (Boolean)


48
49
50
51
# File 'lib/celluloid/zmq.rb', line 48

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



26
27
28
29
# File 'lib/celluloid/zmq.rb', line 26

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

.init(worker_threads = 1) ⇒ Object

Obtain a 0MQ context



32
33
34
# File 'lib/celluloid/zmq.rb', line 32

def init(worker_threads = 1)
  @context ||= ::ZMQ::Context.new(worker_threads)
end

.result_ok?(result) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/celluloid/zmq.rb', line 75

def result_ok?(result)
  ::ZMQ::Util.resultcode_ok?(result)
end

.terminateObject



41
42
43
44
# File 'lib/celluloid/zmq.rb', line 41

def terminate
  @context.terminate if @context
  @context = nil
end

.wait_readable(socket) ⇒ Object



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

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

.wait_writable(socket) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'lib/celluloid/zmq.rb', line 64

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