public StartProxy(string typeName, ClusterShardingSettings settings, IdExtractor extractEntityId, ShardResolver extractShardId) { if (string.IsNullOrEmpty(typeName)) throw new ArgumentNullException("typeName", "ClusterSharding start proxy requires type name to be provided"); TypeName = typeName; Settings = settings; ExtractEntityId = extractEntityId; ExtractShardId = extractShardId; }
/// <summary> /// Register a named entity type by defining the <see cref="Actor.Props"/> of the entity actor and /// functions to extract entity and shard identifier from messages. The <see cref="Sharding.ShardRegion"/> /// actor for this type can later be retrieved with the <see cref="ShardRegion"/> method. /// </summary> /// <param name="typeName">The name of the entity type</param> /// <param name="entityProps"> /// The <see cref="Actor.Props"/> of the entity actors that will be created by the <see cref="Sharding.ShardRegion"/> /// </param> /// <param name="settings">Configuration settings, see <see cref="ClusterShardingSettings"/></param> /// <param name="idExtractor"> /// Partial function to extract the entity id and the message to send to the entity from the incoming message, /// if the partial function does not match the message will be `unhandled`, /// i.e.posted as `Unhandled` messages on the event stream /// </param> /// <param name="shardResolver"> /// Function to determine the shard id for an incoming message, only messages that passed the `extractEntityId` will be used /// </param> /// <returns>The actor ref of the <see cref="Sharding.ShardRegion"/> that is to be responsible for the shard.</returns> public Task <IActorRef> StartAsync( string typeName, //TODO: change type name to type instance? Props entityProps, ClusterShardingSettings settings, IdExtractor idExtractor, ShardResolver shardResolver) { var allocationStrategy = new LeastShardAllocationStrategy( Settings.TunningParameters.LeastShardAllocationRebalanceThreshold, Settings.TunningParameters.LeastShardAllocationMaxSimultaneousRebalance); return(StartAsync(typeName, entityProps, settings, idExtractor, shardResolver, allocationStrategy, PoisonPill.Instance)); }
public PersistentShard( string typeName, string shardId, Props entityProps, ClusterShardingSettings settings, IdExtractor extractEntityId, ShardResolver extractShardId, object handOffStopMessage) : base(typeName, shardId, entityProps, settings, extractEntityId, extractShardId, handOffStopMessage) { _persistenceId = "/sharding/" + TypeName + "Shard/" + ShardId; JournalPluginId = Settings.JournalPluginId; SnapshotPluginId = Settings.SnapshotPluginId; }
public Start(string typeName, Props entityProps, ClusterShardingSettings settings, IdExtractor idIdExtractor, ShardResolver shardResolver, IShardAllocationStrategy allocationStrategy, object handOffStopMessage) { if (string.IsNullOrEmpty(typeName)) throw new ArgumentNullException("typeName", "ClusterSharding start requires type name to be provided"); if (entityProps == null) throw new ArgumentNullException("entityProps", string.Format("ClusterSharding start requires Props for [{0}] to be provided", typeName)); TypeName = typeName; EntityProps = entityProps; Settings = settings; IdExtractor = idIdExtractor; ShardResolver = shardResolver; AllocationStrategy = allocationStrategy; HandOffStopMessage = handOffStopMessage; }
public static IdExtractor ToIdExtractor(this IMessageExtractor self) { IdExtractor idExtractor = msg => { if (self.EntityId(msg) != null) { return(Tuple.Create(self.EntityId(msg), self.EntityMessage(msg))); } //TODO: should we really use tuples? return(null); }; return(idExtractor); }
/// <summary> /// TBD /// </summary> /// <param name="typeName">TBD</param> /// <param name="shardId">TBD</param> /// <param name="entityProps">TBD</param> /// <param name="settings">TBD</param> /// <param name="extractEntityId">TBD</param> /// <param name="extractShardId">TBD</param> /// <param name="handOffStopMessage">TBD</param> protected Shard( string typeName, string shardId, Props entityProps, ClusterShardingSettings settings, IdExtractor extractEntityId, ShardResolver extractShardId, object handOffStopMessage) { TypeName = typeName; ShardId = shardId; EntityProps = entityProps; Settings = settings; ExtractEntityId = extractEntityId; ExtractShardId = extractShardId; HandOffStopMessage = handOffStopMessage; }
public ShardRegion(string typeName, Props entityProps, ClusterShardingSettings settings, string coordinatorPath, IdExtractor extractEntityId, ShardResolver extractShardId, object handOffStopMessage) { TypeName = typeName; EntityProps = entityProps; Settings = settings; CoordinatorPath = coordinatorPath; IdExtractor = extractEntityId; ShardResolver = extractShardId; HandOffStopMessage = handOffStopMessage; //TODO: how to apply custom comparer different way? var membersByAgeBuilder = ImmutableSortedSet <Member> .Empty.ToBuilder(); membersByAgeBuilder.KeyComparer = AgeOrdering; MembersByAge = membersByAgeBuilder.ToImmutable(); _retryTask = Context.System.Scheduler.ScheduleTellRepeatedlyCancelable(Settings.TunningParameters.RetryInterval, Settings.TunningParameters.RetryInterval, Self, Retry.Instance, Self); }
/// <summary> /// TBD /// </summary> /// <param name="typeName">TBD</param> /// <param name="entityProps">TBD</param> /// <param name="settings">TBD</param> /// <param name="idIdExtractor">TBD</param> /// <param name="shardResolver">TBD</param> /// <param name="allocationStrategy">TBD</param> /// <param name="handOffStopMessage">TBD</param> /// <exception cref="ArgumentNullException"> /// This exception is thrown when the specified <paramref name="typeName"/> or <paramref name="entityProps"/> is undefined. /// </exception> public Start(string typeName, Props entityProps, ClusterShardingSettings settings, IdExtractor idIdExtractor, ShardResolver shardResolver, IShardAllocationStrategy allocationStrategy, object handOffStopMessage) { if (string.IsNullOrEmpty(typeName)) { throw new ArgumentNullException(nameof(typeName), "ClusterSharding start requires type name to be provided"); } if (entityProps == null) { throw new ArgumentNullException(nameof(entityProps), $"ClusterSharding start requires Props for [{typeName}] to be provided"); } TypeName = typeName; EntityProps = entityProps; Settings = settings; IdExtractor = idIdExtractor; ShardResolver = shardResolver; AllocationStrategy = allocationStrategy; HandOffStopMessage = handOffStopMessage; }
/// <summary> /// Register a named entity type by defining the <see cref="Actor.Props"/> of the entity actor and /// functions to extract entity and shard identifier from messages. The <see cref="Sharding.ShardRegion"/> /// actor for this type can later be retrieved with the <see cref="ShardRegion"/> method. /// </summary> /// <param name="typeName">The name of the entity type</param> /// <param name="entityProps"> /// The <see cref="Actor.Props"/> of the entity actors that will be created by the <see cref="Sharding.ShardRegion"/> /// </param> /// <param name="settings">Configuration settings, see <see cref="ClusterShardingSettings"/></param> /// <param name="idExtractor"> /// Partial function to extract the entity id and the message to send to the entity from the incoming message, /// if the partial function does not match the message will be `unhandled`, /// i.e.posted as `Unhandled` messages on the event stream /// </param> /// <param name="shardResolver"> /// Function to determine the shard id for an incoming message, only messages that passed the `extractEntityId` will be used /// </param> /// <param name="allocationStrategy">Possibility to use a custom shard allocation and rebalancing logic</param> /// <param name="handOffStopMessage"> /// The message that will be sent to entities when they are to be stopped for a rebalance or /// graceful shutdown of a <see cref="Sharding.ShardRegion"/>, e.g. <see cref="PoisonPill"/>. /// </param> /// <returns>The actor ref of the <see cref="Sharding.ShardRegion"/> that is to be responsible for the shard.</returns> public IActorRef Start( string typeName, //TODO: change type name to type instance? Props entityProps, ClusterShardingSettings settings, IdExtractor idExtractor, ShardResolver shardResolver, IShardAllocationStrategy allocationStrategy, object handOffStopMessage) { RequireClusterRole(settings.Role); var timeout = _system.Settings.CreationTimeout; var startMsg = new ClusterShardingGuardian.Start(typeName, entityProps, settings, idExtractor, shardResolver, allocationStrategy, handOffStopMessage); var started = _guardian.Value.Ask <ClusterShardingGuardian.Started>(startMsg, timeout).Result; var shardRegion = started.ShardRegion; _regions.TryAdd(typeName, shardRegion); return(shardRegion); }
public static Actor.Props Props(string typeName, ShardId shardId, Props entryProps, ClusterShardingSettings settings, IdExtractor idExtractor, ShardResolver shardResolver, object handOffStopMessage) { return(Actor.Props.Create(() => new PersistentShard(typeName, shardId, entryProps, settings, idExtractor, shardResolver, handOffStopMessage)).WithDeploy(Deploy.Local)); }
/// <summary> /// Factory method for the <see cref="Actor.Props"/> of the <see cref="ShardRegion"/> actor when used in proxy only mode. /// </summary> internal static Props ProxyProps(string typeName, ClusterShardingSettings settings, string coordinatorPath, IdExtractor extractEntityId, ShardResolver extractShardId) { return(Actor.Props.Create(() => new ShardRegion(typeName, null, settings, coordinatorPath, extractEntityId, extractShardId, PoisonPill.Instance)).WithDeploy(Deploy.Local)); }
/// <summary> /// Factory method for the <see cref="Actor.Props"/> of the <see cref="ShardRegion"/> actor. /// </summary> internal static Props Props(string typeName, Props entityProps, ClusterShardingSettings settings, string coordinatorPath, IdExtractor extractEntityId, ShardResolver extractShardId, object handOffStopMessage) { return(Actor.Props.Create(() => new ShardRegion(typeName, entityProps, settings, coordinatorPath, extractEntityId, extractShardId, handOffStopMessage)).WithDeploy(Deploy.Local)); }
IIdExtractor ICodingStyle.GetIdExtractor(IType type) => IdExtractor.Get(type);