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 java.io.Closeable;
11 import java.io.IOException;
12 import java.net.InetSocketAddress;
13 import java.util.concurrent.ExecutionException;
15 import org.opendaylight.protocol.bgp.parser.BGPSession;
16 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
17 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
18 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionProposal;
19 import org.opendaylight.protocol.concepts.ListenerRegistration;
20 import org.opendaylight.protocol.framework.ReconnectStrategy;
22 import com.google.common.base.Preconditions;
25 * Implementation of {@link BGP}.
27 public class BGPImpl implements BGP, Closeable {
29 * Wrapper class to give listener a close method.
31 public class BGPListenerRegistration extends ListenerRegistration<BGPSessionListener> {
32 private final BGPSession session;
34 public BGPListenerRegistration(final BGPSessionListener l, final BGPSession session) {
36 this.session = session;
40 public void removeRegistration() {
45 private final BGPDispatcher dispatcher;
47 private final InetSocketAddress address;
49 private final BGPSessionProposal proposal;
51 public BGPImpl(final BGPDispatcher dispatcher, final InetSocketAddress address, final BGPSessionProposal proposal) {
52 this.dispatcher = Preconditions.checkNotNull(dispatcher);
53 this.address = Preconditions.checkNotNull(address);
54 this.proposal = Preconditions.checkNotNull(proposal);
61 public BGPListenerRegistration registerUpdateListener(final BGPSessionListener listener, final ReconnectStrategy strategy) throws IOException {
62 final BGPSession session;
64 session = this.dispatcher.createClient(this.address, this.proposal.getProposal(), listener, strategy).get();
65 } catch (InterruptedException | ExecutionException e) {
66 throw new IOException("Failed to connect to peer", e);
68 return new BGPListenerRegistration(listener, session);