BUG-58: refactor to take advantage of netty
[bgpcep.git] / bgp / testtool / src / main / java / org / opendaylight / protocol / bgp / testtool / TestingListener.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.testtool;
9
10 import org.opendaylight.protocol.bgp.parser.BGPMessage;
11 import org.opendaylight.protocol.bgp.parser.BGPSession;
12 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
13 import org.opendaylight.protocol.bgp.parser.BGPTerminationReason;
14 import org.opendaylight.protocol.framework.DispatcherImpl;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 /**
19  * Testing BGP Listener.
20  */
21 public class TestingListener implements BGPSessionListener {
22         private static final Logger logger = LoggerFactory.getLogger(TestingListener.class);
23
24         DispatcherImpl d;
25
26         TestingListener(final DispatcherImpl d) {
27                 this.d = d;
28         }
29
30         @Override
31         public void onMessage(final BGPSession session, final BGPMessage message) {
32                 logger.info("Client Listener: message received: {}", message.toString());
33         }
34
35         @Override
36         public void onSessionUp(final BGPSession session) {
37                 logger.info("Client Listener: Session Up.");
38         }
39
40         @Override
41         public void onSessionDown(final BGPSession session, final Exception e) {
42                 logger.info("Client Listener: Connection lost.");
43                 session.close();
44                 // this.d.stop();
45         }
46
47         @Override
48         public void onSessionTerminated(final BGPSession session, final BGPTerminationReason cause) {
49                 logger.info("Client Listener: Connection lost: {}.", cause);
50                 // this.d.stop();
51         }
52 }