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