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 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;
19 import org.opendaylight.controller.remote.rpc.registry.gossip.BucketData;
20 import org.opendaylight.controller.sal.connector.api.RpcRouter.RouteIdentifier;
22 public class RoutingTable implements BucketData<RoutingTable>, Serializable {
23 private static final long serialVersionUID = 1L;
25 private final Set<RouteIdentifier<?, ?, ?>> rpcs;
26 private final ActorRef rpcInvoker;
28 private RoutingTable(final ActorRef rpcInvoker, final Set<RouteIdentifier<?, ?, ?>> table) {
29 this.rpcInvoker = Preconditions.checkNotNull(rpcInvoker);
30 this.rpcs = ImmutableSet.copyOf(table);
33 RoutingTable(final ActorRef rpcInvoker) {
34 this(rpcInvoker, ImmutableSet.of());
38 public Optional<ActorRef> getWatchActor() {
39 return Optional.of(rpcInvoker);
42 public Set<RouteIdentifier<?, ?, ?>> getRoutes() {
46 ActorRef getRpcInvoker() {
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);
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);
63 boolean contains(final RouteIdentifier<?, ?, ?> routeId) {
64 return rpcs.contains(routeId);
73 public String toString() {
74 return "RoutingTable{" + "rpcs=" + rpcs + ", rpcInvoker=" + rpcInvoker + '}';