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.



21
22
23
# File 'lib/cztop/proxy.rb', line 21

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



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

def actor
  @actor
end

Instance Method Details

#backendConfigurator

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

Returns:



54
55
56
# File 'lib/cztop/proxy.rb', line 54

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



64
65
66
67
# File 'lib/cztop/proxy.rb', line 64

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

#frontendConfigurator

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

Returns:



46
47
48
# File 'lib/cztop/proxy.rb', line 46

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.



75
76
77
78
# File 'lib/cztop/proxy.rb', line 75

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.



86
87
88
89
# File 'lib/cztop/proxy.rb', line 86

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

#terminatevoid

This method returns an undefined value.

Terminates the proxy.



30
31
32
# File 'lib/cztop/proxy.rb', line 30

def terminate
  @actor.terminate
end

#verbose!void

This method returns an undefined value.

Enable verbose logging of commands and activity.



37
38
39
40
# File 'lib/cztop/proxy.rb', line 37

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