Initial framework migration to netty.
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / BGPImpl.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bgp.rib.impl;
9
10 import java.io.Closeable;
11 import java.io.IOException;
12 import java.net.InetSocketAddress;
13
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;
21
22 /**
23  * Implementation of {@link BGP}.
24  */
25 public class BGPImpl implements BGP, Closeable {
26         /**
27          * Wrapper class to give listener a close method.
28          */
29         public class BGPListenerRegistration implements ListenerRegistration<BGPSessionListener> {
30
31                 private final BGPSessionListener listener;
32
33                 private final BGPSession session;
34
35                 public BGPListenerRegistration(final BGPSessionListener l, final BGPSession session) {
36                         this.listener = l;
37                         this.session = session;
38                 }
39
40                 @Override
41                 public void close() {
42                         this.session.close();
43                 }
44
45                 @Override
46                 public BGPSessionListener getListener() {
47                         return this.listener;
48                 }
49         }
50
51         private final BGPDispatcher dispatcher;
52
53         private final ProtocolMessageFactory parser;
54
55         private final InetSocketAddress address;
56
57         private final BGPSessionProposal proposal;
58
59         private final BGPSessionProposalChecker checker;
60
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;
64                 this.parser = parser;
65                 this.address = address;
66                 this.proposal = proposal;
67                 this.checker = checker;
68         }
69
70         /**
71          * {@inheritDoc}
72          */
73         @Override
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);
78         }
79
80         @Override
81         public void close() {
82
83         }
84 }