Assigned bugs to FIXMEs.
[bgpcep.git] / pcep / topology-provider / src / main / java / org / opendaylight / bgpcep / pcep / topology / provider / PCEPTopologyProvider.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.bgpcep.pcep.topology.provider;
9
10 import io.netty.channel.Channel;
11 import io.netty.channel.ChannelFuture;
12
13 import java.net.InetSocketAddress;
14 import java.util.concurrent.ExecutionException;
15
16 import org.opendaylight.bgpcep.programming.spi.InstructionScheduler;
17 import org.opendaylight.bgpcep.topology.DefaultTopologyReference;
18 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
19 import org.opendaylight.protocol.pcep.PCEPDispatcher;
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22
23 import com.google.common.base.Preconditions;
24
25 public final class PCEPTopologyProvider extends DefaultTopologyReference implements AutoCloseable {
26         private final ServerSessionManager manager;
27         private final TopologyProgramming network;
28         private final TopologyRPCs element;
29         private final Channel channel;
30
31         private PCEPTopologyProvider(final Channel channel, final InstanceIdentifier<Topology> topology, final ServerSessionManager manager,
32                         final TopologyRPCs element, final TopologyProgramming network) {
33                 super(topology);
34                 this.channel = Preconditions.checkNotNull(channel);
35                 this.manager = Preconditions.checkNotNull(manager);
36                 this.element = Preconditions.checkNotNull(element);
37                 this.network = Preconditions.checkNotNull(network);
38         }
39
40         public static PCEPTopologyProvider create(final PCEPDispatcher dispatcher, final InetSocketAddress address,
41                         final InstructionScheduler scheduler, final DataProviderService dataService, final InstanceIdentifier<Topology> topology)
42                         throws InterruptedException, ExecutionException {
43
44                 final ServerSessionManager manager = new ServerSessionManager(dataService, topology);
45                 final TopologyRPCs element = new TopologyRPCs(manager);
46                 final TopologyProgramming network = new TopologyProgramming(scheduler, manager);
47                 final ChannelFuture f = dispatcher.createServer(address, manager);
48                 f.get();
49                 return new PCEPTopologyProvider(f.channel(), topology, manager, element, network);
50         }
51
52         @Override
53         public void close() throws Exception {
54                 this.channel.close();
55                 // FIXME: BUG-193: close other stuff
56         }
57 }