2 * Copyright (c) 2013 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.collect.Lists;
11 import com.google.common.util.concurrent.Uninterruptibles;
12 import java.util.List;
13 import java.util.concurrent.CountDownLatch;
14 import java.util.concurrent.TimeUnit;
15 import org.junit.Assert;
16 import org.opendaylight.protocol.bgp.rib.spi.BGPSession;
17 import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
18 import org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
20 import org.opendaylight.yangtools.yang.binding.Notification;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * Listener for the client.
27 public final class SimpleSessionListener implements BGPSessionListener {
29 private static final Logger LOG = LoggerFactory.getLogger(SimpleSessionListener.class);
30 private final List<Notification> listMsg = Lists.newArrayList();
31 private BGPSession session;
32 private final CountDownLatch sessionLatch = new CountDownLatch(1);
34 SimpleSessionListener() {
37 List<Notification> getListMsg() {
42 public void markUptodate(final TablesKey tablesKey) {
43 LOG.debug("Table marked as up-to-date {}", tablesKey);
47 public void onSessionUp(final BGPSession session) {
48 LOG.info("Session Up");
49 this.session = session;
50 this.sessionLatch.countDown();
54 public void onSessionDown(final BGPSession session, final Exception e) {
55 LOG.debug("Session Down", e);
59 public void onSessionTerminated(final BGPSession session, final BGPTerminationReason cause) {
60 LOG.debug("Session terminated. Cause : {}", cause.toString());
64 public void onMessage(final BGPSession session, final Notification message) {
65 this.listMsg.add(message);
66 LOG.debug("Message received: {}", message);
70 public void releaseConnection() {
71 LOG.debug("Releasing connection");
72 if (this.session != null) {
75 } catch (final Exception e) {
76 LOG.warn("Error closing session", e);
81 BGPSessionImpl.State getState() {
82 return getSession().getState();
85 BGPSessionImpl getSession() {
86 Assert.assertEquals("Session up", true, Uninterruptibles.awaitUninterruptibly(this.sessionLatch, 10, TimeUnit.SECONDS));
87 return (BGPSessionImpl) this.session;