2 * Copyright (c) 2014 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.controller.remote.rpc.registry;
10 import akka.actor.ActorRef;
11 import akka.japi.Option;
12 import akka.japi.Pair;
13 import org.opendaylight.controller.remote.rpc.registry.gossip.Copier;
14 import org.opendaylight.controller.sal.connector.api.RpcRouter;
16 import java.io.Serializable;
17 import java.util.Collections;
18 import java.util.HashMap;
21 public class RoutingTable implements Copier<RoutingTable>, Serializable {
23 private Map<RpcRouter.RouteIdentifier<?, ?, ?>, Long> table = new HashMap<>();
24 private ActorRef router;
27 public RoutingTable copy() {
28 RoutingTable copy = new RoutingTable();
29 copy.setTable(Collections.unmodifiableMap(table));
30 copy.setRouter(this.getRouter());
35 public Option<Pair<ActorRef, Long>> getRouterFor(RpcRouter.RouteIdentifier<?, ?, ?> routeId){
36 Long updatedTime = table.get(routeId);
38 if (updatedTime == null || router == null)
41 return Option.option(new Pair<>(router, updatedTime));
44 public void addRoute(RpcRouter.RouteIdentifier<?,?,?> routeId){
45 table.put(routeId, System.currentTimeMillis());
48 public void removeRoute(RpcRouter.RouteIdentifier<?, ?, ?> routeId){
49 table.remove(routeId);
52 public Boolean contains(RpcRouter.RouteIdentifier<?, ?, ?> routeId){
53 return table.containsKey(routeId);
56 public Boolean isEmpty(){
57 return table.isEmpty();
63 public Map<RpcRouter.RouteIdentifier<?, ?, ?>, Long> getTable() {
67 void setTable(Map<RpcRouter.RouteIdentifier<?, ?, ?>, Long> table) {
71 public ActorRef getRouter() {
75 public void setRouter(ActorRef router) {
80 public String toString() {
81 return "RoutingTable{" +
83 ", router=" + router +