Move protocol framework from BGPCEP project
[controller.git] / opendaylight / commons / protocol-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<SimpleMessage> messages = new ArrayList<SimpleMessage>();
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     @Override
35     public void onSessionUp(final SimpleSession session) {
36         this.up = true;
37     }
38
39     @Override
40     public void onSessionDown(final SimpleSession session, final Exception e) {
41         this.failed = true;
42         this.notifyAll();
43     }
44
45     @Override
46     public void onSessionTerminated(final SimpleSession session, final TerminationReason reason) {
47         this.failed = true;
48         this.notifyAll();
49     }
50 }