*/
package org.opendaylight.protocol.bgp.rib.impl;
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
+import org.opendaylight.protocol.bgp.rib.impl.spi.CodecsRegistry;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContext;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContextRegistry;
import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionConsumerContext;
import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
-import org.opendaylight.yangtools.binding.data.codec.api.BindingCodecTree;
-import org.opendaylight.yangtools.binding.data.codec.api.BindingCodecTreeFactory;
-import org.opendaylight.yangtools.sal.binding.generator.impl.GeneratedClassLoadingStrategy;
-import org.opendaylight.yangtools.sal.binding.generator.util.BindingRuntimeContext;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.Tables;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
+import org.opendaylight.yangtools.yang.binding.ChildOf;
+import org.opendaylight.yangtools.yang.binding.ChoiceIn;
+import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
final class RIBSupportContextRegistryImpl implements RIBSupportContextRegistry {
- private final LoadingCache<RIBSupport, RIBSupportContextImpl> contexts = CacheBuilder.newBuilder()
- .build(new CacheLoader<RIBSupport, RIBSupportContextImpl>(){
-
+ private final RIBExtensionConsumerContext extensionContext;
+ private final CodecsRegistry codecs;
+ private final LoadingCache<RIBSupport<?, ?>, RIBSupportContextImpl> contexts = CacheBuilder.newBuilder()
+ .build(new CacheLoader<RIBSupport<?, ?>, RIBSupportContextImpl>() {
@Override
- public RIBSupportContextImpl load(final RIBSupport key) {
- return createContext(key);
+ public RIBSupportContextImpl load(final RIBSupport<?, ?> key) {
+ return createRIBSupportContext(key);
}
});
- private final RIBExtensionConsumerContext extensionContext;
- private final BindingCodecTreeFactory codecFactory;
- private final GeneratedClassLoadingStrategy classContext;
- private volatile BindingCodecTree latestCodecTree;
-
- private RIBSupportContextRegistryImpl(final RIBExtensionConsumerContext extensions, final BindingCodecTreeFactory codecFactory,
- final GeneratedClassLoadingStrategy strategy) {
- this.extensionContext = Preconditions.checkNotNull(extensions);
- this.codecFactory = Preconditions.checkNotNull(codecFactory);
- this.classContext = Preconditions.checkNotNull(strategy);
+ private RIBSupportContextRegistryImpl(final RIBExtensionConsumerContext extensions, final CodecsRegistry codecs) {
+ this.extensionContext = requireNonNull(extensions);
+ this.codecs = requireNonNull(codecs);
}
static RIBSupportContextRegistryImpl create(final RIBExtensionConsumerContext extensions,
- final BindingCodecTreeFactory codecFactory, final GeneratedClassLoadingStrategy classStrategy) {
- return new RIBSupportContextRegistryImpl(extensions, codecFactory, classStrategy);
+ final CodecsRegistry codecs) {
+ return new RIBSupportContextRegistryImpl(extensions, codecs);
}
- @Override
- public RIBSupportContext getRIBSupportContext(final TablesKey key) {
- final RIBSupport ribSupport = this.extensionContext.getRIBSupport(key);
- if(ribSupport != null) {
- return this.contexts.getUnchecked(ribSupport);
- }
- return null;
+ private RIBSupportContextImpl createRIBSupportContext(final RIBSupport<?, ?> support) {
+ return new RIBSupportContextImpl(support, this.codecs);
}
@Override
- public RIBSupportContext getRIBSupportContext(final NodeIdentifierWithPredicates key) {
- final RIBSupport ribSupport = this.extensionContext.getRIBSupport(key);
- if(ribSupport != null) {
- return this.contexts.getUnchecked(ribSupport);
- }
- return null;
+ public <C extends Routes & DataObject & ChoiceIn<Tables>, S extends ChildOf<? super C>>
+ RIBSupport<C, S> getRIBSupport(final TablesKey key) {
+ final RIBSupportContext ribSupport = getRIBSupportContext(key);
+ return ribSupport == null ? null : ribSupport.getRibSupport();
}
- private RIBSupportContextImpl createContext(final RIBSupport ribSupport) {
- final RIBSupportContextImpl ribContext = new RIBSupportContextImpl(ribSupport);
- if(this.latestCodecTree != null) {
- // FIXME: Do we need to recalculate latestCodecTree? E.g. new rib support was added
- // after bgp was started.
- ribContext.onCodecTreeUpdated(this.latestCodecTree);
- }
- return ribContext;
+ @Override
+ public RIBSupportContext getRIBSupportContext(final TablesKey key) {
+ final RIBSupport<?, ?> ribSupport = this.extensionContext.getRIBSupport(key);
+ return ribSupport == null ? null : this.contexts.getUnchecked(ribSupport);
}
- void onSchemaContextUpdated(final SchemaContext context) {
- final BindingRuntimeContext runtimeContext = BindingRuntimeContext.create(this.classContext, context);
- this.latestCodecTree = this.codecFactory.create(runtimeContext);
- for(final RIBSupportContextImpl rib : this.contexts.asMap().values()) {
- rib.onCodecTreeUpdated(this.latestCodecTree);
- }
+ @Override
+ public RIBSupportContext getRIBSupportContext(final NodeIdentifierWithPredicates key) {
+ final RIBSupport<?, ?> ribSupport = this.extensionContext.getRIBSupport(key);
+ return ribSupport == null ? null : this.contexts.getUnchecked(ribSupport);
}
-
}