Class: CZTop::Monitor
- Inherits:
-
Object
- Object
- CZTop::Monitor
- Includes:
- CZMQ::FFI
- Defined in:
- lib/cztop/monitor.rb
Overview
This works only on connection oriented transports, like TCP, IPC, and TIPC.
CZMQ monitor. Listen for socket events.
This is implemented using an Actor.
Constant Summary collapse
- ZMONITOR_FPTR =
function pointer to the zmonitor() function
::CZMQ::FFI.ffi_libraries.each do |dl| fptr = dl.find_function('zmonitor') break fptr if fptr end
- EVENTS =
Returns types of valid events.
%w[ ALL CONNECTED CONNECT_DELAYED CONNECT_RETRIED LISTENING BIND_FAILED ACCEPTED ACCEPT_FAILED CLOSED CLOSE_FAILED DISCONNECTED MONITOR_STOPPED HANDSHAKE_SUCCEEDED HANDSHAKE_FAILED_NO_DETAIL HANDSHAKE_FAILED_PROTOCOL HANDSHAKE_FAILED_AUTH ].freeze
Instance Attribute Summary collapse
-
#actor ⇒ Actor
readonly
The actor behind this monitor.
Instance Method Summary collapse
-
#fd ⇒ Integer
Useful for registration in an event-loop.
-
#initialize(socket) ⇒ Monitor
constructor
A new instance of Monitor.
-
#listen(*events) ⇒ void
Configure monitor to listen for specific events.
-
#next ⇒ Message
Get next event.
-
#readable? ⇒ Boolean
Whether there’s at least one event available.
-
#start ⇒ void
Start the monitor.
-
#terminate ⇒ void
Terminates the monitor.
-
#verbose! ⇒ void
Enable verbose logging of commands and activity.
Constructor Details
#initialize(socket) ⇒ Monitor
Returns a new instance of Monitor.
24 25 26 |
# File 'lib/cztop/monitor.rb', line 24 def initialize(socket) @actor = Actor.new(ZMONITOR_FPTR, socket) end |
Instance Attribute Details
#actor ⇒ Actor (readonly)
Returns the actor behind this monitor.
29 30 31 |
# File 'lib/cztop/monitor.rb', line 29 def actor @actor end |
Instance Method Details
#fd ⇒ Integer
Useful for registration in an event-loop.
87 88 89 |
# File 'lib/cztop/monitor.rb', line 87 def fd @actor.fd end |
#listen(*events) ⇒ void
This method returns an undefined value.
Configure monitor to listen for specific events.
67 68 69 70 71 72 73 |
# File 'lib/cztop/monitor.rb', line 67 def listen(*events) events.each do |event| EVENTS.include?(event) or raise ArgumentError, "invalid event: #{event.inspect}" end @actor << ['LISTEN', *events] end |
#next ⇒ Message
Get next event. This blocks until the next event is available.
120 121 122 |
# File 'lib/cztop/monitor.rb', line 120 def next @actor.receive end |
#readable? ⇒ Boolean
Returns whether there’s at least one event available.
93 94 95 |
# File 'lib/cztop/monitor.rb', line 93 def readable? @actor.readable? end |
#start ⇒ void
This method returns an undefined value.
Start the monitor. After this, you can read events using #next.
78 79 80 81 |
# File 'lib/cztop/monitor.rb', line 78 def start @actor << 'START' @actor.wait end |
#terminate ⇒ void
This method returns an undefined value.
Terminates the monitor.
33 34 35 |
# File 'lib/cztop/monitor.rb', line 33 def terminate @actor.terminate end |
#verbose! ⇒ void
This method returns an undefined value.
Enable verbose logging of commands and activity.
40 41 42 |
# File 'lib/cztop/monitor.rb', line 40 def verbose! @actor << 'VERBOSE' end |