Re-added config.version to config-module-archetype.
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / implementation / src / main / java / org / opendaylight / controller / sal / connector / remoterpc / RoutingTableProvider.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
9 package org.opendaylight.controller.sal.connector.remoterpc;
10
11 import org.opendaylight.controller.sal.connector.api.RpcRouter;
12 import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTable;
13 import org.opendaylight.controller.sal.connector.remoterpc.impl.RoutingTableImpl;
14 import org.osgi.framework.BundleContext;
15 import org.osgi.util.tracker.ServiceTracker;
16
17 import com.google.common.base.Optional;
18
19 public class RoutingTableProvider implements AutoCloseable {
20
21     @SuppressWarnings("rawtypes")
22     final ServiceTracker<RoutingTable,RoutingTable> tracker;
23
24     private RoutingTableImpl<?, ?> routingTableImpl = null;
25
26     //final private RouteChangeListener routeChangeListener;
27
28
29     public RoutingTableProvider(BundleContext ctx){//,RouteChangeListener rcl) {
30         @SuppressWarnings("rawtypes")
31         ServiceTracker<RoutingTable, RoutingTable> rawTracker = new ServiceTracker<>(ctx, RoutingTable.class, null);
32         tracker = rawTracker;
33         tracker.open();
34
35         //routeChangeListener = rcl;
36     }
37
38     public Optional<RoutingTable<RpcRouter.RouteIdentifier<?, ?, ?>, String>> getRoutingTable() {
39         @SuppressWarnings("unchecked")
40         RoutingTable<RpcRouter.RouteIdentifier<?, ?, ?>, String> tracked = tracker.getService();
41
42         if(tracked instanceof RoutingTableImpl){
43             if(routingTableImpl != tracked){
44              routingTableImpl= (RoutingTableImpl<?, ?>)tracked;
45              //routingTableImpl.setRouteChangeListener(routeChangeListener);
46             }
47         }
48
49         return Optional.fromNullable(tracked);
50     }
51
52     @Override
53     public void close() throws Exception {
54         tracker.close();
55     }
56 }