Class: Griffin::ServerConfigBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/griffin/server_config_builder.rb

Defined Under Namespace

Classes: ServerConfig

Constant Summary collapse

SERVERENGINE_PRIMITIVE_CONFIGS =
%i[workers bind port log pid_path log_level logger].freeze
SERVERENGINE_BLOCK_CONFIGS =
%i[before_fork after_fork].freeze
SERVERENGIEN_FIXED_CONFIGS =

Users can’t change these values

%i[daemonize worker_type worker_process_name].freeze
DEFAULT_POOL_SIZE =

The default size of thread pool TCP Connection

20
DEFAULT_CONNECTION_SIZE =
3
GRIFFIN_CONFIGS =
[
  :max_pool_size,
  :min_pool_size,
  :max_connection_size,
  :min_connection_size,
  :max_receive_message_size,
  :max_send_message_size,
  :http2_settings,
].freeze
GRPC_CONFIGS =
%i[services interceptors].freeze
DEFAULT_SERVER_CONFIG =
{
  worker_process_name: 'griffin worker',
  daemonize: false,
  log: '-', # STDOUT
  worker_type: 'process',
  workers: 1,
  bind: '0.0.0.0',
  port: 50051,
  max_pool_size: DEFAULT_POOL_SIZE,
  min_pool_size: DEFAULT_POOL_SIZE,
  max_connection_size: DEFAULT_CONNECTION_SIZE,
  min_connection_size: DEFAULT_CONNECTION_SIZE,
  interceptors: [],
  services: [],
  http2_settings: [],
}.freeze

Instance Method Summary collapse

Constructor Details

#initializeServerConfigBuilder

Returns a new instance of ServerConfigBuilder.



49
50
51
# File 'lib/griffin/server_config_builder.rb', line 49

def initialize
  @opts = DEFAULT_SERVER_CONFIG.dup
end

Instance Method Details

#buildObject



96
97
98
99
100
101
# File 'lib/griffin/server_config_builder.rb', line 96

def build
  c = ServerConfig.new
  @opts.each do |name, value|
    c.send("#{name}=", value)
  end
end

#connection_size(min, max) ⇒ Object



70
71
72
73
# File 'lib/griffin/server_config_builder.rb', line 70

def connection_size(min, max)
  @opts[:min_connection_size] = Integer(min)
  @opts[:max_connection_size] = Integer(max)
end

#http2_settings(settings) ⇒ Object



75
76
77
# File 'lib/griffin/server_config_builder.rb', line 75

def http2_settings(settings)
  @opts[:http2_settings] = settings
end

#interceptors(*value) ⇒ Object



79
80
81
# File 'lib/griffin/server_config_builder.rb', line 79

def interceptors(*value)
  @opts[:interceptors].concat(value).flatten!
end

#max_receive_message_size(value) ⇒ Object



87
88
89
# File 'lib/griffin/server_config_builder.rb', line 87

def max_receive_message_size(value)
  @opts[:max_receive_message_size] = Integer(value)
end

#max_send_message_size(value) ⇒ Object



91
92
93
# File 'lib/griffin/server_config_builder.rb', line 91

def max_send_message_size(value)
  @opts[:max_send_message_size] = Integer(value)
end

#pool_size(min, max) ⇒ Object



65
66
67
68
# File 'lib/griffin/server_config_builder.rb', line 65

def pool_size(min, max)
  @opts[:min_pool_size] = Integer(min)
  @opts[:max_pool_size] = Integer(max)
end

#services(*value) ⇒ Object



83
84
85
# File 'lib/griffin/server_config_builder.rb', line 83

def services(*value)
  @opts[:services].concat(value).flatten!
end