BUG-2982 : moved path-attributes container to grouping
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / AdjRIBOutEntry.java
1 /*
2  * Copyright (c) 2014 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 com.google.common.base.Preconditions;
11 import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
12 import org.opendaylight.protocol.bgp.rib.spi.RouteEncoder;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.Route;
15 import org.opendaylight.yangtools.yang.binding.DataContainer;
16
17 @Deprecated
18 final class AdjRIBOutEntry<K, V extends Route> {
19     @SuppressWarnings("rawtypes")
20     private static final AtomicReferenceFieldUpdater<AdjRIBOutEntry, Route> NLRIENTRY_ADV_UPDATER = AtomicReferenceFieldUpdater.newUpdater(AdjRIBOutEntry.class, Route.class, "advertisedValue");
21     @SuppressWarnings("rawtypes")
22     private static final AtomicReferenceFieldUpdater<AdjRIBOutEntry, Route> NLRIENTRY_CUR_UPDATER = AtomicReferenceFieldUpdater.newUpdater(AdjRIBOutEntry.class, Route.class, "currentValue");
23
24     /*
25      * Marker object for uninitialized value. Distinct from null.
26      */
27     private static final Route NLRIENTRY_NONE_VALUE = new Route() {
28         @Override
29         public Class<? extends DataContainer> getImplementedInterface() {
30             throw new IllegalStateException("This method should never be invoked");
31         }
32
33         @Override
34         public Attributes getAttributes() {
35             throw new IllegalStateException("This method should never be invoked");
36         }
37     };
38
39     // Referenced via AtomicReferenceFieldUpdaters
40     @SuppressWarnings("unused")
41     private volatile Route currentValue = NLRIENTRY_NONE_VALUE;
42     @SuppressWarnings("unused")
43     private volatile Route advertisedValue = NLRIENTRY_NONE_VALUE;
44     private final RouteEncoder ribOut;
45
46     AdjRIBOutEntry(final RouteEncoder ribOut) {
47         this.ribOut = Preconditions.checkNotNull(ribOut);
48     }
49
50     Route getAdverised() {
51         return NLRIENTRY_ADV_UPDATER.get(this);
52     }
53
54     void setAdverised(final V value) {
55         NLRIENTRY_ADV_UPDATER.set(this, value);
56     }
57
58     @SuppressWarnings("unchecked")
59     V getCurrent() {
60         final Route o = NLRIENTRY_CUR_UPDATER.get(this);
61         Preconditions.checkState(!isNone(o), "Value cannot be NONE here");
62         return (V) o;
63     }
64
65     Route getAndSetCurrent(final V value) {
66         return NLRIENTRY_CUR_UPDATER.getAndSet(this, value);
67     }
68
69     RouteEncoder getRibOut() {
70         return this.ribOut;
71     }
72
73     static boolean isNone(final Object o) {
74         return NLRIENTRY_NONE_VALUE.equals(o);
75     }
76 }