Class: Handlers::ConnectorHandler

Inherits:
BasicHandler
  • Object
show all
Defined in:
lib/handlers/connector_handler.rb

Overview

Connector events handler for connector client

Instance Attribute Summary collapse

Attributes inherited from BasicHandler

#broker, #exit_timer, #idle_timeout, #log_lib, #max_frame_size, #sasl_enabled, #sasl_mechs

Instance Method Summary collapse

Constructor Details

#initialize(broker, count, sasl_mechs, idle_timeout, max_frame_size, sasl_enabled, log_lib, exit_timer) ⇒ ConnectorHandler

Initialization of events handler for connector client

Connector events handler arguments

broker

URI of broker

count

Number of connections to create

sasl_mechs

Allowed SASL mechanisms



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/handlers/connector_handler.rb', line 34

def initialize(
  broker,
  count,
  sasl_mechs,
  idle_timeout,
  max_frame_size,
  sasl_enabled,
  log_lib,
  exit_timer
)
  super(
    broker,
    sasl_mechs,
    idle_timeout,
    max_frame_size,
    sasl_enabled,
    log_lib,
    exit_timer
  )
  # Save count of connections
  @count = count
  # Initialize array of connections
  @connections = []
end

Instance Attribute Details

#connectionsObject

Array of connections



27
28
29
# File 'lib/handlers/connector_handler.rb', line 27

def connections
  @connections
end

#countObject

Count of connections



25
26
27
# File 'lib/handlers/connector_handler.rb', line 25

def count
  @count
end

Instance Method Details

#on_connection_open(_c) ⇒ Object



82
83
84
# File 'lib/handlers/connector_handler.rb', line 82

def on_connection_open(_c)
  exit_timer.reset if exit_timer
end

#on_container_start(container) ⇒ Object

Called when the event loop starts, connecting ConnectorHandler#count number of connections



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/handlers/connector_handler.rb', line 61

def on_container_start(container)
  # Connecting count number of connections
  @count.times do
    # Save created connection(s) into array
    @connections.push(container.connect(
      # Set broker URI
      @broker,
      # Enable SASL authentication
      sasl_enabled: @sasl_enabled,
      # Enable insecure SASL mechanisms
      sasl_allow_insecure_mechs: true,
      # Set allowed SASL mechanisms
      sasl_allowed_mechs: @sasl_mechs,
      # Set idle timeout
      idle_timeout: @idle_timeout,
      # Set max frame size
      max_frame_size: @max_frame_size,
    ))
  end
end