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