2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.bgp.rib.impl;
10 import static java.util.Objects.requireNonNull;
12 import java.util.concurrent.ConcurrentHashMap;
13 import java.util.concurrent.ConcurrentMap;
14 import javax.inject.Inject;
15 import javax.inject.Singleton;
16 import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTree;
17 import org.opendaylight.protocol.bgp.rib.impl.spi.Codecs;
18 import org.opendaylight.protocol.bgp.rib.impl.spi.CodecsRegistry;
19 import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
22 public final class ConstantCodecsRegistry implements CodecsRegistry {
23 private final ConcurrentMap<RIBSupport<?, ?, ?, ?>, Codecs> contexts = new ConcurrentHashMap<>();
24 private final BindingCodecTree codecTree;
27 public ConstantCodecsRegistry(final BindingCodecTree codecTree) {
28 this.codecTree = requireNonNull(codecTree);
32 public Codecs getCodecs(final RIBSupport<?, ?, ?, ?> ribSupport) {
33 return contexts.computeIfAbsent(ribSupport, this::createCodecs);
36 private Codecs createCodecs(final RIBSupport<?, ?, ?, ?> key) {
37 final Codecs codecs = new CodecsImpl(key);
38 codecs.onCodecTreeUpdated(codecTree);