Merge "Remove check for empty lists, where not needed."
[bgpcep.git] / pcep / pcc-mock / src / test / java / org / opendaylight / protocol / pcep / pcc / mock / TestingSessionListener.java
1 /*
2  * Copyright (c) 2015 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
9 package org.opendaylight.protocol.pcep.pcc.mock;
10
11 import com.google.common.collect.Lists;
12 import java.util.List;
13 import org.opendaylight.protocol.pcep.PCEPSession;
14 import org.opendaylight.protocol.pcep.PCEPSessionListener;
15 import org.opendaylight.protocol.pcep.PCEPTerminationReason;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 public class TestingSessionListener implements PCEPSessionListener {
21
22     private static final Logger LOG = LoggerFactory.getLogger(TestingSessionListener.class);
23
24     private final List<Message> messages = Lists.newArrayList();
25
26     private boolean up = false;
27     private PCEPSession session = null;
28
29     @Override
30     public void onMessage(final PCEPSession session, final Message message) {
31         LOG.debug("Received message: {}", message);
32         this.messages.add(message);
33     }
34
35     @Override
36     public void onSessionUp(final PCEPSession session) {
37         LOG.debug("Session up.");
38         this.up = true;
39         this.session = session;
40     }
41
42     @Override
43     public void onSessionDown(final PCEPSession session, final Exception e) {
44         LOG.debug("Session down. Cause : {} ", e, e);
45         this.up = false;
46         this.session = null;
47     }
48
49     @Override
50     public void onSessionTerminated(final PCEPSession session, final PCEPTerminationReason cause) {
51         LOG.debug("Session terminated. Cause : {}", cause);
52     }
53
54     public List<Message> messages() {
55         return this.messages;
56     }
57
58     public boolean isUp () {
59         return this.up;
60     }
61
62     public PCEPSession getSession() {
63         return this.session;
64     }
65 }