Merge "BUG-1287: migrate tests to new APIs"
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / BGPSessionNegotiatorFactory.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.bgp.rib.impl;
9
10 import com.google.common.base.Preconditions;
11
12 import io.netty.channel.Channel;
13 import io.netty.util.Timer;
14 import io.netty.util.concurrent.Promise;
15
16 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
17 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
18 import org.opendaylight.protocol.framework.SessionListenerFactory;
19 import org.opendaylight.protocol.framework.SessionNegotiator;
20 import org.opendaylight.protocol.framework.SessionNegotiatorFactory;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
22 import org.opendaylight.yangtools.yang.binding.Notification;
23
24 public final class BGPSessionNegotiatorFactory implements SessionNegotiatorFactory<Notification, BGPSessionImpl, BGPSessionListener> {
25     private final BGPSessionPreferences initialPrefs;
26     private final AsNumber remoteAs;
27     private final Timer timer;
28
29     public BGPSessionNegotiatorFactory(final Timer timer, final BGPSessionPreferences initialPrefs, final AsNumber remoteAs) {
30         this.timer = Preconditions.checkNotNull(timer);
31         this.initialPrefs = Preconditions.checkNotNull(initialPrefs);
32         this.remoteAs = Preconditions.checkNotNull(remoteAs);
33     }
34
35     @Override
36     public SessionNegotiator<BGPSessionImpl> getSessionNegotiator(final SessionListenerFactory<BGPSessionListener> factory,
37             final Channel channel, final Promise<BGPSessionImpl> promise) {
38         return new BGPSessionNegotiator(this.timer, promise, channel, this.initialPrefs, remoteAs, factory.getSessionListener());
39     }
40 }