Example #1
0
        public object EntityMessage(object message)
        {
            _adapter.Log(LogLevel.InfoLevel, $"Getting entity message for type {message.GetType()}");
            var result = _messageExtractor.EntityMessage(message);

            _adapter.Log(LogLevel.InfoLevel, $"Entity message was {result}");
            return(result);
        }
Example #2
0
        /// <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="messageExtractor">
        /// Functions to extract the entity id, shard id, and the message to send to the entity from the incoming message.
        /// </param>
        /// <returns>The actor ref of the <see cref="Sharding.ShardRegion"/> that is to be responsible for the shard.</returns>
        public Task <IActorRef> StartProxyAsync(string typeName, string role, IMessageExtractor messageExtractor)
        {
            IdExtractor extractEntityId = msg =>
            {
                var entityId      = messageExtractor.EntityId(msg);
                var entityMessage = messageExtractor.EntityMessage(msg);
                return(Tuple.Create(entityId, entityMessage));
            };

            return(StartProxyAsync(typeName, role, extractEntityId, messageExtractor.ShardId));
        }
Example #3
0
        /// <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="messageExtractor">
        /// Functions to extract the entity id, shard id, and the message to send to the entity from the incoming message.
        /// </param>
        /// <returns>The actor ref of the <see cref="Sharding.ShardRegion"/> that is to be responsible for the shard.</returns>
        public IActorRef StartProxy(string typeName, string role, IMessageExtractor messageExtractor)
        {
            Tuple <EntityId, Msg> extractEntityId(Msg msg)
            {
                var entityId      = messageExtractor.EntityId(msg);
                var entityMessage = messageExtractor.EntityMessage(msg);

                return(Tuple.Create(entityId, entityMessage));
            };

            return(StartProxy(typeName, role, extractEntityId, messageExtractor.ShardId));
        }
Example #4
0
        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);
        }
Example #5
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="self">TBD</param>
        /// <returns>TBD</returns>
        public static ExtractEntityId ToExtractEntityId(this IMessageExtractor self)
        {
            ExtractEntityId extractEntityId = msg =>
            {
                if (self.EntityId(msg) != null)
                {
                    return(Tuple.Create(self.EntityId(msg), self.EntityMessage(msg)));
                }
                //TODO: should we really use tuples?

                return(null);
            };

            return(extractEntityId);
        }
 public void RouteShardEnvelope()
 {
     _extractor.EntityId(_m1);
     _extractor.EntityMessage(_m1);
     _extractor.ShardId(_m1);
 }