PCEP Entity Identifier configurable
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / AbstractPCEPSessionNegotiatorFactory.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 io.netty.channel.Channel;
11 import io.netty.util.concurrent.Promise;
12 import org.opendaylight.protocol.pcep.PCEPSessionNegotiatorFactory;
13 import org.opendaylight.protocol.pcep.PCEPSessionNegotiatorFactoryDependencies;
14 import org.opendaylight.protocol.pcep.SessionNegotiator;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 /**
19  * SessionNegotiator which takes care of making sure sessions between PCEP peers are kept unique. This needs to be
20  * further subclassed to provide either a client or server factory.
21  */
22 public abstract class AbstractPCEPSessionNegotiatorFactory implements PCEPSessionNegotiatorFactory<PCEPSessionImpl> {
23
24     private static final Logger LOG = LoggerFactory.getLogger(AbstractPCEPSessionNegotiatorFactory.class);
25
26     private final PCEPPeerRegistry sessionRegistry = new PCEPPeerRegistry();
27
28     /**
29      * Create a new negotiator. This method needs to be implemented by subclasses to actually provide a negotiator.
30      *
31      * @param snd       PCEP Session Negotiator dependencies
32      * @param promise   Session promise to be completed by the negotiator
33      * @param channel   Associated channel
34      * @param sessionId Session ID assigned to the resulting session
35      * @return a PCEP session negotiator
36      */
37     protected abstract AbstractPCEPSessionNegotiator createNegotiator(
38             PCEPSessionNegotiatorFactoryDependencies snd,
39             Promise<PCEPSessionImpl> promise,
40             Channel channel, short sessionId);
41
42     @Override
43     public final SessionNegotiator getSessionNegotiator(final PCEPSessionNegotiatorFactoryDependencies dependencies,
44             final Channel channel, final Promise<PCEPSessionImpl> promise) {
45
46         LOG.debug("Instantiating bootstrap negotiator for channel {}", channel);
47         return new PCEPSessionNegotiator(channel, promise, dependencies, this);
48     }
49
50     public PCEPPeerRegistry getSessionRegistry() {
51         return this.sessionRegistry;
52     }
53 }