BUG-6784 - Failed to fully assemble schema context for ..
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / CacheDisconnectedPeersImpl.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bgp.rib.impl;
9
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;
17
18 public final class CacheDisconnectedPeersImpl implements CacheDisconnectedPeers {
19     private static Cache<PeerId, Boolean> cache = CacheBuilder.newBuilder().expireAfterAccess(30, TimeUnit.SECONDS).build();
20
21     CacheDisconnectedPeersImpl() {
22     }
23
24     @Override
25     public boolean isPeerDisconnected(final PeerId peerId) {
26         if (this.cache.getIfPresent(peerId) != null) {
27             return true;
28         }
29         return false;
30     }
31
32     @Override
33     public void reconnected(final PeerId peerId) {
34         this.cache.asMap().remove(peerId);
35     }
36
37     @Override
38     public void insertDesconectedPeer(final Ipv4Address peerId) {
39         this.cache.put(RouterIds.createPeerId(peerId), true);
40     }
41 }