2 * Copyright (c) 2016 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.cache.Cache;
11 import com.google.common.cache.CacheBuilder;
12 import java.util.concurrent.TimeUnit;
13 import org.opendaylight.protocol.bgp.rib.spi.CacheDisconnectedPeers;
14 import org.opendaylight.protocol.bgp.rib.spi.RouterIds;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerId;
18 public final class CacheDisconnectedPeersImpl implements CacheDisconnectedPeers {
19 private static Cache<PeerId, Boolean> cache = CacheBuilder.newBuilder().expireAfterAccess(30, TimeUnit.SECONDS).build();
21 CacheDisconnectedPeersImpl() {
25 public boolean isPeerDisconnected(final PeerId peerId) {
26 if (this.cache.getIfPresent(peerId) != null) {
33 public void reconnected(final PeerId peerId) {
34 this.cache.asMap().remove(peerId);
38 public void insertDesconectedPeer(final Ipv4Address peerId) {
39 this.cache.put(RouterIds.createPeerId(peerId), true);