2 * Copyright (c) 2014 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 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.rib.rev130925.Route;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.route.Attributes;
15 import org.opendaylight.yangtools.yang.binding.DataContainer;
17 final class AdjRIBOutEntry<K, V extends Route> {
18 @SuppressWarnings("rawtypes")
19 private static final AtomicReferenceFieldUpdater<AdjRIBOutEntry, Route> NLRIENTRY_ADV_UPDATER = AtomicReferenceFieldUpdater.newUpdater(AdjRIBOutEntry.class, Route.class, "advertisedValue");
20 @SuppressWarnings("rawtypes")
21 private static final AtomicReferenceFieldUpdater<AdjRIBOutEntry, Route> NLRIENTRY_CUR_UPDATER = AtomicReferenceFieldUpdater.newUpdater(AdjRIBOutEntry.class, Route.class, "currentValue");
24 * Marker object for uninitialized value. Distinct from null.
26 private static final Route NLRIENTRY_NONE_VALUE = new Route() {
28 public Class<? extends DataContainer> getImplementedInterface() {
29 throw new IllegalStateException("This method should never be invoked");
33 public Attributes getAttributes() {
34 throw new IllegalStateException("This method should never be invoked");
38 // Referenced via AtomicReferenceFieldUpdaters
39 @SuppressWarnings("unused")
40 private volatile Route currentValue = NLRIENTRY_NONE_VALUE;
41 @SuppressWarnings("unused")
42 private volatile Route advertisedValue = NLRIENTRY_NONE_VALUE;
43 private final RouteEncoder ribOut;
45 AdjRIBOutEntry(final RouteEncoder ribOut) {
46 this.ribOut = Preconditions.checkNotNull(ribOut);
49 Route getAdverised() {
50 return NLRIENTRY_ADV_UPDATER.get(this);
53 void setAdverised(final V value) {
54 NLRIENTRY_ADV_UPDATER.set(this, value);
57 @SuppressWarnings("unchecked")
59 final Route o = NLRIENTRY_CUR_UPDATER.get(this);
60 Preconditions.checkState(!isNone(o), "Value cannot be NONE here");
64 Route getAndSetCurrent(final V value) {
65 return NLRIENTRY_CUR_UPDATER.getAndSet(this, value);
68 RouteEncoder getRibOut() {
72 static boolean isNone(final Object o) {
73 return o == NLRIENTRY_NONE_VALUE;