@@ -199,6 +199,12 @@ public void start() {
199199 }
200200
201201 public void refresh (final @ NotNull List <ProtocolAdapterEntity > configs ) {
202+ // Don't submit refresh if shutdown initiated or executor is shutting down
203+ if (shutdownInitiated .get () || refreshExecutor .isShutdown ()) {
204+ log .debug ("Skipping refresh because manager is shutting down" );
205+ return ;
206+ }
207+
202208 refreshExecutor .submit (() -> {
203209 // Atomically check and clear skip flag (hot-reload in progress)
204210 if (skipRefreshForAdapter .getAndSet (false )) {
@@ -264,18 +270,33 @@ public void refresh(final @NotNull List<ProtocolAdapterEntity> configs) {
264270 log .error (
265271 "Existing adapters were modified while a refresh was ongoing, adapter with name '{}' was deleted and could not be updated" ,
266272 name );
273+ return ;
267274 }
268- if (wrapper != null && !protocolAdapterConfigs .get (name ).equals (wrapper .getConfig ())) {
269- if (log .isDebugEnabled ()) {
270- log .debug ("Updating adapter '{}'" , name );
275+
276+ if (!protocolAdapterConfigs .get (name ).equals (wrapper .getConfig ())) {
277+ final boolean isStarted =
278+ wrapper .getRuntimeStatus () == ProtocolAdapterState .RuntimeStatus .STARTED ;
279+
280+ if (!isStarted ) {
281+ // Adapter is stopped - update config by recreating wrapper but don't start
282+ if (log .isDebugEnabled ()) {
283+ log .debug ("Updating config for stopped adapter '{}' without starting" , name );
284+ }
285+ deleteAdapterInternal (name );
286+ createAdapterInternal (protocolAdapterConfigs .get (name ), versionProvider .getVersion ());
287+ } else {
288+ // Adapter is started - do full stop->delete->create->start cycle
289+ if (log .isDebugEnabled ()) {
290+ log .debug ("Updating adapter '{}'" , name );
291+ }
292+ stopAsync (name ).thenApply (v -> {
293+ deleteAdapterInternal (name );
294+ return null ;
295+ })
296+ .thenCompose (ignored -> startAsync (createAdapterInternal (protocolAdapterConfigs .get (
297+ name ), versionProvider .getVersion ())))
298+ .get ();
271299 }
272- stopAsync (name ).thenApply (v -> {
273- deleteAdapterInternal (name );
274- return null ;
275- })
276- .thenCompose (ignored -> startAsync (createAdapterInternal (protocolAdapterConfigs .get (name ),
277- versionProvider .getVersion ())))
278- .get ();
279300 } else {
280301 if (log .isDebugEnabled ()) {
281302 log .debug ("Not-updating adapter '{}' since the config is unchanged" , name );
0 commit comments