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