Fixed javadocs for java8.
[bgpcep.git] / bgp / rib-spi / src / main / java / org / opendaylight / protocol / bgp / rib / spi / AbstractAdjRIBs.java
index 4c42505d473a1b055683f1e3330c41852a236461..bb479e0ae7e84068442cfea8e422b941fa51fcac 100644 (file)
@@ -7,8 +7,8 @@
  */
 package org.opendaylight.protocol.bgp.rib.spi;
 
-import com.google.common.base.Objects;
-import com.google.common.base.Objects.ToStringHelper;
+import com.google.common.base.MoreObjects;
+import com.google.common.base.MoreObjects.ToStringHelper;
 import com.google.common.base.Preconditions;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -39,6 +39,7 @@ import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@Deprecated
 @ThreadSafe
 public abstract class AbstractAdjRIBs<I, D extends Identifiable<K> & Route, K extends Identifier<D>> implements AdjRIBsIn<I, D>, RouteEncoder {
     protected abstract static class RIBEntryData<I, D extends Identifiable<K> & Route, K extends Identifier<D>> {
@@ -69,7 +70,7 @@ public abstract class AbstractAdjRIBs<I, D extends Identifiable<K> & Route, K ex
 
         @Override
         public final String toString() {
-            return addToStringAttributes(Objects.toStringHelper(this)).toString();
+            return addToStringAttributes(MoreObjects.toStringHelper(this)).toString();
         }
 
         protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
@@ -77,107 +78,13 @@ public abstract class AbstractAdjRIBs<I, D extends Identifiable<K> & Route, K ex
         }
     }
 
-    /**
-     * A single RIB table entry, which holds multiple versions of the entry's state and elects the authoritative based
-     * on ordering specified by the supplied comparator.
-     *
-     */
-    private final class RIBEntry {
-        private static final int DEFAULT_MAP_SIZE = 2;
-        /*
-         * TODO: we could dramatically optimize performance by using the comparator
-         *       to retain the candidate states ordered -- thus selection would occur
-         *       automatically through insertion, without the need of a second walk.
-         */
-        private final Map<Peer, RIBEntryData<I, D, K>> candidates = new HashMap<>(DEFAULT_MAP_SIZE);
-        private final I key;
-
-        @GuardedBy("this")
-        private KeyedInstanceIdentifier<D, K> name;
-        @GuardedBy("this")
-        private RIBEntryData<I, D, K> currentState;
-
-        RIBEntry(final I key) {
-            this.key = Preconditions.checkNotNull(key);
-        }
-
-        private KeyedInstanceIdentifier<D, K> getName() {
-            if (this.name == null) {
-                this.name = identifierForKey(this.key);
-                LOG.trace("Entry {} grew key {}", this, this.name);
-            }
-            return this.name;
-        }
-
-        /**
-         * Based on given comparator, finds a new best candidate for initial route.
-         *
-         * @param comparator
-         * @param initial
-         * @return
-         */
-        private RIBEntryData<I, D, K> findCandidate(final BGPObjectComparator comparator, final RIBEntryData<I, D, K> initial) {
-            RIBEntryData<I, D, K> newState = initial;
-            for (final RIBEntryData<I, D, K> s : this.candidates.values()) {
-                if (newState == null || comparator.compare(newState, s) > 0) {
-                    newState = s;
-                }
-            }
-
-            return newState;
-        }
-
-        /**
-         * Advertize newly elected best candidate to datastore.
-         *
-         * @param transaction
-         * @param candidate
-         */
-        private void electCandidate(final AdjRIBsTransaction transaction, final RIBEntryData<I, D, K> candidate) {
-            LOG.trace("Electing state {} to supersede {}", candidate, this.currentState);
-
-            if (this.currentState == null || !this.currentState.equals(candidate)) {
-                LOG.trace("Elected new state for {}: {}", getName(), candidate);
-                transaction.advertise(AbstractAdjRIBs.this, this.key, getName(), candidate.getPeer(), candidate.getDataObject(this.key, getName().getKey()));
-                this.currentState = candidate;
-            }
-        }
-
-        /**
-         * Removes RIBEntry from database. If we are removing best path, elect another candidate (using BPS).
-         * If there are no other candidates, remove the path completely.
-         * @param transaction
-         * @param peer
-         * @return true if the list of the candidates for this path is empty
-         */
-        synchronized boolean removeState(final AdjRIBsTransaction transaction, final Peer peer) {
-            final RIBEntryData<I, D, K> data = this.candidates.remove(peer);
-            LOG.trace("Removed data {}", data);
-
-            final RIBEntryData<I, D, K> candidate = findCandidate(transaction.comparator(), null);
-            if (candidate != null) {
-                electCandidate(transaction, candidate);
-            } else {
-                LOG.trace("Final candidate disappeared, removing entry {}", getName());
-                transaction.withdraw(AbstractAdjRIBs.this, this.key, getName());
-            }
-
-            return this.candidates.isEmpty();
-        }
-
-        synchronized void setState(final AdjRIBsTransaction transaction, final Peer peer, final RIBEntryData<I, D, K> state) {
-            this.candidates.put(Preconditions.checkNotNull(peer), Preconditions.checkNotNull(state));
-            electCandidate(transaction, findCandidate(transaction.comparator(), state));
-        }
-    }
-
     private static final Logger LOG = LoggerFactory.getLogger(AbstractAdjRIBs.class);
     private final KeyedInstanceIdentifier<Tables, TablesKey> basePath;
     private final BgpTableType tableType;
     private final Update eor;
 
     @GuardedBy("this")
