BUG-58: refactor to take advantage of netty
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / BGPSessionNegotiatorFactory.java
1 package org.opendaylight.protocol.bgp.rib.impl;
2
3 import io.netty.channel.Channel;
4 import io.netty.util.Timer;
5 import io.netty.util.concurrent.Promise;
6
7 import org.opendaylight.protocol.bgp.parser.BGPMessage;
8 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
9 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
10 import org.opendaylight.protocol.framework.SessionListenerFactory;
11 import org.opendaylight.protocol.framework.SessionNegotiator;
12 import org.opendaylight.protocol.framework.SessionNegotiatorFactory;
13
14 import com.google.common.base.Preconditions;
15
16 public final class BGPSessionNegotiatorFactory implements SessionNegotiatorFactory<BGPMessage, BGPSessionImpl, BGPSessionListener> {
17         private final BGPSessionPreferences initialPrefs;
18         private final Timer timer;
19
20         public BGPSessionNegotiatorFactory(final Timer timer, final BGPSessionPreferences initialPrefs) {
21                 this.timer = Preconditions.checkNotNull(timer);
22                 this.initialPrefs = Preconditions.checkNotNull(initialPrefs);
23         }
24
25         @Override
26         public SessionNegotiator<BGPSessionImpl> getSessionNegotiator(final SessionListenerFactory<BGPSessionListener> factory,
27                         final Channel channel, final Promise<BGPSessionImpl> promise) {
28                 return new BGPSessionNegotiator(timer, promise, channel, initialPrefs, factory.getSessionListener());
29         }
30 }