Class: Yoda::Server::RootHandler
- Inherits:
-
Object
- Object
- Yoda::Server::RootHandler
show all
- Extended by:
- Forwardable
- Defined in:
- lib/yoda/server/root_handler.rb
Defined Under Namespace
Classes: NotImplementedMethod
Constant Summary
collapse
- NOT_INITIALIZED =
:not_initialized
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(writer:, thread_pool: nil) ⇒ RootHandler
Returns a new instance of RootHandler.
26
27
28
29
30
|
# File 'lib/yoda/server/root_handler.rb', line 26
def initialize(writer:, thread_pool: nil)
@thread_pool = thread_pool || self.class.default_thread_pool
@writer = writer
@future_map = Concurrent::Map.new
end
|
Instance Attribute Details
#thread_pool ⇒ Concurrent::ThreadPoolExecutor
17
18
19
|
# File 'lib/yoda/server/root_handler.rb', line 17
def thread_pool
@thread_pool
end
|
14
15
16
|
# File 'lib/yoda/server/root_handler.rb', line 14
def writer
@writer
end
|
Class Method Details
.default_thread_pool ⇒ Concurrent::ThreadPoolExecutor
20
21
22
|
# File 'lib/yoda/server/root_handler.rb', line 20
def self.default_thread_pool
Concurrent.global_fast_executor
end
|
Instance Method Details
#cancel_all_requests ⇒ Object
60
61
62
|
# File 'lib/yoda/server/root_handler.rb', line 60
def cancel_all_requests
future_map.each_value { |future| future&.cancel }
end
|
#cancel_request(id) ⇒ Object
56
57
58
|
# File 'lib/yoda/server/root_handler.rb', line 56
def cancel_request(id)
future_map[id]&.cancel
end
|
#handle(id:, method:, params:) ⇒ Concurrent::Future?
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/yoda/server/root_handler.rb', line 36
def handle(id:, method:, params:)
if lifecycle_handler.handle?(method)
return write_response(id, lifecycle_handler.handle(method: method, params: params))
end
return write_response(id, build_error_response(NOT_INITIALIZED)) unless session
if provider = Providers.build_provider(notifier: notifier, session: session, method: method)
provide_async(provider: provider, id: id, method: method, params: params)
else
write_response(id, build_error_response(NotImplementedMethod.new(method)))
end
end
|
51
52
53
|
# File 'lib/yoda/server/root_handler.rb', line 51
def notifier
@notifier ||= Notifier.new(writer)
end
|