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.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;
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");
25 * Marker object for uninitialized value. Distinct from null.
27 private static final Route NLRIENTRY_NONE_VALUE = new Route() {
29 public Class<? extends DataContainer> getImplementedInterface() {
30 throw new IllegalStateException("This method should never be invoked");
34 public Attributes getAttributes() {
35 throw new IllegalStateException("This method should never be invoked");
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;
46 AdjRIBOutEntry(final RouteEncoder ribOut) {
47 this.ribOut = Preconditions.checkNotNull(ribOut);
50 Route getAdverised() {
51 return NLRIENTRY_ADV_UPDATER.get(this);
54 void setAdverised(final V value) {
55 NLRIENTRY_ADV_UPDATER.set(this, value);
58 @SuppressWarnings("unchecked")
60 final Route o = NLRIENTRY_CUR_UPDATER.get(this);
61 Preconditions.checkState(!isNone(o), "Value cannot be NONE here");
65 Route getAndSetCurrent(final V value) {
66 return NLRIENTRY_CUR_UPDATER.getAndSet(this, value);
69 RouteEncoder getRibOut() {
73 static boolean isNone(final Object o) {
74 return NLRIENTRY_NONE_VALUE.equals(o);