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