Class: LanGrove::Adaptor::EventMachineAdaptor

Inherits:
Base
  • Object
show all
Defined in:
lib/langrove/adaptor/event_machine_adaptor.rb

Direct Known Subclasses

QueryAdaptor

Instance Attribute Summary

Attributes inherited from Base

#logger

Instance Method Summary collapse

Methods inherited from Base

#listen, #validate_config_adaptor

Methods inherited from Base

#config_exception, #type

Constructor Details

#initialize(root, config, deamon_name) ⇒ EventMachineAdaptor

Returns a new instance of EventMachineAdaptor.



29
30
31
32
33
# File 'lib/langrove/adaptor/event_machine_adaptor.rb', line 29

def initialize( root, config, deamon_name )
  
  super
  
end

Instance Method Details

#connector(params, &block) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/langrove/adaptor/event_machine_adaptor.rb', line 117

def connector( params, &block )
  
  handler  = params[ :handler ]

  handler_class = handler[:class]
  handler_class = @demux.handler unless @demux.nil?

  @logger.info "Starting listen at #{@connect} #{@iface}:#{@port}"
  
  EventMachine::send( 

    @em_server_type, 
    @iface, 
    @port, 
    handler_class, 
    @soc_opts 

  ) do |connected_handler|
  
    yield connected_handler if block
    
  end
  
end

#path(partial) ⇒ Object



142
143
144
145
146
# File 'lib/langrove/adaptor/event_machine_adaptor.rb', line 142

def path( partial )

  return "#{DAEMON_ROOT}/#{partial}"

end

#reloadObject



19
20
21
22
23
24
25
26
27
# File 'lib/langrove/adaptor/event_machine_adaptor.rb', line 19

def reload

  #
  # OVERRIDE
  # 
  # Daemon has been called to HUP
  #

end

#reload_adaptorObject



95
96
97
98
99
# File 'lib/langrove/adaptor/event_machine_adaptor.rb', line 95

def reload_adaptor

  reload

end

#stopObject



9
10
11
12
13
14
15
16
17
# File 'lib/langrove/adaptor/event_machine_adaptor.rb', line 9

def stop
  
  #
  # OVERRIDE
  #
  # Daemon has been called to stop
  #

end

#stop_adaptorObject



89
90
91
92
93
# File 'lib/langrove/adaptor/event_machine_adaptor.rb', line 89

def stop_adaptor

  stop

end

#validate_configObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/langrove/adaptor/event_machine_adaptor.rb', line 35

def validate_config

  @type = :event_machine_adaptor
  
  @connect  = :tcp
  @iface    = '127.0.0.1'
  @port     = 12701

  if @config

    @iface    = @config[ :iface ] if @config.has_key? :iface
    @port     = @config[ :port ]  if @config.has_key? :port
    @connect  = @config[ :connect ].to_sym  if @config.has_key? :connect
    @soc_opts = @config[ :socket_options ] if @config.has_key? :socket_options

  end

  unless @soc_opts.nil?

    unless @soc_opts[ :tls_options ].nil?

      validate_tls_options( @soc_opts[ :tls_options ] )

    end

  else

    @soc_opts = {}

  end

  #
  # Assign the call signature to eventmachine's
  # TCP or UDP servers.
  #
  @em_server_type = case @connect

    when :tcp

      :start_server

    when :udp

      :open_datagram_socket

    else

      :start_server

  end

end

#validate_tls_options(options) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/langrove/adaptor/event_machine_adaptor.rb', line 101

def validate_tls_options( options )

  unless options[ :private_key_file ].nil?

    options[ :private_key_file ] = path( options[ :private_key_file ] )

  end

  unless options[ :cert_chain_file ].nil?

    options[ :cert_chain_file ] = path( options[ :cert_chain_file ] )

  end

end