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 java.io.Serializable;
14 import java.util.HashMap;
16 import org.opendaylight.controller.remote.rpc.registry.gossip.Copier;
17 import org.opendaylight.controller.sal.connector.api.RpcRouter;
19 public class RoutingTable implements Copier<RoutingTable>, Serializable {
20 private static final long serialVersionUID = 5592610415175278760L;
22 private final Map<RpcRouter.RouteIdentifier<?, ?, ?>, Long> table = new HashMap<>();
23 private ActorRef router;
26 public RoutingTable copy() {
27 RoutingTable copy = new RoutingTable();
28 copy.table.putAll(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));
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();
64 public ActorRef getRouter() {
68 public void setRouter(ActorRef router) {
73 public String toString() {
74 return "RoutingTable{" +
76 ", router=" + router +