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
9 package org.opendaylight.controller.cluster.datastore;
11 import akka.actor.ActorPath;
12 import akka.actor.ActorRef;
13 import akka.actor.Address;
14 import akka.actor.Cancellable;
15 import akka.actor.OneForOneStrategy;
16 import akka.actor.Props;
17 import akka.actor.SupervisorStrategy;
18 import akka.cluster.ClusterEvent;
19 import akka.japi.Creator;
20 import akka.japi.Function;
21 import akka.japi.Procedure;
22 import akka.persistence.RecoveryCompleted;
23 import akka.persistence.RecoveryFailure;
24 import akka.serialization.Serialization;
25 import com.google.common.annotations.VisibleForTesting;
26 import com.google.common.base.Objects;
27 import com.google.common.base.Preconditions;
28 import com.google.common.base.Strings;
29 import com.google.common.base.Supplier;
30 import com.google.common.collect.ImmutableSet;
31 import com.google.common.collect.Sets;
32 import java.io.Serializable;
33 import java.util.ArrayList;
34 import java.util.Collection;
35 import java.util.Collections;
36 import java.util.HashMap;
37 import java.util.HashSet;
38 import java.util.Iterator;
39 import java.util.List;
42 import java.util.concurrent.CountDownLatch;
43 import org.opendaylight.controller.cluster.DataPersistenceProvider;
44 import org.opendaylight.controller.cluster.common.actor.AbstractUntypedPersistentActorWithMetering;
45 import org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException;
46 import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier;
47 import org.opendaylight.controller.cluster.datastore.identifiers.ShardManagerIdentifier;
48 import org.opendaylight.controller.cluster.datastore.jmx.mbeans.shardmanager.ShardManagerInfo;
49 import org.opendaylight.controller.cluster.datastore.jmx.mbeans.shardmanager.ShardManagerInfoMBean;
50 import org.opendaylight.controller.cluster.datastore.messages.ActorInitialized;
51 import org.opendaylight.controller.cluster.datastore.messages.ActorNotInitialized;
52 import org.opendaylight.controller.cluster.datastore.messages.FindLocalShard;
53 import org.opendaylight.controller.cluster.datastore.messages.FindPrimary;
54 import org.opendaylight.controller.cluster.datastore.messages.LocalShardFound;
55 import org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound;
56 import org.opendaylight.controller.cluster.datastore.messages.PeerAddressResolved;
57 import org.opendaylight.controller.cluster.datastore.messages.PrimaryFound;
58 import org.opendaylight.controller.cluster.datastore.messages.PrimaryNotFound;
59 import org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext;
60 import org.opendaylight.controller.cluster.datastore.utils.Dispatchers;
61 import org.opendaylight.controller.cluster.notifications.LeaderStateChanged;
62 import org.opendaylight.controller.cluster.notifications.RegisterRoleChangeListener;
63 import org.opendaylight.controller.cluster.notifications.RoleChangeNotification;
64 import org.opendaylight.controller.cluster.raft.RaftState;
65 import org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus;
66 import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
67 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
68 import org.slf4j.Logger;
69 import org.slf4j.LoggerFactory;
70 import scala.concurrent.duration.Duration;
73 * The ShardManager has the following jobs,
75 * <li> Create all the local shard replicas that belong on this cluster member
76 * <li> Find the address of the local shard
77 * <li> Find the primary replica for any given shard
78 * <li> Monitor the cluster members and store their addresses
81 public class ShardManager extends AbstractUntypedPersistentActorWithMetering {
83 private static final Logger LOG = LoggerFactory.getLogger(ShardManager.class);
85 // Stores a mapping between a member name and the address of the member
86 // Member names look like "member-1", "member-2" etc and are as specified
88 private final Map<String, Address> memberNameToAddress = new HashMap<>();
90 // Stores a mapping between a shard name and it's corresponding information
91 // Shard names look like inventory, topology etc and are as specified in
93 private final Map<String, ShardInformation> localShards = new HashMap<>();
95 // The type of a ShardManager reflects the type of the datastore itself
96 // A data store could be of type config/operational
97 private final String type;
99 private final ClusterWrapper cluster;
101 private final Configuration configuration;
103 private final String shardDispatcherPath;
105 private ShardManagerInfo mBean;
107 private DatastoreContext datastoreContext;
109 private Collection<String> knownModules = Collections.emptySet();
111 private final DataPersistenceProvider dataPersistenceProvider;
113 private final CountDownLatch waitTillReadyCountdownLatch;
117 protected ShardManager(ClusterWrapper cluster, Configuration configuration,
118 DatastoreContext datastoreContext, CountDownLatch waitTillReadyCountdownLatch) {
120 this.cluster = Preconditions.checkNotNull(cluster, "cluster should not be null");
121 this.configuration = Preconditions.checkNotNull(configuration, "configuration should not be null");
122 this.datastoreContext = datastoreContext;
123 this.dataPersistenceProvider = createDataPersistenceProvider(datastoreContext.isPersistent());
124 this.type = datastoreContext.getDataStoreType();
125 this.shardDispatcherPath =
126 new Dispatchers(context().system().dispatchers()).getDispatcherPath(Dispatchers.DispatcherType.Shard);
127 this.waitTillReadyCountdownLatch = waitTillReadyCountdownLatch;
129 // Subscribe this actor to cluster member events
130 cluster.subscribeToMemberEvents(getSelf());
135 protected DataPersistenceProvider createDataPersistenceProvider(boolean persistent) {
136 return (persistent) ? new PersistentDataProvider() : new NonPersistentDataProvider();
139 public static Props props(
140 final ClusterWrapper cluster,
141 final Configuration configuration,
142 final DatastoreContext datastoreContext,
143 final CountDownLatch waitTillReadyCountdownLatch) {
145 Preconditions.checkNotNull(cluster, "cluster should not be null");
146 Preconditions.checkNotNull(configuration, "configuration should not be null");
147 Preconditions.checkNotNull(waitTillReadyCountdownLatch, "waitTillReadyCountdownLatch should not be null");
149 return Props.create(new ShardManagerCreator(cluster, configuration, datastoreContext, waitTillReadyCountdownLatch));
153 public void postStop() {
154 LOG.info("Stopping ShardManager");
156 mBean.unregisterMBean();
160 public void handleCommand(Object message) throws Exception {
161 if (FindPrimary.SERIALIZABLE_CLASS.isInstance(message)) {
162 findPrimary(FindPrimary.fromSerializable(message));
163 } else if(message instanceof FindLocalShard){
164 findLocalShard((FindLocalShard) message);
165 } else if (message instanceof UpdateSchemaContext) {
166 updateSchemaContext(message);
167 } else if(message instanceof ActorInitialized) {
168 onActorInitialized(message);
169 } else if (message instanceof ClusterEvent.MemberUp){
170 memberUp((ClusterEvent.MemberUp) message);
171 } else if(message instanceof ClusterEvent.MemberRemoved) {
172 memberRemoved((ClusterEvent.MemberRemoved) message);
173 } else if(message instanceof ClusterEvent.UnreachableMember) {
174 ignoreMessage(message);
175 } else if(message instanceof DatastoreContext) {
176 onDatastoreContext((DatastoreContext)message);
177 } else if(message instanceof RoleChangeNotification) {
178 onRoleChangeNotification((RoleChangeNotification) message);
179 } else if(message instanceof FollowerInitialSyncUpStatus){
180 onFollowerInitialSyncStatus((FollowerInitialSyncUpStatus) message);
181 } else if(message instanceof ShardNotInitializedTimeout) {
182 onShardNotInitializedTimeout((ShardNotInitializedTimeout)message);
183 } else if(message instanceof LeaderStateChanged) {
184 onLeaderStateChanged((LeaderStateChanged)message);
186 unknownMessage(message);
191 private void onLeaderStateChanged(LeaderStateChanged leaderStateChanged) {
192 LOG.info("{}: Received LeaderStateChanged message: {}", persistenceId(), leaderStateChanged);
194 ShardInformation shardInformation = findShardInformation(leaderStateChanged.getMemberId());
195 if(shardInformation != null) {
196 shardInformation.setLeaderId(leaderStateChanged.getLeaderId());
198 LOG.debug("No shard found with member Id {}", leaderStateChanged.getMemberId());
202 private void onShardNotInitializedTimeout(ShardNotInitializedTimeout message) {
203 ShardInformation shardInfo = message.getShardInfo();
205 LOG.debug("{}: Received ShardNotInitializedTimeout message for shard {}", persistenceId(),
206 shardInfo.getShardId());
208 shardInfo.removeOnShardInitialized(message.getOnShardInitialized());
210 if(!shardInfo.isShardInitialized()) {
211 message.getSender().tell(new ActorNotInitialized(), getSelf());
213 message.getSender().tell(createNoShardLeaderException(shardInfo.shardId), getSelf());
217 private void onFollowerInitialSyncStatus(FollowerInitialSyncUpStatus status) {
218 LOG.info("{} Received follower initial sync status for {} status sync done {}", persistenceId(),
219 status.getName(), status.isInitialSyncDone());
221 ShardInformation shardInformation = findShardInformation(status.getName());
223 if(shardInformation != null) {
224 shardInformation.setFollowerSyncStatus(status.isInitialSyncDone());
226 mBean.setSyncStatus(isInSync());
231 private void onRoleChangeNotification(RoleChangeNotification roleChanged) {
232 LOG.info("{}: Received role changed for {} from {} to {}", persistenceId(), roleChanged.getMemberId(),
233 roleChanged.getOldRole(), roleChanged.getNewRole());
235 ShardInformation shardInformation = findShardInformation(roleChanged.getMemberId());
236 if(shardInformation != null) {
237 shardInformation.setRole(roleChanged.getNewRole());
240 LOG.info("{}: All Shards are ready - data store {} is ready, available count is {}",
241 persistenceId(), type, waitTillReadyCountdownLatch.getCount());
243 waitTillReadyCountdownLatch.countDown();
246 mBean.setSyncStatus(isInSync());
251 private ShardInformation findShardInformation(String memberId) {
252 for(ShardInformation info : localShards.values()){
253 if(info.getShardId().toString().equals(memberId)){
261 private boolean isReady() {
262 boolean isReady = true;
263 for (ShardInformation info : localShards.values()) {
264 if(!info.isShardReady()){
272 private boolean isInSync(){
273 for (ShardInformation info : localShards.values()) {
274 if(!info.isInSync()){
281 private void onActorInitialized(Object message) {
282 final ActorRef sender = getSender();
284 if (sender == null) {
285 return; //why is a non-actor sending this message? Just ignore.
288 String actorName = sender.path().name();
289 //find shard name from actor name; actor name is stringified shardId
290 ShardIdentifier shardId = ShardIdentifier.builder().fromShardIdString(actorName).build();
292 if (shardId.getShardName() == null) {
296 markShardAsInitialized(shardId.getShardName());
299 private void markShardAsInitialized(String shardName) {
300 LOG.debug("Initializing shard [{}]", shardName);
302 ShardInformation shardInformation = localShards.get(shardName);
303 if (shardInformation != null) {
304 shardInformation.setActorInitialized();
306 shardInformation.getActor().tell(new RegisterRoleChangeListener(), self());
311 protected void handleRecover(Object message) throws Exception {
312 if(dataPersistenceProvider.isRecoveryApplicable()) {
313 if (message instanceof SchemaContextModules) {
314 SchemaContextModules msg = (SchemaContextModules) message;
315 knownModules = ImmutableSet.copyOf(msg.getModules());
316 } else if (message instanceof RecoveryFailure) {
317 RecoveryFailure failure = (RecoveryFailure) message;
318 LOG.error("Recovery failed", failure.cause());
319 } else if (message instanceof RecoveryCompleted) {
320 LOG.info("Recovery complete : {}", persistenceId());
322 // Delete all the messages from the akka journal except the last one
323 deleteMessages(lastSequenceNr() - 1);
326 if (message instanceof RecoveryCompleted) {
327 LOG.info("Recovery complete : {}", persistenceId());
329 // Delete all the messages from the akka journal
330 deleteMessages(lastSequenceNr());
335 private void findLocalShard(FindLocalShard message) {
336 final ShardInformation shardInformation = localShards.get(message.getShardName());
338 if(shardInformation == null){
339 getSender().tell(new LocalShardNotFound(message.getShardName()), getSelf());
343 sendResponse(shardInformation, message.isWaitUntilInitialized(), false, new Supplier<Object>() {
345 public Object get() {
346 return new LocalShardFound(shardInformation.getActor());
351 private void sendResponse(ShardInformation shardInformation, boolean doWait,
352 boolean wantShardReady, final Supplier<Object> messageSupplier) {
353 if (!shardInformation.isShardInitialized() || (wantShardReady && !shardInformation.isShardReadyWithLeaderId())) {
355 final ActorRef sender = getSender();
356 final ActorRef self = self();
358 Runnable replyRunnable = new Runnable() {
361 sender.tell(messageSupplier.get(), self);
365 OnShardInitialized onShardInitialized = wantShardReady ? new OnShardReady(replyRunnable) :
366 new OnShardInitialized(replyRunnable);
368 shardInformation.addOnShardInitialized(onShardInitialized);
370 Cancellable timeoutSchedule = getContext().system().scheduler().scheduleOnce(
371 datastoreContext.getShardInitializationTimeout().duration(), getSelf(),
372 new ShardNotInitializedTimeout(shardInformation, onShardInitialized, sender),
373 getContext().dispatcher(), getSelf());
375 onShardInitialized.setTimeoutSchedule(timeoutSchedule);
377 } else if (!shardInformation.isShardInitialized()) {
378 getSender().tell(new ActorNotInitialized(), getSelf());
380 getSender().tell(createNoShardLeaderException(shardInformation.shardId), getSelf());
386 getSender().tell(messageSupplier.get(), getSelf());
389 private NoShardLeaderException createNoShardLeaderException(ShardIdentifier shardId) {
390 return new NoShardLeaderException(String.format(
391 "Could not find a leader for shard %s. This typically happens when the system is coming up or " +
392 "recovering and a leader is being elected. Try again later.", shardId));
395 private void memberRemoved(ClusterEvent.MemberRemoved message) {
396 memberNameToAddress.remove(message.member().roles().head());
399 private void memberUp(ClusterEvent.MemberUp message) {
400 String memberName = message.member().roles().head();
402 memberNameToAddress.put(memberName, message.member().address());
404 for(ShardInformation info : localShards.values()){
405 String shardName = info.getShardName();
406 info.updatePeerAddress(getShardIdentifier(memberName, shardName).toString(),
407 getShardActorPath(shardName, memberName), getSelf());
411 private void onDatastoreContext(DatastoreContext context) {
412 datastoreContext = context;
413 for (ShardInformation info : localShards.values()) {
414 if (info.getActor() != null) {
415 info.getActor().tell(datastoreContext, getSelf());
421 * Notifies all the local shards of a change in the schema context
425 private void updateSchemaContext(final Object message) {
426 final SchemaContext schemaContext = ((UpdateSchemaContext) message).getSchemaContext();
428 Set<ModuleIdentifier> allModuleIdentifiers = schemaContext.getAllModuleIdentifiers();
429 Set<String> newModules = new HashSet<>(128);
431 for(ModuleIdentifier moduleIdentifier : allModuleIdentifiers){
432 String s = moduleIdentifier.getNamespace().toString();
436 if(newModules.containsAll(knownModules)) {
438 LOG.debug("New SchemaContext has a super set of current knownModules - persisting info");
440 knownModules = ImmutableSet.copyOf(newModules);
442 dataPersistenceProvider.persist(new SchemaContextModules(newModules), new Procedure<SchemaContextModules>() {
445 public void apply(SchemaContextModules param) throws Exception {
446 LOG.debug("Sending new SchemaContext to Shards");
447 for (ShardInformation info : localShards.values()) {
448 if (info.getActor() == null) {
449 info.setActor(newShardActor(schemaContext, info));
451 info.getActor().tell(message, getSelf());
458 LOG.debug("Rejecting schema context update - not a super set of previously known modules:\nUPDATE: {}\nKNOWN: {}",
459 newModules, knownModules);
465 protected ActorRef newShardActor(final SchemaContext schemaContext, ShardInformation info) {
466 return getContext().actorOf(Shard.props(info.getShardId(),
467 info.getPeerAddresses(), datastoreContext, schemaContext)
468 .withDispatcher(shardDispatcherPath), info.getShardId().toString());
471 private void findPrimary(FindPrimary message) {
472 final String shardName = message.getShardName();
474 // First see if the there is a local replica for the shard
475 final ShardInformation info = localShards.get(shardName);
477 sendResponse(info, message.isWaitUntilReady(), true, new Supplier<Object>() {
479 public Object get() {
480 Object found = new PrimaryFound(info.getSerializedLeaderActor()).toSerializable();
482 if(LOG.isDebugEnabled()) {
483 LOG.debug("{}: Found primary for {}: {}", shardName, found);
493 List<String> members = configuration.getMembersFromShardName(shardName);
495 if(cluster.getCurrentMemberName() != null) {
496 members.remove(cluster.getCurrentMemberName());
500 * FIXME: Instead of sending remote shard actor path back to sender,
501 * forward FindPrimary message to remote shard manager
503 // There is no way for us to figure out the primary (for now) so assume
504 // that one of the remote nodes is a primary
505 for(String memberName : members) {
506 Address address = memberNameToAddress.get(memberName);
509 getShardActorPath(shardName, memberName);
510 getSender().tell(new PrimaryFound(path).toSerializable(), getSelf());
514 getSender().tell(new PrimaryNotFound(shardName).toSerializable(), getSelf());
517 private String getShardActorPath(String shardName, String memberName) {
518 Address address = memberNameToAddress.get(memberName);
519 if(address != null) {
520 StringBuilder builder = new StringBuilder();
521 builder.append(address.toString())
523 .append(ShardManagerIdentifier.builder().type(type).build().toString())
525 .append(getShardIdentifier(memberName, shardName));
526 return builder.toString();
532 * Construct the name of the shard actor given the name of the member on
533 * which the shard resides and the name of the shard
539 private ShardIdentifier getShardIdentifier(String memberName, String shardName){
540 return ShardIdentifier.builder().memberName(memberName).shardName(shardName).type(type).build();
544 * Create shards that are local to the member on which the ShardManager
548 private void createLocalShards() {
549 String memberName = this.cluster.getCurrentMemberName();
550 List<String> memberShardNames =
551 this.configuration.getMemberShardNames(memberName);
553 List<String> localShardActorNames = new ArrayList<>();
554 for(String shardName : memberShardNames){
555 ShardIdentifier shardId = getShardIdentifier(memberName, shardName);
556 Map<String, String> peerAddresses = getPeerAddresses(shardName);
557 localShardActorNames.add(shardId.toString());
558 localShards.put(shardName, new ShardInformation(shardName, shardId, peerAddresses));
561 mBean = ShardManagerInfo.createShardManagerMBean("shard-manager-" + this.type,
562 datastoreContext.getDataStoreMXBeanType(), localShardActorNames);
566 * Given the name of the shard find the addresses of all it's peers
571 private Map<String, String> getPeerAddresses(String shardName){
573 Map<String, String> peerAddresses = new HashMap<>();
575 List<String> members = this.configuration.getMembersFromShardName(shardName);
577 String currentMemberName = this.cluster.getCurrentMemberName();
579 for(String memberName : members){
580 if(!currentMemberName.equals(memberName)){
581 ShardIdentifier shardId = getShardIdentifier(memberName, shardName);
582 String path = getShardActorPath(shardName, currentMemberName);
583 peerAddresses.put(shardId.toString(), path);
586 return peerAddresses;
590 public SupervisorStrategy supervisorStrategy() {
592 return new OneForOneStrategy(10, Duration.create("1 minute"),
593 new Function<Throwable, SupervisorStrategy.Directive>() {
595 public SupervisorStrategy.Directive apply(Throwable t) {
596 LOG.warn("Supervisor Strategy caught unexpected exception - resuming", t);
597 return SupervisorStrategy.resume();
605 public String persistenceId() {
606 return "shard-manager-" + type;
610 Collection<String> getKnownModules() {
615 DataPersistenceProvider getDataPersistenceProvider() {
616 return dataPersistenceProvider;
620 ShardManagerInfoMBean getMBean(){
625 protected static class ShardInformation {
626 private final ShardIdentifier shardId;
627 private final String shardName;
628 private ActorRef actor;
629 private ActorPath actorPath;
630 private final Map<String, String> peerAddresses;
632 // flag that determines if the actor is ready for business
633 private boolean actorInitialized = false;
635 private boolean followerSyncStatus = false;
637 private final Set<OnShardInitialized> onShardInitializedSet = Sets.newHashSet();
638 private String role ;
639 private String leaderId;
641 private ShardInformation(String shardName, ShardIdentifier shardId,
642 Map<String, String> peerAddresses) {
643 this.shardName = shardName;
644 this.shardId = shardId;
645 this.peerAddresses = peerAddresses;
648 String getShardName() {
656 ActorPath getActorPath() {
660 void setActor(ActorRef actor) {
662 this.actorPath = actor.path();
665 ShardIdentifier getShardId() {
669 Map<String, String> getPeerAddresses() {
670 return peerAddresses;
673 void updatePeerAddress(String peerId, String peerAddress, ActorRef sender){
674 LOG.info("updatePeerAddress for peer {} with address {}", peerId,
676 if(peerAddresses.containsKey(peerId)){
677 peerAddresses.put(peerId, peerAddress);
680 if(LOG.isDebugEnabled()) {
681 LOG.debug("Sending PeerAddressResolved for peer {} with address {} to {}",
682 peerId, peerAddress, actor.path());
685 actor.tell(new PeerAddressResolved(peerId.toString(), peerAddress), sender);
688 notifyOnShardInitializedCallbacks();
692 boolean isShardReady() {
693 return !RaftState.Candidate.name().equals(role) && !Strings.isNullOrEmpty(role);
696 boolean isShardReadyWithLeaderId() {
697 return isShardReady() && (isLeader() || peerAddresses.containsKey(leaderId));
700 boolean isShardInitialized() {
701 return getActor() != null && actorInitialized;
705 return Objects.equal(leaderId, shardId.toString());
708 String getSerializedLeaderActor() {
710 return Serialization.serializedActorPath(getActor());
712 return peerAddresses.get(leaderId);
716 void setActorInitialized() {
717 LOG.debug("Shard {} is initialized", shardId);
719 this.actorInitialized = true;
721 notifyOnShardInitializedCallbacks();
724 private void notifyOnShardInitializedCallbacks() {
725 if(onShardInitializedSet.isEmpty()) {
729 boolean ready = isShardReadyWithLeaderId();
731 if(LOG.isDebugEnabled()) {
732 LOG.debug("Shard {} is {} - notifying {} OnShardInitialized callbacks", shardId,
733 ready ? "ready" : "initialized", onShardInitializedSet.size());
736 Iterator<OnShardInitialized> iter = onShardInitializedSet.iterator();
737 while(iter.hasNext()) {
738 OnShardInitialized onShardInitialized = iter.next();
739 if(!(onShardInitialized instanceof OnShardReady) || ready) {
741 onShardInitialized.getTimeoutSchedule().cancel();
742 onShardInitialized.getReplyRunnable().run();
747 void addOnShardInitialized(OnShardInitialized onShardInitialized) {
748 onShardInitializedSet.add(onShardInitialized);
751 void removeOnShardInitialized(OnShardInitialized onShardInitialized) {
752 onShardInitializedSet.remove(onShardInitialized);
755 void setRole(String newRole) {
758 notifyOnShardInitializedCallbacks();
761 void setFollowerSyncStatus(boolean syncStatus){
762 this.followerSyncStatus = syncStatus;
766 if(RaftState.Follower.name().equals(this.role)){
767 return followerSyncStatus;
768 } else if(RaftState.Leader.name().equals(this.role)){
775 void setLeaderId(String leaderId) {
776 this.leaderId = leaderId;
778 notifyOnShardInitializedCallbacks();
782 private static class ShardManagerCreator implements Creator<ShardManager> {
783 private static final long serialVersionUID = 1L;
785 final ClusterWrapper cluster;
786 final Configuration configuration;
787 final DatastoreContext datastoreContext;
788 private final CountDownLatch waitTillReadyCountdownLatch;
790 ShardManagerCreator(ClusterWrapper cluster,
791 Configuration configuration, DatastoreContext datastoreContext, CountDownLatch waitTillReadyCountdownLatch) {
792 this.cluster = cluster;
793 this.configuration = configuration;
794 this.datastoreContext = datastoreContext;
795 this.waitTillReadyCountdownLatch = waitTillReadyCountdownLatch;
799 public ShardManager create() throws Exception {
800 return new ShardManager(cluster, configuration, datastoreContext, waitTillReadyCountdownLatch);
804 private static class OnShardInitialized {
805 private final Runnable replyRunnable;
806 private Cancellable timeoutSchedule;
808 OnShardInitialized(Runnable replyRunnable) {
809 this.replyRunnable = replyRunnable;
812 Runnable getReplyRunnable() {
813 return replyRunnable;
816 Cancellable getTimeoutSchedule() {
817 return timeoutSchedule;
820 void setTimeoutSchedule(Cancellable timeoutSchedule) {
821 this.timeoutSchedule = timeoutSchedule;
825 private static class OnShardReady extends OnShardInitialized {
826 OnShardReady(Runnable replyRunnable) {
827 super(replyRunnable);
831 private static class ShardNotInitializedTimeout {
832 private final ActorRef sender;
833 private final ShardInformation shardInfo;
834 private final OnShardInitialized onShardInitialized;
836 ShardNotInitializedTimeout(ShardInformation shardInfo, OnShardInitialized onShardInitialized, ActorRef sender) {
837 this.sender = sender;
838 this.shardInfo = shardInfo;
839 this.onShardInitialized = onShardInitialized;
842 ActorRef getSender() {
846 ShardInformation getShardInfo() {
850 OnShardInitialized getOnShardInitialized() {
851 return onShardInitialized;
855 static class SchemaContextModules implements Serializable {
856 private static final long serialVersionUID = -8884620101025936590L;
858 private final Set<String> modules;
860 SchemaContextModules(Set<String> modules){
861 this.modules = modules;
864 public Set<String> getModules() {