-    private final Map<I, RIBEntry> entries = new HashMap<>();
+    private final Map<I, RIBEntry<I, D, K>> entries = new HashMap<>();
 
     @GuardedBy("this")
     private final Map<Peer, Boolean> peers = new HashMap<>();
@@ -192,9 +99,9 @@ public abstract class AbstractAdjRIBs<I, D extends Identifiable<K> & Route, K ex
 
     @Override
     public final synchronized void clear(final AdjRIBsTransaction trans, final Peer peer) {
-        final Iterator<Entry<I, RIBEntry>> i = this.entries.entrySet().iterator();
+        final Iterator<Entry<I, RIBEntry<I, D, K>>> i = this.entries.entrySet().iterator();
         while (i.hasNext()) {
-            final Entry<I, RIBEntry> e = i.next();
+            final Entry<I, RIBEntry<I, D, K>> e = i.next();
 
             if (e.getValue().removeState(trans, peer)) {
                 i.remove();
@@ -206,10 +113,10 @@ public abstract class AbstractAdjRIBs<I, D extends Identifiable<K> & Route, K ex
     }
 
     public final synchronized void addAllEntries(final AdjRIBsTransaction trans) {
-        for (final Entry<I, RIBEntry> e : this.entries.entrySet()) {
-            final RIBEntry entry = e.getValue();
+        for (final Entry<I, RIBEntry<I, D, K>> e : this.entries.entrySet()) {
+            final RIBEntry<I, D, K> entry = e.getValue();
             final RIBEntryData<I, D, K> state = entry.currentState;
-            trans.advertise(this, e.getKey(), entry.name, state.peer, state.getDataObject(entry.key, entry.name.getKey()));
+            trans.advertise(this, e.getKey(), entry.name, state.peer, state.getDataObject(entry.getKey(), entry.name.getKey()));
         }
     }
 
@@ -252,7 +159,7 @@ public abstract class AbstractAdjRIBs<I, D extends Identifiable<K> & Route, K ex
 
     /**
      * Transform a withdrawn identifier into a the corresponding NLRI in MP_UNREACH attribute.
-     *
+     * @param builder MpUnreachNlriBuilder
      * @param id Route key
      */
     protected abstract void addWithdrawal(MpUnreachNlriBuilder builder, I id);
@@ -273,7 +180,7 @@ public abstract class AbstractAdjRIBs<I, D extends Identifiable<K> & Route, K ex
     public abstract I keyForIdentifier(KeyedInstanceIdentifier<D, K> id);
 
     /**
-     * Common backend for {@link AdjRIBsIn#addRoutes()} implementations.
+     * Common backend for {@link AdjRIBsIn#addRoutes(AdjRIBsTransaction, Peer, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpReachNlri, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributes)} implementations.
      * If a new route is added, check first for its existence in Map of entries.
      * If the route is already there, change it's state. Then check for peer in
      * Map of peers, if it's not there, add it.
@@ -286,9 +193,9 @@ public abstract class AbstractAdjRIBs<I, D extends Identifiable<K> & Route, K ex
     protected final synchronized void add(final AdjRIBsTransaction trans, final Peer peer, final I id, final RIBEntryData<I, D, K> data) {
         LOG.debug("Adding state {} for {} peer {}", data, id, peer);
 
-        RIBEntry e = this.entries.get(Preconditions.checkNotNull(id));
+        RIBEntry<I, D, K> e = this.entries.get(Preconditions.checkNotNull(id));
         if (e == null) {
-            e = new RIBEntry(id);
+            e = new RIBEntry<I, D, K>(this, id);
             this.entries.put(id, e);
         }
 
@@ -300,14 +207,14 @@ public abstract class AbstractAdjRIBs<I, D extends Identifiable<K> & Route, K ex
     }
 
     /**
-     * Common backend for {@link AdjRIBsIn#removeRoutes()} implementations.
+     * Common backend for {@link AdjRIBsIn#removeRoutes(AdjRIBsTransaction, Peer, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpUnreachNlri)} implementations.
      *
      * @param trans Transaction context
      * @param peer Originating peer
      * @param id Data store instance identifier
      */
     protected final synchronized void remove(final AdjRIBsTransaction trans, final Peer peer, final I id) {
-        final RIBEntry e = this.entries.get(id);
+        final RIBEntry<I, D, K> e = this.entries.get(id);
         if (e != null && e.removeState(trans, peer)) {
             LOG.debug("Removed last state, removing entry for {}", id);
             this.entries.remove(id);