Skip to content

Commit

Permalink
MID-7484: transport config refresh removes only old config transports
Browse files Browse the repository at this point in the history
Dynamic instance registration should be driven mainly by sysconfig,
but sometimes explicit registrations are used (e.g. dummy).
Transport service now remembers what transports are registered based on
the sysconfig and removes only these when the sysconfig is changed.
  • Loading branch information
virgo47 committed Feb 17, 2022
1 parent d59ff00 commit 2404c54
Showing 1 changed file with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
package com.evolveum.midpoint.transport.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.PostConstruct;
Expand Down Expand Up @@ -46,6 +48,12 @@ public class TransportServiceImpl implements TransportService {

private final Map<String, Transport<?>> transports = new ConcurrentHashMap<>();

/**
* This holds the names of the transports configured from system config object.
* When new config is read we don't want to remove other transports registered explicitly (e.g. tests).
*/
private final List<String> transportsFromSysConfig = new ArrayList<>();

// injected fields for TransportSupport
@Autowired private ApplicationContext applicationContext;
@Autowired private PrismContext prismContext;
Expand Down Expand Up @@ -92,6 +100,8 @@ public ApplicationContext applicationContext() {
return applicationContext;
}
};

registerLegacyTransports();
}

/**
Expand All @@ -100,8 +110,7 @@ public ApplicationContext applicationContext() {
*/
@EventListener
public void refreshTransportConfiguration(SystemConfigurationChangeEvent event) {
transports.clear();
registerLegacyTransports();
clearPreviousConfiguration();
createTransports(event.getSystemConfiguration());
}

Expand Down Expand Up @@ -129,7 +138,6 @@ public void registerTransport(@NotNull Transport<?> transport) {

// TODO should be internal and go away eventually
// accepts name:subname (e.g. dummy:accounts) - a primitive form of passing parameters (will be enhanced/replaced in the future)

@Override
public Transport<?> getTransport(String name) {
Transport<?> transport = transports.get(name);
Expand All @@ -155,7 +163,14 @@ private void createTransports(SystemConfigurationType systemConfiguration) {
createCustomTransport(customConfig);
}

// TODO
// TODO other types
}

private void clearPreviousConfiguration() {
for (String transport : transportsFromSysConfig) {
transports.remove(transport);
}
transportsFromSysConfig.clear();
}

private void createCustomTransport(CustomTransportConfigurationType customConfig) {
Expand Down

0 comments on commit 2404c54

Please sign in to comment.