HONEYCOMB-359 - Wildcarded writers
[honeycomb.git] / infra / northbound / bgp / src / main / java / io / fd / honeycomb / infra / bgp / ApplicationRibWriterFactory.java
1 /*
2  * Copyright (c) 2017 Cisco and/or its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package io.fd.honeycomb.infra.bgp;
18
19 import com.google.common.collect.ImmutableSet;
20 import com.google.inject.Inject;
21 import com.google.inject.name.Named;
22 import io.fd.honeycomb.translate.util.write.BindingBrokerWriter;
23 import io.fd.honeycomb.translate.write.WriterFactory;
24 import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder;
25 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.ApplicationRib;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.Tables;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29
30 /**
31  * {@link WriterFactory} for BGP Application RIB write integration with HC writer registry.
32  * Uses BindingBrokerWriter to write routes via dedicated broker that, unlike
33  * {@link io.fd.honeycomb.data.impl.DataBroker DataBroker}, supports tx chains and DOMDataChangeListener registration
34  * extensively used by ODL's bgp.
35  * <p>
36  * As a bonus BGP routes persisted and available for read via RESTCONF/NETCONF.
37  */
38 final class ApplicationRibWriterFactory implements WriterFactory {
39
40     @Inject
41     @Named(BgpModule.HONEYCOMB_BGP)
42     private DataBroker dataBroker;
43
44     private static final InstanceIdentifier<ApplicationRib> AR_IID =
45             InstanceIdentifier.create(ApplicationRib.class);
46     private static final InstanceIdentifier<Tables> TABLES_IID = AR_IID.child(Tables.class);
47
48     @Override
49     public void init(final ModifiableWriterRegistryBuilder registry) {
50         registry.subtreeAdd(ImmutableSet.of(TABLES_IID), new BindingBrokerWriter<>(InstanceIdentifier.create(ApplicationRib.class), dataBroker)
51         );
52     }
53 }