Fix model names and imports
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / RIBActivator.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bgp.rib.impl;
9
10 import java.util.Comparator;
11
12 import org.opendaylight.protocol.bgp.rib.spi.AdjRIBsIn;
13 import org.opendaylight.protocol.bgp.rib.spi.AdjRIBsInFactory;
14 import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderActivator;
15 import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderContext;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.PathAttributes;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 import com.google.common.base.Preconditions;
25
26 public final class RIBActivator implements RIBExtensionProviderActivator {
27         private static final Logger LOG = LoggerFactory.getLogger(RIBActivator.class);
28         private AutoCloseable v4reg, v6reg;
29
30         @Override
31         public void startRIBExtensionProvider(final RIBExtensionProviderContext context) {
32                 Preconditions.checkState(v4reg == null);
33                 Preconditions.checkState(v6reg == null);
34
35                 v4reg = context.registerAdjRIBsInFactory(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, new AdjRIBsInFactory() {
36                         @Override
37                         public AdjRIBsIn createAdjRIBsIn(final Comparator<PathAttributes> comparator, final TablesKey key) {
38                                 return new Ipv4AdjRIBsIn(comparator, key);
39                         }
40                 });
41
42                 v6reg = context.registerAdjRIBsInFactory(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, new AdjRIBsInFactory() {
43                         @Override
44                         public AdjRIBsIn createAdjRIBsIn(final Comparator<PathAttributes> comparator, final TablesKey key) {
45                                 return new Ipv6AdjRIBsIn(comparator, key);
46                         }
47                 });
48
49         }
50
51         @Override
52         public void stopRIBExtensionProvider() {
53                 if (v4reg != null) {
54                         try {
55                                 v4reg.close();
56                         } catch (Exception e) {
57                                 LOG.warn("Failed to unregister IPv4 extension", e);
58                         } finally {
59                                 v4reg = null;
60                         }
61                 }
62                 if (v6reg != null) {
63                         try {
64                                 v6reg.close();
65                         } catch (Exception e) {
66                                 LOG.warn("Failed to unregister IPv6 extension", e);
67                         } finally {
68                                 v6reg = null;
69                         }
70                 }
71         }
72 }