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
9 package org.opendaylight.controller.sal.connector.remoterpc;
11 import com.google.common.base.Optional;
12 import org.opendaylight.controller.sal.connector.remoterpc.api.RouteChangeListener;
13 import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTable;
14 import org.opendaylight.controller.sal.connector.remoterpc.impl.RoutingTableImpl;
15 import org.osgi.framework.BundleContext;
16 import org.osgi.util.tracker.ServiceTracker;
18 public class RoutingTableProvider implements AutoCloseable {
20 @SuppressWarnings("rawtypes")
21 final ServiceTracker<RoutingTable,RoutingTable> tracker;
23 private RoutingTableImpl routingTableImpl = null;
25 final private RouteChangeListener routeChangeListener;
28 public RoutingTableProvider(BundleContext ctx,RouteChangeListener rcl) {
29 @SuppressWarnings("rawtypes")
30 ServiceTracker<RoutingTable, RoutingTable> rawTracker = new ServiceTracker<>(ctx, RoutingTable.class, null);
34 routeChangeListener = rcl;
37 public Optional<RoutingTable<String, String>> getRoutingTable() {
38 @SuppressWarnings("unchecked")
39 RoutingTable<String,String> tracked = tracker.getService();
41 if(tracked instanceof RoutingTableImpl){
42 if(routingTableImpl != tracked){
43 routingTableImpl= (RoutingTableImpl)tracked;
44 routingTableImpl.setRouteChangeListener(routeChangeListener);
48 return Optional.fromNullable(tracked);
52 public void close() throws Exception {