BUG-58: refactor to take advantage of netty
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / BGPDispatcherImpl.java
index e368b28b9bcd5ef8edcf82fbcd3d891d07c0910d..d6d165fc1520fca1e7a50becc6cc8e4b1641449c 100644 (file)
@@ -7,30 +7,40 @@
  */
 package org.opendaylight.protocol.bgp.rib.impl;
 
+import io.netty.util.HashedWheelTimer;
+import io.netty.util.Timer;
 import io.netty.util.concurrent.Future;
 
+import java.net.InetSocketAddress;
+
+import org.opendaylight.protocol.bgp.parser.BGPMessage;
 import org.opendaylight.protocol.bgp.parser.BGPSession;
-import org.opendaylight.protocol.bgp.rib.impl.spi.BGPConnection;
+import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
+import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
 import org.opendaylight.protocol.framework.Dispatcher;
 import org.opendaylight.protocol.framework.ProtocolMessageFactory;
 import org.opendaylight.protocol.framework.ReconnectStrategy;
 
+import com.google.common.base.Preconditions;
+
 /**
  * Implementation of BGPDispatcher.
  */
 public final class BGPDispatcherImpl implements BGPDispatcher {
-
+       private final Timer timer = new HashedWheelTimer();
+       private final ProtocolMessageFactory<BGPMessage> parser;
        private final Dispatcher dispatcher;
 
-       public BGPDispatcherImpl(final Dispatcher dispatcher) {
-               this.dispatcher = dispatcher;
+       public BGPDispatcherImpl(final Dispatcher dispatcher, final ProtocolMessageFactory<BGPMessage> parser) {
+               this.dispatcher = Preconditions.checkNotNull(dispatcher);
+               this.parser = Preconditions.checkNotNull(parser);
        }
 
        @Override
-       public Future<? extends BGPSession> createClient(final BGPConnection connection, final ProtocolMessageFactory parser,
-                       final ReconnectStrategy strategy) {
-               return this.dispatcher.createClient(connection, new BGPSessionFactory(parser), strategy);
+       public Future<? extends BGPSession> createClient(final InetSocketAddress address, final BGPSessionPreferences preferences,
+                       final BGPSessionListener listener, final ReconnectStrategy strategy) {
+               return this.dispatcher.createClient(address, listener, new BGPSessionNegotiatorFactory(timer, preferences), parser, strategy);
        }
 
        public Dispatcher getDispatcher() {