/// <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="messageExtractor"> /// Functions to extract the entity id, shard id, and the message to send to the entity from the incoming message. /// </param> /// <param name="allocationStrategy">Possibility to use a custom shard allocation and rebalancing logic</param> /// <param name="handOffMessage"> /// 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 Task <IActorRef> StartAsync(string typeName, Props entityProps, ClusterShardingSettings settings, IMessageExtractor messageExtractor, IShardAllocationStrategy allocationStrategy, object handOffMessage) { IdExtractor idExtractor = messageExtractor.ToIdExtractor(); ShardResolver shardResolver = messageExtractor.ShardId; return(StartAsync(typeName, entityProps, settings, idExtractor, shardResolver, allocationStrategy, handOffMessage)); }
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> /// TBD /// </summary> /// <param name="typeName">TBD</param> /// <param name="settings">TBD</param> /// <param name="extractEntityId">TBD</param> /// <param name="extractShardId">TBD</param> /// <exception cref="ArgumentException"> /// This exception is thrown when the specified <paramref name="typeName"/> is undefined. /// </exception> public StartProxy(string typeName, ClusterShardingSettings settings, IdExtractor extractEntityId, ShardResolver extractShardId) { if (string.IsNullOrEmpty(typeName)) { throw new ArgumentNullException(nameof(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; }
/// <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)); }
/// <summary> /// Register a named entity type `ShardRegion` on this node that will run in proxy only mode, i.e.it will /// delegate messages to other `ShardRegion` actors on other nodes, but not host any entity actors itself. /// 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="role"> /// Specifies that this entity type is located on cluster nodes with a specific role. /// If the role is not specified all nodes in the cluster are used. /// </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 async Task <IActorRef> StartProxyAsync(string typeName, string role, IdExtractor idExtractor, ShardResolver shardResolver) { var timeout = _system.Settings.CreationTimeout; var settings = ClusterShardingSettings.Create(_system).WithRole(role); var startMsg = new ClusterShardingGuardian.StartProxy(typeName, settings, idExtractor, shardResolver); var started = await _guardian.Value.Ask <ClusterShardingGuardian.Started>(startMsg, timeout); _regions.TryAdd(typeName, started.ShardRegion); return(started.ShardRegion); }