コード例 #1
0
        private static ActorMessageHeaders GetActorMessageHeaders(ServiceRemotingMessageHeaders messageHeaders)
        {
            ActorMessageHeaders actorMessageHeaders = null;

            if (ActorMessageHeaders.TryFromServiceMessageHeaders(messageHeaders, out actorMessageHeaders))
            {
            }
            return(actorMessageHeaders);
        }
コード例 #2
0
        private async Task <byte[]> HandleSubscriptionRequestsAsync(
            IServiceRemotingRequestContext requestContext,
            ServiceRemotingMessageHeaders messageHeaders,
            byte[] requestMsgBodyBytes)
        {
            ActorMessageHeaders actorMessageHeaders;

            if (!ActorMessageHeaders.TryFromServiceMessageHeaders(messageHeaders, out actorMessageHeaders))
            {
                //This can only happen if there is issue in our product code like Message Corruption or changing headers format.
                ReleaseAssert.Failfast("ActorMessageHeaders Deserialization failed");
            }

            if (actorMessageHeaders.MethodId == ActorEventSubscription.SubscribeMethodId)
            {
                var requestMsgBody       = (ActorMessageBody)SerializationUtility.Deserialize(ActorEventSubscription.Serializer, requestMsgBodyBytes);
                var castedRequestMsgBody = (EventSubscriptionRequestBody)requestMsgBody.Value;

                await this.actorService.ActorManager.SubscribeAsync(
                    actorMessageHeaders.ActorId,
                    castedRequestMsgBody.eventInterfaceId,
                    new ActorEventSubscriberProxy(
                        castedRequestMsgBody.subscriptionId,
                        requestContext.GetCallbackClient()));

                return(null);
            }

            if (actorMessageHeaders.MethodId == ActorEventSubscription.UnSubscribeMethodId)
            {
                var requestMsgBody       = (ActorMessageBody)SerializationUtility.Deserialize(ActorEventSubscription.Serializer, requestMsgBodyBytes);
                var castedRequestMsgBody = (EventSubscriptionRequestBody)requestMsgBody.Value;

                await this.actorService.ActorManager.UnsubscribeAsync(
                    actorMessageHeaders.ActorId,
                    castedRequestMsgBody.eventInterfaceId,
                    castedRequestMsgBody.subscriptionId);

                return(null);
            }

            throw new MissingMethodException(string.Format(CultureInfo.CurrentCulture, Actors.SR.ErrorInvalidMethodId, actorMessageHeaders.MethodId));
        }
コード例 #3
0
        private async Task <byte[]> HandleSubscriptionRequests(
            IServiceRemotingRequestContext requestContext,
            ServiceRemotingMessageHeaders messageHeaders,
            byte[] requestMsgBodyBytes)
        {
            ActorMessageHeaders actorMessageHeaders;

            if (!ActorMessageHeaders.TryFromServiceMessageHeaders(messageHeaders, out actorMessageHeaders))
            {
                throw new SerializationException(Actors.SR.ErrorActorMessageHeadersDeserializationFailed);
            }

            if (actorMessageHeaders.MethodId == ActorEventSubscription.SubscribeMethodId)
            {
                var requestMsgBody       = (ActorMessageBody)SerializationUtility.Deserialize(ActorEventSubscription.Serializer, requestMsgBodyBytes);
                var castedRequestMsgBody = (EventSubscriptionRequestBody)requestMsgBody.Value;

                await this.actorService.ActorManager.SubscribeAsync(
                    actorMessageHeaders.ActorId,
                    castedRequestMsgBody.eventInterfaceId,
                    new ActorEventSubscriberProxy(
                        castedRequestMsgBody.subscriptionId,
                        requestContext.GetCallbackClient()));

                return(null);
            }

            if (actorMessageHeaders.MethodId == ActorEventSubscription.UnSubscribeMethodId)
            {
                var requestMsgBody       = (ActorMessageBody)SerializationUtility.Deserialize(ActorEventSubscription.Serializer, requestMsgBodyBytes);
                var castedRequestMsgBody = (EventSubscriptionRequestBody)requestMsgBody.Value;

                await this.actorService.ActorManager.UnsubscribeAsync(
                    actorMessageHeaders.ActorId,
                    castedRequestMsgBody.eventInterfaceId,
                    castedRequestMsgBody.subscriptionId);

                return(null);
            }

            throw new MissingMethodException(string.Format(CultureInfo.CurrentCulture, Actors.SR.ErrorInvalidMethodId, actorMessageHeaders.MethodId));
        }
コード例 #4
0
        private async Task <byte[]> HandleActorMethodDispatchAsync(
            ServiceRemotingMessageHeaders messageHeaders,
            byte[] requestMsgBodyBytes)
        {
            var startTime = DateTime.UtcNow;
            ActorMessageHeaders actorMessageHeaders;

            if (!ActorMessageHeaders.TryFromServiceMessageHeaders(messageHeaders, out actorMessageHeaders))
            {
                throw new SerializationException(Actors.SR.ErrorActorMessageHeadersDeserializationFailed);
            }

            if (this.IsCancellationRequest(messageHeaders))
            {
                await this.cancellationHelper.CancelRequestAsync(
                    actorMessageHeaders.InterfaceId,
                    actorMessageHeaders.MethodId,
                    messageHeaders.InvocationId);

                return(null);
            }
            else
            {
                byte[] retVal;
                this.actorService.ActorManager.DiagnosticsEventManager.ActorRequestProcessingStart();
                try
                {
                    retVal = await this.cancellationHelper.DispatchRequest(
                        actorMessageHeaders.InterfaceId,
                        actorMessageHeaders.MethodId,
                        messageHeaders.InvocationId,
                        cancellationToken => this.OnDispatch(actorMessageHeaders, requestMsgBodyBytes, cancellationToken));
                }
                finally
                {
                    this.actorService.ActorManager.DiagnosticsEventManager.ActorRequestProcessingFinish(startTime);
                }
                return(retVal);
            }
        }
コード例 #5
0
        public void OneWayMessage(ServiceRemotingMessageHeaders serviceMessageHeaders, byte[] requestBody)
        {
            ActorMessageHeaders actorHeaders;

            if (!ActorMessageHeaders.TryFromServiceMessageHeaders(serviceMessageHeaders, out actorHeaders))
            {
                return;
            }

            ActorMethodDispatcherBase eventDispatcher;

            if ((this.eventIdToDispatchersMap == null) ||
                (!this.eventIdToDispatchersMap.TryGetValue(actorHeaders.InterfaceId, out eventDispatcher)))
            {
                return;
            }

            SubscriptionInfo info;

            if (!this.subscriptionIdToInfoMap.TryGetValue(actorHeaders.ActorId.GetGuidId(), out info))
            {
                return;
            }

            if (info.Subscriber.EventId != actorHeaders.InterfaceId)
            {
                return;
            }

            try
            {
                var eventMsgBody = eventDispatcher.DeserializeRequestMessageBody(requestBody);
                eventDispatcher.Dispatch(info.Subscriber.Instance, actorHeaders.MethodId, eventMsgBody);
            }
            catch
            {
                // ignored
            }
        }