Apply modernization to pcep-impl
[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 import org.opendaylight.protocol.pcep.PCEPSession;
13 import org.opendaylight.protocol.pcep.PCEPSessionListener;
14 import org.opendaylight.protocol.pcep.PCEPTerminationReason;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Message;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 /**
20  * Simple Session Listener that is notified about messages and changes in the session.
21  */
22 public class SimpleSessionListener implements PCEPSessionListener {
23
24     public final List<Message> messages = new ArrayList<>();
25
26     public boolean up = false;
27
28     private static final Logger LOG = LoggerFactory.getLogger(SimpleSessionListener.class);
29
30     public SimpleSessionListener() {
31     }
32
33     @Override
34     public void onMessage(final PCEPSession session, final Message message) {
35         LOG.debug("Received message: {} {}", message.getClass(), message);
36         this.messages.add(message);
37     }
38
39     @Override
40     public synchronized void onSessionUp(final PCEPSession session) {
41         LOG.debug("Session up.");
42         this.up = true;
43         this.notifyAll();
44     }
45
46     @Override
47     public void onSessionDown(final PCEPSession session, final Exception exception) {
48         LOG.debug("Session down.", exception);
49         this.up = false;
50         // this.notifyAll();
51     }
52
53     @Override
54     public void onSessionTerminated(final PCEPSession session, final PCEPTerminationReason cause) {
55         LOG.debug("Session terminated. Cause : {}", cause.toString());
56         this.up = false;
57     }
58 }