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;
17 import java.net.InetSocketAddress;
19 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
20 import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
21 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
22 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
23 import org.opendaylight.protocol.framework.AbstractDispatcher;
24 import org.opendaylight.protocol.framework.ReconnectStrategy;
25 import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
26 import org.opendaylight.protocol.framework.SessionListenerFactory;
29 * Implementation of BGPDispatcher.
31 public final class BGPDispatcherImpl extends AbstractDispatcher<BGPSessionImpl, BGPSessionListener> implements BGPDispatcher, AutoCloseable {
32 private final Timer timer = new HashedWheelTimer();
34 private final BGPHandlerFactory hf;
36 public BGPDispatcherImpl(final MessageRegistry messageRegistry, final EventLoopGroup bossGroup, final EventLoopGroup workerGroup) {
37 super(bossGroup, workerGroup);
38 this.hf = new BGPHandlerFactory(messageRegistry);
42 public Future<BGPSessionImpl> createClient(final InetSocketAddress address, final BGPSessionPreferences preferences,
43 final BGPSessionListener listener, final ReconnectStrategy strategy) {
44 final BGPSessionNegotiatorFactory snf = new BGPSessionNegotiatorFactory(this.timer, preferences);
45 final SessionListenerFactory<BGPSessionListener> slf = new SessionListenerFactory<BGPSessionListener>() {
47 public BGPSessionListener getSessionListener() {
51 return super.createClient(address, strategy, new PipelineInitializer<BGPSessionImpl>() {
53 public void initializeChannel(final SocketChannel ch, final Promise<BGPSessionImpl> promise) {
54 ch.pipeline().addLast(hf.getDecoders());
55 ch.pipeline().addLast("negotiator", snf.getSessionNegotiator(slf, ch, promise));
56 ch.pipeline().addLast(hf.getEncoders());
62 public Future<Void> createReconnectingClient(final InetSocketAddress address,
63 final BGPSessionPreferences preferences, final BGPSessionListener listener,
64 final ReconnectStrategyFactory connectStrategyFactory,
65 final ReconnectStrategy reestablishStrategy) {
66 final BGPSessionNegotiatorFactory snf = new BGPSessionNegotiatorFactory(this.timer, preferences);
67 final SessionListenerFactory<BGPSessionListener> slf = new SessionListenerFactory<BGPSessionListener>() {
69 public BGPSessionListener getSessionListener() {
74 return super.createReconnectingClient(address, connectStrategyFactory, reestablishStrategy, new PipelineInitializer<BGPSessionImpl>() {
76 public void initializeChannel(final SocketChannel ch, final Promise<BGPSessionImpl> promise) {
77 ch.pipeline().addLast(hf.getDecoders());
78 ch.pipeline().addLast("negotiator", snf.getSessionNegotiator(slf, ch, promise));
79 ch.pipeline().addLast(hf.getEncoders());