Example #1
0
        private IActorRef GetShard(ShardId id)
        {
            //TODO: change on ConcurrentDictionary.GetOrAdd?
            IActorRef region = null;

            if (!Shards.TryGetValue(id, out region))
            {
                if (EntityProps == null || EntityProps.Equals(Actor.Props.Empty))
                {
                    throw new IllegalStateException("Shard must not be allocated to a proxy only ShardRegion");
                }
                else if (ShardsByRef.Values.All(shardId => shardId != id))
                {
                    Log.Debug("Starting shard [{0}] in region", id);

                    //val name = URLEncoder.encode(id, "utf-8")
                    var name     = Uri.EscapeDataString(id);
                    var shardRef = Context.Watch(Context.ActorOf(PersistentShard.Props(
                                                                     TypeName,
                                                                     id,
                                                                     EntityProps,
                                                                     Settings,
                                                                     IdExtractor,
                                                                     ShardResolver,
                                                                     HandOffStopMessage).WithDispatcher(Context.Props.Dispatcher), name));

                    ShardsByRef = ShardsByRef.SetItem(shardRef, id);
                    return(shardRef);
                }
            }

            return(region ?? ActorRefs.Nobody);
        }
Example #2
0
        public PersistentShardActor(
            string typeName,
            string shardId,
            Props entityProps,
            ClusterShardingSettings settings,
            ExtractEntityId extractEntityId,
            ExtractShardId extractShardId,
            object handOffStopMessage)
        {
            _shardSemantic = new PersistentShard(
                context: Context,
                persistentContext: this,
                unhandled: Unhandled,
                typeName: typeName,
                shardId: shardId,
                entityProps: entityProps,
                settings: settings,
                extractEntityId: extractEntityId,
                extractShardId: extractShardId,
                handOffStopMessage: handOffStopMessage);

            JournalPluginId  = _shardSemantic.JournalPluginId;
            SnapshotPluginId = _shardSemantic.SnapshotPluginId;
        }