Class: Garcon::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/garcon/configuration.rb

Overview

Configuration instance

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) {|_self| ... } ⇒ undefined

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialized a configuration instance.

Yields:

  • (_self)

Yield Parameters:



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/garcon/configuration.rb', line 68

def initialize(opts = {})
  @min_threads = opts.fetch(:min_threads, [2, Garcon.processor_count].max)
  @max_threads = opts.fetch(:max_threads,     Garcon.processor_count * 100)

  @crypto = Crypto::Configuration.new
  @secret = Secret::Configuration.new

  @auto_terminate_global_executors = AtomicBoolean.new(true)
  @auto_terminate_all_executors    = AtomicBoolean.new(true)

  @global_fast_executor = Delay.new do
    Garcon.new_fast_executor(
      stop_on_exit: @auto_terminate_global_executors.value)
  end

  @global_io_executor = Delay.new do
    Garcon.new_io_executor(
      stop_on_exit: @auto_terminate_global_executors.value)
  end

  @global_timer_set = Delay.new do
    TimerSet.new(stop_on_exit: @auto_terminate_global_executors.value)
  end

  yield self if block_given?
end

Instance Attribute Details

#auto_terminate_all_executorsBoolean

Returns Defines if global executors should be auto-terminated with an ‘at_exit` callback. When set to `false` it will be the application programmer’s responsibility to ensure that the global thread pools are shutdown properly prior to application exit.

Returns:

  • (Boolean)

    Defines if global executors should be auto-terminated with an ‘at_exit` callback. When set to `false` it will be the application programmer’s responsibility to ensure that the global thread pools are shutdown properly prior to application exit.



43
44
45
# File 'lib/garcon/configuration.rb', line 43

def auto_terminate_all_executors
  @auto_terminate_all_executors
end

#auto_terminate_global_executorsBoolean

Returns Defines if global executors should be auto-terminated with an ‘at_exit` callback. When set to `false` it will be the application programmer’s responsibility to ensure that the global thread pools are shutdown properly prior to application exit.

Returns:

  • (Boolean)

    Defines if global executors should be auto-terminated with an ‘at_exit` callback. When set to `false` it will be the application programmer’s responsibility to ensure that the global thread pools are shutdown properly prior to application exit.



36
37
38
# File 'lib/garcon/configuration.rb', line 36

def auto_terminate_global_executors
  @auto_terminate_global_executors
end

#global_fast_executorObject (readonly)

Global thread pool optimized for short, fast operations.



49
50
51
# File 'lib/garcon/configuration.rb', line 49

def global_fast_executor
  @global_fast_executor
end

#global_io_executorObject (readonly)

Global thread pool optimized for long, blocking (IO) tasks.



55
56
57
# File 'lib/garcon/configuration.rb', line 55

def global_io_executor
  @global_io_executor
end

#global_timer_setObject (readonly)

Global thread pool user for global timers.



61
62
63
# File 'lib/garcon/configuration.rb', line 61

def global_timer_set
  @global_timer_set
end

#max_threadsObject

Access the maximum number of threads setting for this instance.



29
30
31
# File 'lib/garcon/configuration.rb', line 29

def max_threads
  @max_threads
end

#min_threadsObject

Access the minimum number of threads setting for this instance.



26
27
28
# File 'lib/garcon/configuration.rb', line 26

def min_threads
  @min_threads
end

Instance Method Details

#crypto(&block) ⇒ Crypto

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Access the crypto for this instance and optional configure a new crypto with the passed block.

Examples:

Garcon.config do |c|
  c.crypto.password = "!mWh0!s@y!m"
  c.crypto.salt     = "9e5f851900cad8892ac8b737b7370cbe"
end

Returns:



107
108
109
110
# File 'lib/garcon/configuration.rb', line 107

def crypto(&block)
  @crypto = Crypto::Configuration.new(&block) if block_given?
  @crypto
end

#secret(&block) ⇒ Secret

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Access the secret stash hash cash store for this instance and optional configure a new secret with the passed block.

Returns:



118
119
120
121
# File 'lib/garcon/configuration.rb', line 118

def secret(&block)
  @secret = Secret::Configuration.new(&block) if block_given?
  @secret
end

#to_hObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/garcon/configuration.rb', line 124

def to_h
  { crypto:                          crypto,
    secret:                          secret,
    blender:                         blender,
    min_threads:                     min_threads,
    max_threads:                     max_threads,
    global_timer_set:                global_timer_set,
    global_io_executor:              global_io_executor,
    global_fast_executor:            global_fast_executor,
    auto_terminate_all_executors:    auto_terminate_all_executors,
    auto_terminate_global_executors: auto_terminate_global_executors
  }.freeze
end