garcun 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitattributes +17 -0
- data/.gitignore +197 -0
- data/.rspec +2 -0
- data/Gemfile +22 -0
- data/LICENSE +201 -0
- data/README.md +521 -0
- data/Rakefile +47 -0
- data/garcun.gemspec +83 -0
- data/lib/garcon.rb +290 -0
- data/lib/garcon/chef/chef_helpers.rb +343 -0
- data/lib/garcon/chef/coerce/coercer.rb +134 -0
- data/lib/garcon/chef/coerce/coercions/boolean_definitions.rb +34 -0
- data/lib/garcon/chef/coerce/coercions/date_definitions.rb +32 -0
- data/lib/garcon/chef/coerce/coercions/date_time_definitions.rb +32 -0
- data/lib/garcon/chef/coerce/coercions/fixnum_definitions.rb +34 -0
- data/lib/garcon/chef/coerce/coercions/float_definitions.rb +32 -0
- data/lib/garcon/chef/coerce/coercions/hash_definitions.rb +29 -0
- data/lib/garcon/chef/coerce/coercions/integer_definitions.rb +31 -0
- data/lib/garcon/chef/coerce/coercions/string_definitions.rb +45 -0
- data/lib/garcon/chef/coerce/coercions/time_definitions.rb +32 -0
- data/lib/garcon/chef/handler/devreporter.rb +127 -0
- data/lib/garcon/chef/log.rb +64 -0
- data/lib/garcon/chef/node.rb +100 -0
- data/lib/garcon/chef/provider/civilize.rb +209 -0
- data/lib/garcon/chef/provider/development.rb +159 -0
- data/lib/garcon/chef/provider/download.rb +420 -0
- data/lib/garcon/chef/provider/house_keeping.rb +265 -0
- data/lib/garcon/chef/provider/node_cache.rb +31 -0
- data/lib/garcon/chef/provider/partial.rb +183 -0
- data/lib/garcon/chef/provider/recovery.rb +80 -0
- data/lib/garcon/chef/provider/zip_file.rb +271 -0
- data/lib/garcon/chef/resource/attribute.rb +52 -0
- data/lib/garcon/chef/resource/base_dsl.rb +174 -0
- data/lib/garcon/chef/resource/blender.rb +140 -0
- data/lib/garcon/chef/resource/lazy_eval.rb +66 -0
- data/lib/garcon/chef/resource/resource_name.rb +109 -0
- data/lib/garcon/chef/secret_bag.rb +204 -0
- data/lib/garcon/chef/validations.rb +76 -0
- data/lib/garcon/chef_inclusions.rb +151 -0
- data/lib/garcon/configuration.rb +138 -0
- data/lib/garcon/core_ext.rb +39 -0
- data/lib/garcon/core_ext/array.rb +27 -0
- data/lib/garcon/core_ext/binding.rb +64 -0
- data/lib/garcon/core_ext/boolean.rb +66 -0
- data/lib/garcon/core_ext/duration.rb +271 -0
- data/lib/garcon/core_ext/enumerable.rb +34 -0
- data/lib/garcon/core_ext/file.rb +127 -0
- data/lib/garcon/core_ext/filetest.rb +62 -0
- data/lib/garcon/core_ext/hash.rb +279 -0
- data/lib/garcon/core_ext/kernel.rb +159 -0
- data/lib/garcon/core_ext/lazy.rb +222 -0
- data/lib/garcon/core_ext/method_access.rb +243 -0
- data/lib/garcon/core_ext/module.rb +92 -0
- data/lib/garcon/core_ext/nil.rb +53 -0
- data/lib/garcon/core_ext/numeric.rb +44 -0
- data/lib/garcon/core_ext/object.rb +342 -0
- data/lib/garcon/core_ext/pathname.rb +152 -0
- data/lib/garcon/core_ext/process.rb +41 -0
- data/lib/garcon/core_ext/random.rb +497 -0
- data/lib/garcon/core_ext/string.rb +312 -0
- data/lib/garcon/core_ext/struct.rb +49 -0
- data/lib/garcon/core_ext/symbol.rb +170 -0
- data/lib/garcon/core_ext/time.rb +234 -0
- data/lib/garcon/exceptions.rb +101 -0
- data/lib/garcon/inflections.rb +237 -0
- data/lib/garcon/inflections/defaults.rb +79 -0
- data/lib/garcon/inflections/inflections.rb +182 -0
- data/lib/garcon/inflections/rules_collection.rb +37 -0
- data/lib/garcon/secret.rb +271 -0
- data/lib/garcon/stash/format.rb +114 -0
- data/lib/garcon/stash/journal.rb +226 -0
- data/lib/garcon/stash/queue.rb +83 -0
- data/lib/garcon/stash/serializer.rb +86 -0
- data/lib/garcon/stash/store.rb +435 -0
- data/lib/garcon/task.rb +31 -0
- data/lib/garcon/task/atomic.rb +151 -0
- data/lib/garcon/task/atomic_boolean.rb +127 -0
- data/lib/garcon/task/condition.rb +99 -0
- data/lib/garcon/task/copy_on_notify_observer_set.rb +154 -0
- data/lib/garcon/task/copy_on_write_observer_set.rb +153 -0
- data/lib/garcon/task/count_down_latch.rb +92 -0
- data/lib/garcon/task/delay.rb +196 -0
- data/lib/garcon/task/dereferenceable.rb +144 -0
- data/lib/garcon/task/event.rb +119 -0
- data/lib/garcon/task/executor.rb +275 -0
- data/lib/garcon/task/executor_options.rb +59 -0
- data/lib/garcon/task/future.rb +107 -0
- data/lib/garcon/task/immediate_executor.rb +84 -0
- data/lib/garcon/task/ivar.rb +171 -0
- data/lib/garcon/task/lazy_reference.rb +74 -0
- data/lib/garcon/task/monotonic_time.rb +69 -0
- data/lib/garcon/task/obligation.rb +256 -0
- data/lib/garcon/task/observable.rb +101 -0
- data/lib/garcon/task/priority_queue.rb +234 -0
- data/lib/garcon/task/processor_count.rb +128 -0
- data/lib/garcon/task/read_write_lock.rb +304 -0
- data/lib/garcon/task/safe_task_executor.rb +58 -0
- data/lib/garcon/task/single_thread_executor.rb +97 -0
- data/lib/garcon/task/thread_pool/cached.rb +71 -0
- data/lib/garcon/task/thread_pool/executor.rb +294 -0
- data/lib/garcon/task/thread_pool/fixed.rb +61 -0
- data/lib/garcon/task/thread_pool/worker.rb +90 -0
- data/lib/garcon/task/timer.rb +44 -0
- data/lib/garcon/task/timer_set.rb +194 -0
- data/lib/garcon/task/timer_task.rb +377 -0
- data/lib/garcon/task/waitable_list.rb +58 -0
- data/lib/garcon/utility/ansi.rb +199 -0
- data/lib/garcon/utility/at_random.rb +77 -0
- data/lib/garcon/utility/crypto.rb +292 -0
- data/lib/garcon/utility/equalizer.rb +146 -0
- data/lib/garcon/utility/faker/extensions/array.rb +22 -0
- data/lib/garcon/utility/faker/extensions/symbol.rb +9 -0
- data/lib/garcon/utility/faker/faker.rb +164 -0
- data/lib/garcon/utility/faker/faker/company.rb +17 -0
- data/lib/garcon/utility/faker/faker/hacker.rb +30 -0
- data/lib/garcon/utility/faker/faker/version.rb +3 -0
- data/lib/garcon/utility/faker/locales/en-US.yml +83 -0
- data/lib/garcon/utility/faker/locales/en.yml +21 -0
- data/lib/garcon/utility/file_helper.rb +170 -0
- data/lib/garcon/utility/hookers.rb +178 -0
- data/lib/garcon/utility/interpolation.rb +90 -0
- data/lib/garcon/utility/memstash.rb +364 -0
- data/lib/garcon/utility/misc.rb +54 -0
- data/lib/garcon/utility/msg_from_god.rb +62 -0
- data/lib/garcon/utility/retry.rb +238 -0
- data/lib/garcon/utility/timeout.rb +58 -0
- data/lib/garcon/utility/uber/builder.rb +91 -0
- data/lib/garcon/utility/uber/callable.rb +7 -0
- data/lib/garcon/utility/uber/delegates.rb +13 -0
- data/lib/garcon/utility/uber/inheritable_attr.rb +37 -0
- data/lib/garcon/utility/uber/options.rb +101 -0
- data/lib/garcon/utility/uber/uber_version.rb +3 -0
- data/lib/garcon/utility/uber/version.rb +33 -0
- data/lib/garcon/utility/url_helper.rb +100 -0
- data/lib/garcon/utils.rb +29 -0
- data/lib/garcon/version.rb +62 -0
- data/lib/garcun.rb +24 -0
- metadata +680 -0
@@ -0,0 +1,119 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Author: Stefano Harding <riddopic@gmail.com>
|
4
|
+
# License: Apache License, Version 2.0
|
5
|
+
# Copyright: (C) 2014-2015 Stefano Harding
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'thread'
|
21
|
+
require_relative 'condition'
|
22
|
+
|
23
|
+
module Garcon
|
24
|
+
|
25
|
+
# When an `Event` is created it is in the `unset` state. Threads can choose to
|
26
|
+
# `#wait` on the event, blocking until released by another thread. When one
|
27
|
+
# thread wants to alert all blocking threads it calls the `#set` method which
|
28
|
+
# will then wake up all listeners. Once an `Event` has been set it remains
|
29
|
+
# set. New threads calling `#wait` will return immediately. An `Event` may be
|
30
|
+
# `#reset` at any time once it has been set.
|
31
|
+
#
|
32
|
+
class Event
|
33
|
+
|
34
|
+
# Creates a new `Event` in the unset state. Threads calling `#wait` on the
|
35
|
+
# `Event` will block.
|
36
|
+
#
|
37
|
+
def initialize
|
38
|
+
@set = false
|
39
|
+
@mutex = Mutex.new
|
40
|
+
@condition = Condition.new
|
41
|
+
end
|
42
|
+
|
43
|
+
# Is the object in the set state?
|
44
|
+
#
|
45
|
+
# @return [Boolean]
|
46
|
+
# indicating whether or not the `Event` has been set
|
47
|
+
def set?
|
48
|
+
@mutex.lock
|
49
|
+
@set
|
50
|
+
ensure
|
51
|
+
@mutex.unlock
|
52
|
+
end
|
53
|
+
|
54
|
+
# Trigger the event, setting the state to `set` and releasing all threads
|
55
|
+
# waiting on the event. Has no effect if the `Event` has already been set.
|
56
|
+
#
|
57
|
+
# @return [Boolean]
|
58
|
+
# should always return `true`
|
59
|
+
def set
|
60
|
+
@mutex.lock
|
61
|
+
unless @set
|
62
|
+
@set = true
|
63
|
+
@condition.broadcast
|
64
|
+
end
|
65
|
+
true
|
66
|
+
ensure
|
67
|
+
@mutex.unlock
|
68
|
+
end
|
69
|
+
|
70
|
+
def try?
|
71
|
+
@mutex.lock
|
72
|
+
|
73
|
+
if @set
|
74
|
+
false
|
75
|
+
else
|
76
|
+
@set = true
|
77
|
+
@condition.broadcast
|
78
|
+
true
|
79
|
+
end
|
80
|
+
|
81
|
+
ensure
|
82
|
+
@mutex.unlock
|
83
|
+
end
|
84
|
+
|
85
|
+
# Reset a previously set event back to the `unset` state.
|
86
|
+
# Has no effect if the `Event` has not yet been set.
|
87
|
+
#
|
88
|
+
# @return [Boolean]
|
89
|
+
# should always return `true`
|
90
|
+
def reset
|
91
|
+
@mutex.lock
|
92
|
+
@set = false
|
93
|
+
true
|
94
|
+
ensure
|
95
|
+
@mutex.unlock
|
96
|
+
end
|
97
|
+
|
98
|
+
# Wait a given number of seconds for the `Event` to be set by another
|
99
|
+
# thread. Will wait forever when no `timeout` value is given. Returns
|
100
|
+
# immediately if the `Event` has already been set.
|
101
|
+
#
|
102
|
+
# @return [Boolean]
|
103
|
+
# true if the `Event` was set before timeout else false
|
104
|
+
def wait(timeout = nil)
|
105
|
+
@mutex.lock
|
106
|
+
|
107
|
+
unless @set
|
108
|
+
remaining = Condition::Result.new(timeout)
|
109
|
+
while !@set && remaining.can_wait?
|
110
|
+
remaining = @condition.wait(@mutex, remaining.remaining_time)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
@set
|
115
|
+
ensure
|
116
|
+
@mutex.unlock
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,275 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Author: Stefano Harding <riddopic@gmail.com>
|
4
|
+
# License: Apache License, Version 2.0
|
5
|
+
# Copyright: (C) 2014-2015 Stefano Harding
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
require_relative '../exceptions'
|
21
|
+
require_relative 'event'
|
22
|
+
|
23
|
+
module Garcon
|
24
|
+
|
25
|
+
module Executor
|
26
|
+
# The policy defining how rejected tasks (tasks received once the queue size
|
27
|
+
# reaches the configured `max_queue`, or after the executor has shut down)
|
28
|
+
# are handled. Must be one of the values specified in `FALLBACK_POLICY`.
|
29
|
+
attr_reader :fallback_policy
|
30
|
+
|
31
|
+
# Does the task queue have a maximum size?
|
32
|
+
#
|
33
|
+
# @note Always returns `false`
|
34
|
+
#
|
35
|
+
# @return [Boolean] True if the task queue has a maximum size else false.
|
36
|
+
#
|
37
|
+
# @note Always returns `false`
|
38
|
+
def can_overflow?
|
39
|
+
false
|
40
|
+
end
|
41
|
+
|
42
|
+
# Handler which executes the `fallback_policy` once the queue size reaches
|
43
|
+
# `max_queue`.
|
44
|
+
#
|
45
|
+
# @param [Array] args
|
46
|
+
# The arguments to the task which is being handled.
|
47
|
+
#
|
48
|
+
# @!visibility private
|
49
|
+
def handle_fallback(*args)
|
50
|
+
case @fallback_policy
|
51
|
+
when :abort
|
52
|
+
raise RejectedExecutionError
|
53
|
+
when :discard
|
54
|
+
false
|
55
|
+
when :caller_runs
|
56
|
+
begin
|
57
|
+
yield(*args)
|
58
|
+
rescue => e
|
59
|
+
Chef::Log.debug "Caught exception => #{e}"
|
60
|
+
end
|
61
|
+
true
|
62
|
+
else
|
63
|
+
fail "Unknown fallback policy #{@fallback_policy}"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Does this executor guarantee serialization of its operations?
|
68
|
+
#
|
69
|
+
# @note
|
70
|
+
# Always returns `false`
|
71
|
+
#
|
72
|
+
# @return [Boolean]
|
73
|
+
# True if the executor guarantees that all operations will be post in the
|
74
|
+
# order they are received and no two operations may occur simultaneously.
|
75
|
+
# Else false.
|
76
|
+
def serialized?
|
77
|
+
false
|
78
|
+
end
|
79
|
+
|
80
|
+
def auto_terminate?
|
81
|
+
!! @auto_terminate
|
82
|
+
end
|
83
|
+
|
84
|
+
protected # A T T E N Z I O N E A R E A P R O T E T T A
|
85
|
+
|
86
|
+
def enable_at_exit_handler!(opts = {})
|
87
|
+
if opts.fetch(:stop_on_exit, true)
|
88
|
+
@auto_terminate = true
|
89
|
+
create_mri_at_exit_handler!(self.object_id)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def create_mri_at_exit_handler!(id)
|
94
|
+
at_exit do
|
95
|
+
if Garcon.auto_terminate_all_executors?
|
96
|
+
this = ObjectSpace._id2ref(id)
|
97
|
+
this.kill if this
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def create_at_exit_handler!(this)
|
103
|
+
at_exit do
|
104
|
+
this.kill if Garcon.auto_terminate_all_executors?
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Indicates that the including `Executor` or `ExecutorService` guarantees
|
110
|
+
# that all operations will occur in the order they are post and that no
|
111
|
+
# two operations may occur simultaneously. This module provides no
|
112
|
+
# functionality and provides no guarantees. That is the responsibility
|
113
|
+
# of the including class. This module exists solely to allow the including
|
114
|
+
# object to be interrogated for its serialization status.
|
115
|
+
#
|
116
|
+
# @example
|
117
|
+
# class Foo
|
118
|
+
# include Garcon::SerialExecutor
|
119
|
+
# end
|
120
|
+
#
|
121
|
+
# foo = Foo.new
|
122
|
+
#
|
123
|
+
# foo.is_a? Garcon::Executor # => true
|
124
|
+
# foo.is_a? Garcon::SerialExecutor # => true
|
125
|
+
# foo.serialized? # => true
|
126
|
+
module SerialExecutor
|
127
|
+
include Executor
|
128
|
+
|
129
|
+
# @note
|
130
|
+
# Always returns `true`
|
131
|
+
def serialized?
|
132
|
+
true
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
module RubyExecutor
|
137
|
+
include Executor
|
138
|
+
|
139
|
+
# The set of possible fallback policies that may be set at thread pool
|
140
|
+
# creation.
|
141
|
+
FALLBACK_POLICY = [:abort, :discard, :caller_runs]
|
142
|
+
|
143
|
+
# Submit a task to the executor for asynchronous processing.
|
144
|
+
#
|
145
|
+
# @param [Array] args
|
146
|
+
# Zero or more arguments to be passed to the task
|
147
|
+
#
|
148
|
+
# @yield the asynchronous task to perform
|
149
|
+
#
|
150
|
+
# @raise [ArgumentError]
|
151
|
+
# if no task is given
|
152
|
+
#
|
153
|
+
# @return [Boolean]
|
154
|
+
# True if the task is queued, false if the executor is not running.
|
155
|
+
def post(*args, &task)
|
156
|
+
raise ArgumentError.new('no block given') unless block_given?
|
157
|
+
mutex.synchronize do
|
158
|
+
# If the executor is shut down, reject this task
|
159
|
+
return handle_fallback(*args, &task) unless running?
|
160
|
+
execute(*args, &task)
|
161
|
+
true
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
# Submit a task to the executor for asynchronous processing.
|
166
|
+
#
|
167
|
+
# @param [Proc] task
|
168
|
+
# the asynchronous task to perform
|
169
|
+
#
|
170
|
+
# @return [self]
|
171
|
+
# returns itself
|
172
|
+
def <<(task)
|
173
|
+
post(&task)
|
174
|
+
self
|
175
|
+
end
|
176
|
+
|
177
|
+
# Is the executor running?
|
178
|
+
#
|
179
|
+
# @return [Boolean]
|
180
|
+
# True when running, false when shutting down or shutdown.
|
181
|
+
def running?
|
182
|
+
! stop_event.set?
|
183
|
+
end
|
184
|
+
|
185
|
+
# Is the executor shuttingdown?
|
186
|
+
#
|
187
|
+
# @return [Boolean]
|
188
|
+
# True when not running and not shutdown, else false.
|
189
|
+
def shuttingdown?
|
190
|
+
! (running? || shutdown?)
|
191
|
+
end
|
192
|
+
|
193
|
+
# Is the executor shutdown?
|
194
|
+
#
|
195
|
+
# @return [Boolean]
|
196
|
+
# True when shutdown, false when shutting down or running.
|
197
|
+
def shutdown?
|
198
|
+
stopped_event.set?
|
199
|
+
end
|
200
|
+
|
201
|
+
# Begin an orderly shutdown. Tasks already in the queue will be executed,
|
202
|
+
# but no new tasks will be accepted. Has no additional effect if the
|
203
|
+
# thread pool is not running.
|
204
|
+
#
|
205
|
+
def shutdown
|
206
|
+
mutex.synchronize do
|
207
|
+
break unless running?
|
208
|
+
stop_event.set
|
209
|
+
shutdown_execution
|
210
|
+
end
|
211
|
+
true
|
212
|
+
end
|
213
|
+
|
214
|
+
# Begin an immediate shutdown. In-progress tasks will be allowed to complete
|
215
|
+
# but enqueued tasks will be dismissed and no new tasks will be accepted.
|
216
|
+
# Has no additional effect if the thread pool is not running.
|
217
|
+
#
|
218
|
+
def kill
|
219
|
+
mutex.synchronize do
|
220
|
+
break if shutdown?
|
221
|
+
stop_event.set
|
222
|
+
kill_execution
|
223
|
+
stopped_event.set
|
224
|
+
end
|
225
|
+
true
|
226
|
+
end
|
227
|
+
|
228
|
+
# Block until executor shutdown is complete or until `timeout` seconds have
|
229
|
+
# passed.
|
230
|
+
#
|
231
|
+
# @note
|
232
|
+
# Does not initiate shutdown or termination. Either shutdown or kill must
|
233
|
+
# be called before this method (or on another thread).
|
234
|
+
#
|
235
|
+
# @param [Integer] timeout
|
236
|
+
# The maximum number of seconds to wait for shutdown to complete
|
237
|
+
#
|
238
|
+
# @return [Boolean]
|
239
|
+
# True if shutdown complete or false on timeout.
|
240
|
+
def wait_for_termination(timeout = nil)
|
241
|
+
stopped_event.wait(timeout)
|
242
|
+
end
|
243
|
+
|
244
|
+
protected # A T T E N Z I O N E A R E A P R O T E T T A
|
245
|
+
|
246
|
+
attr_reader :mutex, :stop_event, :stopped_event
|
247
|
+
|
248
|
+
# Initialize the executor by creating and initializing all the internal
|
249
|
+
# synchronization objects.
|
250
|
+
#
|
251
|
+
def init_executor
|
252
|
+
@mutex = Mutex.new
|
253
|
+
@stop_event = Event.new
|
254
|
+
@stopped_event = Event.new
|
255
|
+
end
|
256
|
+
|
257
|
+
def execute(*args, &task)
|
258
|
+
raise NotImplementedError
|
259
|
+
end
|
260
|
+
|
261
|
+
# Callback method called when an orderly shutdown has completed. The default
|
262
|
+
# behavior is to signal all waiting threads.
|
263
|
+
#
|
264
|
+
def shutdown_execution
|
265
|
+
stopped_event.set
|
266
|
+
end
|
267
|
+
|
268
|
+
# Callback method called when the executor has been killed. The default
|
269
|
+
# behavior is to do nothing.
|
270
|
+
#
|
271
|
+
def kill_execution
|
272
|
+
# do nothing
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Author: Stefano Harding <riddopic@gmail.com>
|
4
|
+
# License: Apache License, Version 2.0
|
5
|
+
# Copyright: (C) 2014-2015 Stefano Harding
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
require_relative 'immediate_executor'
|
21
|
+
|
22
|
+
module Garcon
|
23
|
+
module ExecutorOptions
|
24
|
+
|
25
|
+
# Get the requested `Executor` based on the values set in the options hash.
|
26
|
+
#
|
27
|
+
# @param [Hash] opts
|
28
|
+
# The options defining the requested executor.
|
29
|
+
#
|
30
|
+
# @option opts [Executor] :executor
|
31
|
+
# When set use the given `Executor` instance. Three special values are
|
32
|
+
# also supported: `:fast` returns the global fast executor, `:io` returns
|
33
|
+
# the global io executor, and `:immediate` returns a new
|
34
|
+
# `ImmediateExecutor` object.
|
35
|
+
#
|
36
|
+
# @return [Executor, nil]
|
37
|
+
# The requested thread pool, or nil when no option specified.
|
38
|
+
#
|
39
|
+
# @!visibility private
|
40
|
+
def get_executor_from(opts = {})
|
41
|
+
if (executor = opts[:executor]).is_a? Symbol
|
42
|
+
case opts[:executor]
|
43
|
+
when :fast
|
44
|
+
Garcon.global_fast_executor
|
45
|
+
when :io
|
46
|
+
Garcon.global_io_executor
|
47
|
+
when :immediate
|
48
|
+
Garcon::ImmediateExecutor.new
|
49
|
+
else
|
50
|
+
raise ArgumentError, "executor '#{executor}' not recognized"
|
51
|
+
end
|
52
|
+
elsif opts[:executor]
|
53
|
+
opts[:executor]
|
54
|
+
else
|
55
|
+
nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|