-
Notifications
You must be signed in to change notification settings - Fork 215
/
ShardRegions.java
101 lines (86 loc) · 3.3 KB
/
ShardRegions.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.concierge.api.actors;
import org.eclipse.ditto.connectivity.api.ConnectivityMessagingConstants;
import org.eclipse.ditto.internal.utils.cluster.ShardRegionProxyActorFactory;
import org.eclipse.ditto.internal.utils.cluster.config.ClusterConfig;
import org.eclipse.ditto.policies.api.PoliciesMessagingConstants;
import org.eclipse.ditto.things.api.ThingsMessagingConstants;
import org.eclipse.ditto.thingsearch.api.ThingsSearchConstants;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
/**
* Create and retrieve shard region proxies.
*/
public final class ShardRegions {
private final ShardRegionProxyActorFactory shardRegionProxyActorFactory;
private final ActorRef policies;
private final ActorRef things;
private final ActorRef connections;
private final ActorRef search;
private ShardRegions(final ShardRegionProxyActorFactory shardRegionProxyActorFactory) {
this.shardRegionProxyActorFactory = shardRegionProxyActorFactory;
policies =
startShardRegionProxy(PoliciesMessagingConstants.CLUSTER_ROLE, PoliciesMessagingConstants.SHARD_REGION);
things = startShardRegionProxy(ThingsMessagingConstants.CLUSTER_ROLE, ThingsMessagingConstants.SHARD_REGION);
connections = startShardRegionProxy(ConnectivityMessagingConstants.CLUSTER_ROLE,
ConnectivityMessagingConstants.SHARD_REGION);
search = startShardRegionProxy(ThingsSearchConstants.SHARD_REGION, ThingsSearchConstants.CLUSTER_ROLE);
}
private ActorRef startShardRegionProxy(final CharSequence clusterRole, final CharSequence shardRegionName) {
return shardRegionProxyActorFactory.getShardRegionProxyActor(clusterRole, shardRegionName);
}
/**
* Create a set of shard region proxies
*
* @param actorSystem the actor system.
* @param clusterConfig the cluster config of the actor system.
* @return a new ShardRegions object.
* @throws NullPointerException if any argument is {@code null}.
*/
public static ShardRegions of(final ActorSystem actorSystem, final ClusterConfig clusterConfig) {
return new ShardRegions(ShardRegionProxyActorFactory.newInstance(actorSystem, clusterConfig));
}
/**
* Return the policies' shard region proxy.
*
* @return policies shard region proxy.
*/
public ActorRef policies() {
return policies;
}
/**
* Return the things' shard region proxy.
*
* @return things shard region proxy.
*/
public ActorRef things() {
return things;
}
/**
* Return the connections' shard region proxy.
*
* @return connections shard region proxy.
*/
public ActorRef connections() {
return connections;
}
/**
* Return the search shard region proxy.
*
* @return search shard region proxy.
*/
public ActorRef search() {
return search;
}
}