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.socket.SocketChannel;
11 import io.netty.util.HashedWheelTimer;
12 import io.netty.util.Timer;
13 import io.netty.util.concurrent.Future;
14 import io.netty.util.concurrent.Promise;
16 import java.net.InetSocketAddress;
18 import org.opendaylight.protocol.bgp.parser.BGPMessageFactory;
19 import org.opendaylight.protocol.bgp.parser.BGPSession;
20 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
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.SessionListenerFactory;
28 * Implementation of BGPDispatcher.
30 public final class BGPDispatcherImpl extends AbstractDispatcher<BGPSessionImpl, BGPSessionListener> implements BGPDispatcher {
31 private final Timer timer = new HashedWheelTimer();
33 private BGPSessionNegotiatorFactory snf;
35 private final BGPHandlerFactory hf;
37 public BGPDispatcherImpl(final BGPMessageFactory parser) {
39 this.hf = new BGPHandlerFactory(parser);
43 public Future<? extends BGPSession> createClient(final InetSocketAddress address, final BGPSessionPreferences preferences,
44 final BGPSessionListener listener, final ReconnectStrategy strategy) {
45 this.snf = new BGPSessionNegotiatorFactory(this.timer, preferences);
46 final SessionListenerFactory<BGPSessionListener> slf = new SessionListenerFactory<BGPSessionListener>() {
49 public BGPSessionListener getSessionListener() {
53 return super.createClient(address, strategy, slf);
57 public void initializeChannel(final SocketChannel ch, final Promise<BGPSessionImpl> promise,
58 final SessionListenerFactory<BGPSessionListener> slf) {
59 ch.pipeline().addLast(this.hf.getDecoders());
60 ch.pipeline().addLast("negotiator", this.snf.getSessionNegotiator(slf, ch, promise));
61 ch.pipeline().addLast(this.hf.getEncoders());