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;
14 import org.opendaylight.protocol.bgp.parser.BGPSession;
15 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
16 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
17 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionProposal;
18 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionProposalChecker;
19 import org.opendaylight.protocol.concepts.ListenerRegistration;
20 import org.opendaylight.protocol.framework.ProtocolMessageFactory;
23 * Implementation of {@link BGP}.
25 public class BGPImpl implements BGP, Closeable {
27 * Wrapper class to give listener a close method.
29 public class BGPListenerRegistration implements ListenerRegistration<BGPSessionListener> {
31 private final BGPSessionListener listener;
33 private final BGPSession session;
35 public BGPListenerRegistration(final BGPSessionListener l, final BGPSession session) {
37 this.session = session;
46 public BGPSessionListener getListener() {
51 private final BGPDispatcher dispatcher;
53 private final ProtocolMessageFactory parser;
55 private final InetSocketAddress address;
57 private final BGPSessionProposal proposal;
59 private final BGPSessionProposalChecker checker;
61 public BGPImpl(final BGPDispatcher dispatcher, final ProtocolMessageFactory parser, final InetSocketAddress address,
62 final BGPSessionProposal proposal, final BGPSessionProposalChecker checker) throws IOException {
63 this.dispatcher = dispatcher;
65 this.address = address;
66 this.proposal = proposal;
67 this.checker = checker;
74 public ListenerRegistration<BGPSessionListener> registerUpdateListener(final BGPSessionListener listener) throws IOException {
75 final BGPSession session = this.dispatcher.createClient(
76 new BGPConnectionImpl(this.address, listener, this.proposal.getProposal(), this.checker), this.parser);
77 return new BGPListenerRegistration(listener, session);