Module: Celluloid::ZMQ

Defined in:
lib/celluloid/zmq.rb,
lib/celluloid/zmq/waker.rb,
lib/celluloid/zmq/sockets.rb,
lib/celluloid/zmq/mailbox.rb,
lib/celluloid/zmq/reactor.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

UninitializedError =
Class.new StandardError
DeadWakerError =

You can't wake the dead

Class.new IOError
VERSION =
"0.16.0.pre"

Class Attribute Summary (collapse)

Class Method Summary (collapse)

Class Attribute Details

+ (Object) context

Raises:



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

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

Class Method Details

+ (Boolean) evented?

Is this a Celluloid::ZMQ evented actor?



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

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

+ (Object) included(klass)

Included hook to pull in Celluloid



19
20
21
22
# File 'lib/celluloid/zmq.rb', line 19

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

+ (Object) init(worker_threads = 1)

Obtain a 0MQ context



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

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

+ (Object) terminate



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

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

+ (Object) wait_readable(socket)



47
48
49
50
51
52
53
54
55
# File 'lib/celluloid/zmq.rb', line 47

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

+ (Object) wait_writable(socket)



58
59
60
61
62
63
64
65
66
# File 'lib/celluloid/zmq.rb', line 58

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