BUG-58: refactor to take advantage of netty
[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 java.util.List;
11
12 import org.opendaylight.protocol.bgp.parser.BGPMessage;
13 import org.opendaylight.protocol.bgp.parser.BGPSession;
14 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
15 import org.opendaylight.protocol.bgp.parser.BGPTerminationReason;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 import com.google.common.collect.Lists;
20
21 /**
22  * Listener for the client.
23  */
24 public class SimpleSessionListener implements BGPSessionListener {
25
26         private final List<BGPMessage> listMsg = Lists.newArrayList();
27
28         private BGPSessionImpl session = null;
29
30         public boolean up = false;
31
32         private static final Logger logger = LoggerFactory.getLogger(SimpleSessionListener.class);
33
34         public boolean down = false;
35
36         public SimpleSessionListener() {
37         }
38
39         public void sendMessage(final BGPMessage msg) {
40                 this.session.handleMessage(msg);
41         }
42
43         public List<BGPMessage> getListMsg() {
44                 return this.listMsg;
45         }
46
47         public void addSession(final BGPSessionImpl l) {
48                 this.session = l;
49         }
50
51         @Override
52         public void onMessage(final BGPSession session, final BGPMessage message) {
53                 this.listMsg.add(message);
54                 logger.debug("Message received:" + message);
55         }
56
57         @Override
58         public void onSessionUp(final BGPSession session) {
59                 logger.debug("Session Up");
60                 this.up = true;
61                 this.notifyAll();
62         }
63
64         @Override
65         public void onSessionDown(final BGPSession session, final Exception e) {
66                 logger.debug("Session Down", e);
67                 this.down = true;
68         }
69
70         @Override
71         public void onSessionTerminated(final BGPSession session, final BGPTerminationReason cause) {
72                 logger.debug("Session terminated. Cause : " + cause.toString());
73         }
74 }