BUG-58: refactor to take advantage of netty
[bgpcep.git] / framework / src / test / java / org / opendaylight / protocol / framework / 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.framework;
9
10 import java.util.ArrayList;
11 import java.util.List;
12
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
15
16 /**
17  * Simple Session Listener that is notified about messages and changes in the session.
18  */
19 public class SimpleSessionListener implements SessionListener<SimpleMessage, SimpleSession, TerminationReason> {
20         private static final Logger logger = LoggerFactory.getLogger(SimpleSessionListener.class);
21
22         public List<ProtocolMessage> messages = new ArrayList<ProtocolMessage>();
23
24         public boolean up = false;
25
26         public boolean failed = false;
27
28         @Override
29         public void onMessage(final SimpleSession session, final SimpleMessage message) {
30                 logger.debug("Received message: " + message.getClass() + " " + message);
31                 this.messages.add(message);
32         }
33
34         public synchronized void onConnectionFailed(final ProtocolSession<?> session, final Exception e) {
35                 logger.debug("Connection Failed: {}", e.getMessage(), e);
36                 this.failed = true;
37                 this.notifyAll();
38                 session.close();
39         }
40
41         @Override
42         public void onSessionUp(final SimpleSession session) {
43                 this.up = true;
44         }
45
46         @Override
47         public void onSessionDown(final SimpleSession session, final Exception e) {
48                 this.up = false;
49         }
50
51         @Override
52         public void onSessionTerminated(final SimpleSession session,
53                         final TerminationReason reason) {
54                 this.up = false;
55         }
56 }