Replace Preconditions.CheckNotNull per RequireNonNull
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / DefaultPCEPSessionNegotiatorFactory.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 static java.util.Objects.requireNonNull;
11
12 import io.netty.channel.Channel;
13 import io.netty.util.concurrent.Promise;
14 import java.net.InetSocketAddress;
15 import org.opendaylight.protocol.pcep.PCEPPeerProposal;
16 import org.opendaylight.protocol.pcep.PCEPSessionListener;
17 import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.app.config.rev160707.PcepDispatcherConfig;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.app.config.rev160707.pcep.dispatcher.config.Tls;
20
21 public final class DefaultPCEPSessionNegotiatorFactory extends AbstractPCEPSessionNegotiatorFactory {
22     private final PCEPSessionProposalFactory spf;
23     private final int maxUnknownMessages;
24     private final Tls tlsConfiguration;
25
26     public DefaultPCEPSessionNegotiatorFactory(final PCEPSessionProposalFactory spf, final int maxUnknownMessages) {
27         this(spf, maxUnknownMessages, null);
28     }
29
30     public DefaultPCEPSessionNegotiatorFactory(final PCEPSessionProposalFactory spf, final int maxUnknownMessages, final Tls tlsConfiguration) {
31         this.spf = requireNonNull(spf);
32         this.maxUnknownMessages = maxUnknownMessages;
33         this.tlsConfiguration = tlsConfiguration;
34     }
35
36     public DefaultPCEPSessionNegotiatorFactory(final PCEPSessionProposalFactory spf, final PcepDispatcherConfig config) {
37         this(spf, config.getMaxUnknownMessages(), config.getTls());
38     }
39
40     @Override
41     protected AbstractPCEPSessionNegotiator createNegotiator(final Promise<PCEPSessionImpl> promise, final PCEPSessionListener listener,
42             final Channel channel, final short sessionId, final PCEPPeerProposal peerProposal) {
43         return new DefaultPCEPSessionNegotiator(promise, channel, listener, sessionId, this.maxUnknownMessages,
44                 this.spf.getSessionProposal((InetSocketAddress)channel.remoteAddress(), sessionId, peerProposal), this.tlsConfiguration);
45     }
46
47     @Override
48     public PCEPSessionProposalFactory getPCEPSessionProposalFactory() {
49         return this.spf;
50     }
51 }