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.HashMap;
20 public class RoutingTable implements Copier<RoutingTable>, Serializable {
22 private Map<RpcRouter.RouteIdentifier<?, ?, ?>, Long> table = new HashMap<>();
23 private ActorRef router;
26 public RoutingTable copy() {
27 RoutingTable copy = new RoutingTable();
28 copy.setTable(new HashMap<>(table));
29 copy.setRouter(this.getRouter());
34 public Option<Pair<ActorRef, Long>> getRouterFor(RpcRouter.RouteIdentifier<?, ?, ?> routeId){
35 Long updatedTime = table.get(routeId);
37 if (updatedTime == null || router == null)
40 return Option.option(new Pair<>(router, updatedTime));
43 public void addRoute(RpcRouter.RouteIdentifier<?,?,?> routeId){
44 table.put(routeId, System.currentTimeMillis());
47 public void removeRoute(RpcRouter.RouteIdentifier<?, ?, ?> routeId){
48 table.remove(routeId);
51 public Boolean contains(RpcRouter.RouteIdentifier<?, ?, ?> routeId){
52 return table.containsKey(routeId);
55 public Boolean isEmpty(){
56 return table.isEmpty();
62 public Map<RpcRouter.RouteIdentifier<?, ?, ?>, Long> getTable() {
66 void setTable(Map<RpcRouter.RouteIdentifier<?, ?, ?>, Long> table) {
70 public ActorRef getRouter() {
74 public void setRouter(ActorRef router) {
79 public String toString() {
80 return "RoutingTable{" +
82 ", router=" + router +