Add new revision for pcep types model
[bgpcep.git] / pcep / pcc-mock / src / test / java / org / opendaylight / protocol / pcep / pcc / mock / TestingSessionListenerFactory.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 java.net.InetAddress;
12 import java.util.ArrayList;
13 import java.util.List;
14 import javax.annotation.concurrent.GuardedBy;
15 import org.opendaylight.protocol.pcep.PCEPSession;
16 import org.opendaylight.protocol.pcep.PCEPSessionListener;
17 import org.opendaylight.protocol.pcep.PCEPSessionListenerFactory;
18
19 class TestingSessionListenerFactory implements PCEPSessionListenerFactory {
20
21     @GuardedBy("this")
22     private final List<TestingSessionListener> sessionListeners = new ArrayList<>();
23
24     @Override
25     public PCEPSessionListener getSessionListener() {
26         final TestingSessionListener sessionListener = new TestingSessionListener();
27         this.sessionListeners.add(sessionListener);
28         return sessionListener;
29     }
30
31     TestingSessionListener getSessionListenerByRemoteAddress(final InetAddress ipAddress) {
32         for (final TestingSessionListener sessionListener : this.sessionListeners) {
33             if (sessionListener.isUp()) {
34                 final PCEPSession session = sessionListener.getSession();
35                 if (session.getRemoteAddress().equals(ipAddress)) {
36                     return sessionListener;
37                 }
38             }
39         }
40         return null;
41     }
42 }