Deprecate DOMDataTreeProducer-related classes
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / sharding / ShardingServiceAddressResolver.java
1 /*
2  * Copyright (c) 2016 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.cluster.sharding;
9
10 import static com.google.common.base.Preconditions.checkNotNull;
11 import static java.util.Objects.requireNonNull;
12
13 import akka.actor.Address;
14 import java.util.Collection;
15 import java.util.concurrent.ConcurrentHashMap;
16 import java.util.concurrent.ConcurrentMap;
17 import java.util.stream.Collectors;
18 import org.opendaylight.controller.cluster.access.concepts.MemberName;
19
20 /**
21  * Resolver for remote {@link ShardedDataTreeActor}'s.
22  */
23 @Deprecated(forRemoval = true)
24 public class ShardingServiceAddressResolver {
25
26     private final ConcurrentMap<MemberName, Address> memberNameToAddress = new ConcurrentHashMap<>();
27     private final String shardingServiceActorIdentifier;
28     private final MemberName localMemberName;
29
30     public ShardingServiceAddressResolver(final String shardingServiceActorIdentifier,
31                                           final MemberName localMemberName) {
32         this.shardingServiceActorIdentifier = shardingServiceActorIdentifier;
33         this.localMemberName = localMemberName;
34     }
35
36     void addPeerAddress(final MemberName memberName, final Address address) {
37         memberNameToAddress.put(memberName, address);
38     }
39
40     void removePeerAddress(final MemberName memberName) {
41         memberNameToAddress.remove(memberName);
42     }
43
44     Address getPeerAddress(final MemberName memberName) {
45         return memberNameToAddress.get(memberName);
46     }
47
48     StringBuilder getActorPathBuilder(final Address address) {
49         return new StringBuilder().append(address.toString()).append("/user/").append(shardingServiceActorIdentifier);
50     }
51
52     Collection<String> getShardingServicePeerActorAddresses() {
53         final Collection<String> peerAddresses =
54                 memberNameToAddress
55                         .entrySet()
56                         .stream()
57                         .filter(entry -> !localMemberName.equals(entry.getKey()))
58                         .map(entry -> getActorPathBuilder(entry.getValue()).toString())
59                         .collect(Collectors.toList());
60
61         return peerAddresses;
62     }
63
64     public String resolve(final MemberName memberName) {
65         final Address address = memberNameToAddress.get(requireNonNull(memberName));
66         checkNotNull(address, "Requested member[%s] is not present in the resolver", memberName);
67         return getActorPathBuilder(address).toString();
68     }
69 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.