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;
12 import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
14 import org.opendaylight.protocol.bgp.rib.spi.RouteEncoder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.Route;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.route.Attributes;
17 import org.opendaylight.yangtools.yang.binding.DataContainer;
19 final class AdjRIBOutEntry<K, V extends Route> {
20 @SuppressWarnings("rawtypes")
21 private static final AtomicReferenceFieldUpdater<AdjRIBOutEntry, Route> NLRIENTRY_ADV_UPDATER = AtomicReferenceFieldUpdater.newUpdater(AdjRIBOutEntry.class, Route.class, "advertisedValue");
22 @SuppressWarnings("rawtypes")
23 private static final AtomicReferenceFieldUpdater<AdjRIBOutEntry, Route> NLRIENTRY_CUR_UPDATER = AtomicReferenceFieldUpdater.newUpdater(AdjRIBOutEntry.class, Route.class, "currentValue");
26 * Marker object for uninitialized value. Distinct from null.
28 private static final Route NLRIENTRY_NONE_VALUE = new Route() {
30 public Class<? extends DataContainer> getImplementedInterface() {
31 throw new IllegalStateException("This method should never be invoked");
35 public Attributes getAttributes() {
36 throw new IllegalStateException("This method should never be invoked");
40 // Referenced via AtomicReferenceFieldUpdaters
41 @SuppressWarnings("unused")
42 private volatile Route currentValue = NLRIENTRY_NONE_VALUE;
43 @SuppressWarnings("unused")
44 private volatile Route advertisedValue = NLRIENTRY_NONE_VALUE;
45 private final RouteEncoder ribOut;
47 AdjRIBOutEntry(final RouteEncoder ribOut) {
48 this.ribOut = Preconditions.checkNotNull(ribOut);
51 Route getAdverised() {
52 return NLRIENTRY_ADV_UPDATER.get(this);
55 void setAdverised(final V value) {
56 NLRIENTRY_ADV_UPDATER.set(this, value);
59 @SuppressWarnings("unchecked")
61 final Route o = NLRIENTRY_CUR_UPDATER.get(this);
62 Preconditions.checkState(!isNone(o), "Value cannot be NONE here");
66 Route getAndSetCurrent(final V value) {
67 return NLRIENTRY_CUR_UPDATER.getAndSet(this, value);
70 RouteEncoder getRibOut() {
74 static final boolean isNone(final Object o) {
75 return o == NLRIENTRY_NONE_VALUE;