Federico Mariani created CAMEL-23252:
----------------------------------------

             Summary: Add onReload SPI method to ContextServicePlugin for 
dev-mode hot-reload hooks
                 Key: CAMEL-23252
                 URL: https://issues.apache.org/jira/browse/CAMEL-23252
             Project: Camel
          Issue Type: New Feature
    Affects Versions: 4.18.0
            Reporter: Federico Mariani
            Assignee: Federico Mariani


Third-party plugins that register beans during {{ContextServicePlugin.load()}} 
have no way to refresh those beans when properties change in dev mode 
({{--dev}}).

Camel's {{RouteWatcherReloadStrategy}} detects {{.properties}} file changes and 
reloads routes, but third-party beans bound to the registry during {{load()}} 
become stale. Components like {{SqlComponent}} cache bean references (e.g., 
DataSource) at the component level, so even endpoint registry clearing doesn't 
help — the plugin needs a hook to refresh beans before routes are reloaded.

*Proposed change*:

Add a default {{onReload}} method to the {{ContextServicePlugin}} SPI:

{code:java}
public interface ContextServicePlugin {

void load(CamelContext camelContext);

default void unload(CamelContext camelContext) {}

/**
 * Called before routes are reloaded during dev mode (hot-reload).  * Plugins 
can refresh beans/configuration so restarted routes  
 * pick up updated references.
*/
default void onReload(CamelContext camelContext) {}
}
{code}

{{RouteWatcherReloadStrategy}} would invoke {{onReload()}} on all registered 
plugins before removing and re-adding routes in {{onRouteReload()}}.

Benefits:
- Deterministic ordering — same thread, no race conditions
- Backward compatible — default no-op
- Eliminates the need for third-party plugins to run their own file watchers



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to