Class: CZTop::Proxy

Inherits:
Object
  • Object
show all
Includes:
CZMQ::FFI
Defined in:
lib/cztop/proxy.rb

Overview

Steerable proxy which switches messages between a frontend and a backend socket.

This is implemented using an Actor.

Defined Under Namespace

Classes: Configurator

Constant Summary collapse

ZPROXY_FPTR =

function pointer to the zmonitor() function

::CZMQ::FFI.ffi_libraries.each do |dl|
  fptr = dl.find_function("zproxy")
  break fptr if fptr
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProxy

Returns a new instance of Proxy.


18
19
20
# File 'lib/cztop/proxy.rb', line 18

def initialize
  @actor = Actor.new(ZPROXY_FPTR)
end

Instance Attribute Details

#actorActor (readonly)

Returns the actor behind this proxy.

Returns:

  • (Actor)

    the actor behind this proxy


23
24
25
# File 'lib/cztop/proxy.rb', line 23

def actor
  @actor
end

Instance Method Details

#backendConfigurator

Returns a configurator object which you can use to configure the backend socket.

Returns:


48
49
50
# File 'lib/cztop/proxy.rb', line 48

def backend
  @backend ||= Configurator.new(self, :backend)
end

#capture(endpoint) ⇒ void

Note:

The PULL socket has to be bound before calling this method.

This method returns an undefined value.

Captures all proxied messages and delivers them to a PULL socket bound to the specified endpoint.

Parameters:

  • endpoint (String)

    the endpoint to which the PULL socket is bound to


57
58
59
60
# File 'lib/cztop/proxy.rb', line 57

def capture(endpoint)
  @actor << ["CAPTURE", endpoint]
  @actor.wait
end

#frontendConfigurator

Returns a configurator object which you can use to configure the frontend socket.

Returns:


41
42
43
# File 'lib/cztop/proxy.rb', line 41

def frontend
  @frontend ||= Configurator.new(self, :frontend)
end

#pausevoid

Note:

This causes any messages to be queued up and potentialy hit the high-water mark on the frontend or backend socket, causing messages to be dropped or writing applications to block.

This method returns an undefined value.

Pauses proxying of any messages.


67
68
69
70
# File 'lib/cztop/proxy.rb', line 67

def pause
  @actor << "PAUSE"
  @actor.wait
end

#resumevoid

Note:

This is only needed after a call to #pause, not to start the proxy. Proxying starts as soon as the frontend and backend sockets are properly attached.

This method returns an undefined value.

Resume proxying of messages.


77
78
79
80
# File 'lib/cztop/proxy.rb', line 77

def resume
  @actor << "RESUME"
  @actor.wait
end

#terminatevoid

This method returns an undefined value.

Terminates the proxy.


27
28
29
# File 'lib/cztop/proxy.rb', line 27

def terminate
  @actor.terminate
end

#verbose!void

This method returns an undefined value.

Enable verbose logging of commands and activity.


33
34
35
36
# File 'lib/cztop/proxy.rb', line 33

def verbose!
  @actor << "VERBOSE"
  @actor.wait
end