Class: Browserctl::PluginDispatcher
- Inherits:
-
Object
- Object
- Browserctl::PluginDispatcher
- Defined in:
- lib/browserctl/server/plugin_dispatcher.rb
Overview
Invokes plugin commands registered via register_command from
the daemon's command-dispatch loop. Extracted from CommandDispatcher in
v0.15 WS-2 PR 5 so plugin invocation gets two daemon-protecting
properties:
- A per-plugin wall-clock timeout (default
DEFAULT_PLUGIN_TIMEOUT, configurable via
timeout:onregister_command, opt-out withtimeout: nil). On expiry the dispatcher returns a typedPLUGIN_TIMED_OUTresponse and the daemon stays answering subsequent commands. - A rescue boundary that converts ANY uncaught exception from the plugin
block into a typed
PLUGIN_FAILEDJSON-RPC response. The plugin name is always present in the response'scontextso agents can branch on it. The daemon process is never taken down by a buggy plugin.
Plugins live in the Extension zone (see
docs/reference/api-stability.md); the response shape here is documented
in docs/reference/errors.md.
Instance Method Summary collapse
-
#dispatch(req) ⇒ Hash{Symbol => Object}?
Looks up the plugin command for
req[:cmd]and invokes it under the timeout / rescue boundary. -
#initialize(pages, global_mutex:) ⇒ PluginDispatcher
constructor
A new instance of PluginDispatcher.
Methods included from CommandDispatcher::Handlers::ErrorPayload
Constructor Details
#initialize(pages, global_mutex:) ⇒ PluginDispatcher
Returns a new instance of PluginDispatcher.
32 33 34 35 |
# File 'lib/browserctl/server/plugin_dispatcher.rb', line 32 def initialize(pages, global_mutex:) @pages = pages @global_mutex = global_mutex end |
Instance Method Details
#dispatch(req) ⇒ Hash{Symbol => Object}?
Looks up the plugin command for req[:cmd] and invokes it under the
timeout / rescue boundary. Returns nil if no plugin handles this
command — the caller falls through to its "unknown command" branch.
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/browserctl/server/plugin_dispatcher.rb', line 43 def dispatch(req) plugin = Browserctl.lookup_plugin_command(req[:cmd]) return nil unless plugin name = req[:cmd].to_s session = req[:name] ? @global_mutex.synchronize { @pages[req[:name]] } : nil Browserctl.logger.debug("plugin:#{name} #{req[:name]}") invoke(plugin, name, session, req) end |