2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.protocol.bgp.rib.impl;
10 import io.netty.channel.EventLoopGroup;
11 import io.netty.channel.socket.SocketChannel;
12 import io.netty.util.HashedWheelTimer;
13 import io.netty.util.Timer;
14 import io.netty.util.concurrent.Future;
15 import io.netty.util.concurrent.Promise;
16 import org.opendaylight.protocol.bgp.parser.BGPMessageFactory;
17 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
18 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
19 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
20 import org.opendaylight.protocol.framework.AbstractDispatcher;
21 import org.opendaylight.protocol.framework.ReconnectStrategy;
22 import org.opendaylight.protocol.framework.SessionListenerFactory;
24 import java.net.InetSocketAddress;
27 * Implementation of BGPDispatcher.
29 public final class BGPDispatcherImpl extends AbstractDispatcher<BGPSessionImpl, BGPSessionListener> implements BGPDispatcher, AutoCloseable {
30 private final Timer timer = new HashedWheelTimer();
32 private final BGPHandlerFactory hf;
34 public BGPDispatcherImpl(final BGPMessageFactory parser, EventLoopGroup bossGroup, EventLoopGroup workerGroup) {
35 super(bossGroup, workerGroup);
36 this.hf = new BGPHandlerFactory(parser);
40 public Future<BGPSessionImpl> createClient(final InetSocketAddress address, final BGPSessionPreferences preferences,
41 final BGPSessionListener listener, final ReconnectStrategy strategy) {
42 final BGPSessionNegotiatorFactory snf = new BGPSessionNegotiatorFactory(this.timer, preferences);
43 final SessionListenerFactory<BGPSessionListener> slf = new SessionListenerFactory<BGPSessionListener>() {
45 public BGPSessionListener getSessionListener() {
49 return super.createClient(address, strategy, new PipelineInitializer<BGPSessionImpl>() {
51 public void initializeChannel(final SocketChannel ch, final Promise<BGPSessionImpl> promise) {
52 ch.pipeline().addLast(hf.getDecoders());
53 ch.pipeline().addLast("negotiator", snf.getSessionNegotiator(slf, ch, promise));
54 ch.pipeline().addLast(hf.getEncoders());