c7e3d3aaca2c454a82bb39d4622b212244dd4020
[bgpcep.git] / bgp / rib-impl / src / test / java / org / opendaylight / protocol / bgp / rib / impl / SimpleSessionListener.java
1 /*
2  * Copyright (c) 2013 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.collect.Lists;
11 import java.util.List;
12 import org.opendaylight.protocol.bgp.rib.spi.BGPSession;
13 import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
14 import org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
16 import org.opendaylight.yangtools.yang.binding.Notification;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 /**
21  * Listener for the client.
22  */
23 public class SimpleSessionListener implements BGPSessionListener {
24
25     private final List<Notification> listMsg = Lists.newArrayList();
26
27     public boolean up = false;
28
29     private static final Logger LOG = LoggerFactory.getLogger(SimpleSessionListener.class);
30
31     public boolean down = false;
32
33     private BGPSession session;
34
35     public SimpleSessionListener() {
36     }
37
38     public List<Notification> getListMsg() {
39         return this.listMsg;
40     }
41
42     @Override
43     public void onMessage(final BGPSession session, final Notification message) {
44         this.listMsg.add(message);
45         LOG.debug("Message received: {}", message);
46     }
47
48     @Override
49     public void onSessionUp(final BGPSession session) {
50         LOG.debug("Session Up");
51         this.session = session;
52         this.up = true;
53     }
54
55     @Override
56     public void onSessionDown(final BGPSession session, final Exception e) {
57         LOG.debug("Session Down", e);
58         this.down = true;
59     }
60
61     @Override
62     public void onSessionTerminated(final BGPSession session, final BGPTerminationReason cause) {
63         LOG.debug("Session terminated. Cause : {}", cause.toString());
64     }
65
66     @Override
67     public void releaseConnection() {
68         LOG.debug("Releasing connection");
69         if (this.session != null) {
70             try {
71                 this.session.close();
72             } catch (final Exception e) {
73                 LOG.warn("Error closing session", e);
74             }
75             this.session = null;
76         }
77     }
78
79     @Override
80     public boolean isSessionActive() {
81         return true;
82     }
83
84     @Override
85     public void markUptodate(final TablesKey tablesKey) {
86         LOG.debug("Table marked as up-to-date {}", tablesKey);
87     }
88 }