Remove unneded RoutingTable time tracking
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / remote / rpc / registry / RoutingTable.java
1 /*
2  * Copyright (c) 2014 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 package org.opendaylight.controller.remote.rpc.registry;
9
10 import akka.actor.ActorRef;
11 import com.google.common.annotations.VisibleForTesting;
12 import com.google.common.base.Preconditions;
13 import com.google.common.collect.ImmutableSet;
14 import java.io.Serializable;
15 import java.util.Collection;
16 import java.util.HashSet;
17 import java.util.Optional;
18 import java.util.Set;
19 import org.opendaylight.controller.remote.rpc.registry.gossip.BucketData;
20 import org.opendaylight.controller.sal.connector.api.RpcRouter.RouteIdentifier;
21
22 public class RoutingTable implements BucketData<RoutingTable>, Serializable {
23     private static final long serialVersionUID = 1L;
24
25     private final Set<RouteIdentifier<?, ?, ?>> rpcs;
26     private final ActorRef rpcInvoker;
27
28     private RoutingTable(final ActorRef rpcInvoker, final Set<RouteIdentifier<?, ?, ?>> table) {
29         this.rpcInvoker = Preconditions.checkNotNull(rpcInvoker);
30         this.rpcs = ImmutableSet.copyOf(table);
31     }
32
33     RoutingTable(final ActorRef rpcInvoker) {
34         this(rpcInvoker, ImmutableSet.of());
35     }
36
37     @Override
38     public Optional<ActorRef> getWatchActor() {
39         return Optional.of(rpcInvoker);
40     }
41
42     public Set<RouteIdentifier<?, ?, ?>> getRoutes() {
43         return rpcs;
44     }
45
46     ActorRef getRpcInvoker() {
47         return rpcInvoker;
48     }
49
50     RoutingTable addRpcs(final Collection<RouteIdentifier<?, ?, ?>> toAdd) {
51         final Set<RouteIdentifier<?, ?, ?>> newRpcs = new HashSet<>(rpcs);
52         newRpcs.addAll(toAdd);
53         return new RoutingTable(rpcInvoker, newRpcs);
54     }
55
56     RoutingTable removeRpcs(final Collection<RouteIdentifier<?, ?, ?>> toRemove) {
57         final Set<RouteIdentifier<?, ?, ?>> newRpcs = new HashSet<>(rpcs);
58         newRpcs.removeAll(toRemove);
59         return new RoutingTable(rpcInvoker, newRpcs);
60     }
61
62     @VisibleForTesting
63     boolean contains(final RouteIdentifier<?, ?, ?> routeId) {
64         return rpcs.contains(routeId);
65     }
66
67     @VisibleForTesting
68     int size() {
69         return rpcs.size();
70     }
71
72     @Override
73     public String toString() {
74         return "RoutingTable{" + "rpcs=" + rpcs + ", rpcInvoker=" + rpcInvoker + '}';
75     }
76 }