BUG-58: refactor to take advantage of netty
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / BGPDispatcherImpl.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 io.netty.util.HashedWheelTimer;
11 import io.netty.util.Timer;
12 import io.netty.util.concurrent.Future;
13
14 import java.net.InetSocketAddress;
15
16 import org.opendaylight.protocol.bgp.parser.BGPMessage;
17 import org.opendaylight.protocol.bgp.parser.BGPSession;
18 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
19 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
20 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
21 import org.opendaylight.protocol.framework.Dispatcher;
22 import org.opendaylight.protocol.framework.ProtocolMessageFactory;
23 import org.opendaylight.protocol.framework.ReconnectStrategy;
24
25 import com.google.common.base.Preconditions;
26
27 /**
28  * Implementation of BGPDispatcher.
29  */
30 public final class BGPDispatcherImpl implements BGPDispatcher {
31         private final Timer timer = new HashedWheelTimer();
32         private final ProtocolMessageFactory<BGPMessage> parser;
33         private final Dispatcher dispatcher;
34
35         public BGPDispatcherImpl(final Dispatcher dispatcher, final ProtocolMessageFactory<BGPMessage> parser) {
36                 this.dispatcher = Preconditions.checkNotNull(dispatcher);
37                 this.parser = Preconditions.checkNotNull(parser);
38         }
39
40         @Override
41         public Future<? extends BGPSession> createClient(final InetSocketAddress address, final BGPSessionPreferences preferences,
42                         final BGPSessionListener listener, final ReconnectStrategy strategy) {
43                 return this.dispatcher.createClient(address, listener, new BGPSessionNegotiatorFactory(timer, preferences), parser, strategy);
44         }
45
46         public Dispatcher getDispatcher() {
47                 return this.dispatcher;
48         }
49 }