module Fluent::PluginHelper::HttpServer

Constants

Server

Public Class Methods

included(mod) click to toggle source

stop : stop http server and mark callback thread as stopped shutdown : [-] close : correct stopped threads terminate: kill thread

# File lib/fluent/plugin_helper/http_server.rb, line 40
def self.included(mod)
  mod.include Fluent::PluginHelper::Server::ServerTransportParams
end
new(*) click to toggle source
Calls superclass method Fluent::Configurable::new
# File lib/fluent/plugin_helper/http_server.rb, line 44
def initialize(*)
  super
  @_http_server = nil
end

Public Instance Methods

create_http_server(title, addr:, port:, logger:, default_app: nil, proto: nil, tls_opts: nil, &block) click to toggle source
# File lib/fluent/plugin_helper/http_server.rb, line 49
def create_http_server(title, addr:, port:, logger:, default_app: nil, proto: nil, tls_opts: nil, &block)
  logger.warn('this method is deprecated. Use #http_server_create_http_server instead')
  http_server_create_http_server(title, addr: addr, port: port, logger: logger, default_app: default_app, proto: proto, tls_opts: tls_opts, &block)
end
http_server_create_http_server(title, addr:, port:, logger:, default_app: nil, proto: nil, tls_opts: nil) { |serv| ... } click to toggle source

@param title [Symbol] the thread name. this value should be unique. @param addr [String] Listen address @param port [String] Listen port @param logger [Logger] logger used in this server @param default_app [Object] This method must have call. @param proto [Symbol] :tls or :tcp @param tls_opts [Hash] options for TLS.

# File lib/fluent/plugin_helper/http_server.rb, line 61
def http_server_create_http_server(title, addr:, port:, logger:, default_app: nil, proto: nil, tls_opts: nil, &block)
  unless block_given?
    raise ArgumentError, 'BUG: callback not specified'
  end

  if proto == :tls || (@transport_config && @transport_config.protocol == :tls)
    http_server_create_https_server(title, addr: addr, port: port, logger: logger, default_app: default_app, tls_opts: tls_opts, &block)
  else
    @_http_server = HttpServer::Server.new(addr: addr, port: port, logger: logger, default_app: default_app) do |serv|
      yield(serv)
    end

    _block_until_http_server_start do |notify|
      thread_create(title) do
        @_http_server.start(notify)
      end
    end
  end
end
http_server_create_https_server(title, addr:, port:, logger:, default_app: nil, tls_opts: nil) { |serv| ... } click to toggle source

@param title [Symbol] the thread name. this value should be unique. @param addr [String] Listen address @param port [String] Listen port @param logger [Logger] logger used in this server @param default_app [Object] This method must have call. @param tls_opts [Hash] options for TLS.

# File lib/fluent/plugin_helper/http_server.rb, line 87
def http_server_create_https_server(title, addr:, port:, logger:, default_app: nil, tls_opts: nil)
  topt =
    if tls_opts
      _http_server_overwrite_config(@transport_config, tls_opts)
    else
      @transport_config
    end
  ctx = Fluent::PluginHelper::HttpServer::SSLContextBuilder.new($log).build(topt)

  @_http_server = HttpServer::Server.new(addr: addr, port: port, logger: logger, default_app: default_app, tls_context: ctx) do |serv|
    yield(serv)
  end

  _block_until_http_server_start do |notify|
    thread_create(title) do
      @_http_server.start(notify)
    end
  end
end
stop() click to toggle source
Calls superclass method Fluent::PluginHelper::Thread#stop
# File lib/fluent/plugin_helper/http_server.rb, line 107
def stop
  if @_http_server
    @_http_server.stop
  end

  super
end

Private Instance Methods

_block_until_http_server_start() { |que| ... } click to toggle source

To block until server is ready to listen

# File lib/fluent/plugin_helper/http_server.rb, line 128
def _block_until_http_server_start
  que = Queue.new
  yield(que)
  que.pop
end
_http_server_overwrite_config(config, opts) click to toggle source
# File lib/fluent/plugin_helper/http_server.rb, line 117
def _http_server_overwrite_config(config, opts)
  conf = config.dup
  Fluent::PluginHelper::Server::SERVER_TRANSPORT_PARAMS.map(&:to_s).each do |param|
    if opts.key?(param)
      conf[param] = opts[param]
    end
  end
  conf
end