import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.mdsal.dom.api.DOMSchemaService;
import org.opendaylight.netconf.api.capability.Capability;
-import org.opendaylight.netconf.api.monitoring.CapabilityListener;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.netconf.server.api.monitoring.CapabilityListener;
+import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextListener;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
// Non-final for mocking
+@SuppressWarnings("checkstyle:FinalClass")
public class CurrentSchemaContext implements EffectiveModelContextListener, AutoCloseable {
private final AtomicReference<EffectiveModelContext> currentContext = new AtomicReference<>();
- private final ListenerRegistration<?> schemaContextListenerListenerRegistration;
private final Set<CapabilityListener> listeners1 = Collections.synchronizedSet(new HashSet<>());
private final SchemaSourceProvider<YangTextSchemaSource> rootSchemaSourceProvider;
- public CurrentSchemaContext(final DOMSchemaService schemaService,
- final SchemaSourceProvider<YangTextSchemaSource> rootSchemaSourceProvider) {
+ private Registration schemaContextListenerListenerRegistration;
+
+ private CurrentSchemaContext(final SchemaSourceProvider<YangTextSchemaSource> rootSchemaSourceProvider) {
this.rootSchemaSourceProvider = rootSchemaSourceProvider;
- schemaContextListenerListenerRegistration = schemaService.registerSchemaContextListener(this);
+ }
+
+ // keep spotbugs from complaining about overridable method in constructor
+ public static CurrentSchemaContext create(final DOMSchemaService schemaService,
+ final SchemaSourceProvider<YangTextSchemaSource> rootSchemaSourceProvider) {
+ var context = new CurrentSchemaContext(rootSchemaSourceProvider);
+ final Registration registration = schemaService.registerSchemaContextListener(context);
+ context.setRegistration(registration);
+ return context;
+ }
+
+ private void setRegistration(final Registration registration) {
+ schemaContextListenerListenerRegistration = registration;
}
public @NonNull EffectiveModelContext getCurrentContext() {
final Set<Capability> addedCaps = MdsalNetconfOperationServiceFactory.transformCapabilities(
currentContext.get(), rootSchemaSourceProvider);
for (final CapabilityListener listener : listeners1) {
- listener.onCapabilitiesChanged(addedCaps, Collections.emptySet());
+ listener.onCapabilitiesChanged(addedCaps, Set.of());
}
}
currentContext.set(null);
}
- public AutoCloseable registerCapabilityListener(final CapabilityListener listener) {
+ public Registration registerCapabilityListener(final CapabilityListener listener) {
listener.onCapabilitiesChanged(MdsalNetconfOperationServiceFactory.transformCapabilities(currentContext.get(),
- rootSchemaSourceProvider), Collections.emptySet());
+ rootSchemaSourceProvider), Set.of());
listeners1.add(listener);
return () -> listeners1.remove(listener);
}