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