Beispiel #1
0
        /// <summary>
        /// Invokes the specified method for the actor with provided request.
        /// </summary>
        /// <param name="interfaceId">Interface ID.</param>
        /// <param name="methodId">Method ID.</param>
        /// <param name="methodName">Method Name.</param>
        /// <param name="requestMsgBodyValue">Request Message Body Value.</param>
        /// <param name="cancellationToken">Cancellation Token.</param>
        /// <returns>A <see cref="Task{TResult}"/> representing the result of the asynchronous operation.</returns>
        protected async Task <IActorResponseMessageBody> InvokeMethodAsync(
            int interfaceId,
            int methodId,
            string methodName,
            IActorRequestMessageBody requestMsgBodyValue,
            CancellationToken cancellationToken)
        {
            var headers = new ActorRequestMessageHeader
            {
                ActorId     = this.ActorId,
                ActorType   = this.ActorType,
                InterfaceId = interfaceId,
                MethodId    = methodId,
                CallContext = Actors.Helper.GetCallContext(),
                MethodName  = methodName,
            };

            var responseMsg = await this.actorRemotingClient.InvokeAsync(
                new ActorRequestMessage(
                    headers,
                    requestMsgBodyValue),
                cancellationToken);

            return(responseMsg?.GetBody());
        }
Beispiel #2
0
        /// Internal - used by remoting
        /// <summary>
        /// This checks if we are wrapping actor message body or not.
        /// </summary>
        /// <param name="requestMessageBody">Actor Request Message Body.</param>
        /// <returns>true or false.</returns>
        protected bool CheckIfItsWrappedRequest(IActorRequestMessageBody requestMessageBody)
        {
            if (requestMessageBody is WrappedMessage)
            {
                return(true);
            }

            return(false);
        }
Beispiel #3
0
            byte[] IActorRequestMessageBodySerializer.Serialize(IActorRequestMessageBody actorRequestMessageBody)
            {
                if (actorRequestMessageBody == null)
                {
                    return(null);
                }

                using var stream = new MemoryStream();
                using var writer = this.CreateXmlDictionaryWriter(stream);
                this.serializer.WriteObject(writer, actorRequestMessageBody);
                writer.Flush();

                return(stream.ToArray());
            }
Beispiel #4
0
        /// <summary>
        /// Why we pass IMessageBodyFactory to this function instead of
        /// setting at class level?. Since we cache MethodDispatcher for each interface,
        /// we can't set IMessageBodyFactory at class level.
        /// These can be cases where multiple IMessageBodyFactory implmenetation but single dispatcher class.
        /// This method is used to dispatch request to the specified methodId of the
        /// interface implemented by the remoted object.
        /// </summary>
        /// <param name="objectImplementation">The object impplemented the remoted interface.</param>
        /// <param name="methodId">Id of the method to which to dispatch the request to.</param>
        /// <param name="requestBody">The body of the request object that needs to be dispatched to the object.</param>
        /// <param name="remotingMessageBodyFactory">IMessageBodyFactory implementaion.</param>
        /// <param name="cancellationToken">The cancellation token that will be signaled if this operation is cancelled.</param>
        /// <returns>A task that represents the outstanding asynchronous call to the implementation object.
        /// The return value of the task contains the returned value from the invoked method.</returns>
        public Task <IActorResponseMessageBody> DispatchAsync(
            object objectImplementation,
            int methodId,
            IActorRequestMessageBody requestBody,
            IActorMessageBodyFactory remotingMessageBodyFactory,
            CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var dispatchTask = this.OnDispatchAsync(
                methodId,
                objectImplementation,
                requestBody,
                remotingMessageBodyFactory,
                cancellationToken);

            return(dispatchTask);
        }
Beispiel #5
0
 /// <summary>
 /// This method is implemented by the generated method dispatcher to dispatch one way messages to the specified methodId of the
 /// interface implemented by the remoted object.
 /// </summary>
 /// <param name="methodId">Id of the method.</param>
 /// <param name="remotedObject">The remoted object instance.</param>
 /// <param name="requestBody">Request body.</param>
 protected abstract void OnDispatch(int methodId, object remotedObject, IActorRequestMessageBody requestBody);
Beispiel #6
0
 /// <summary>
 /// This method is implemented by the generated method dispatcher to dispatch request to the specified methodId of the
 /// interface implemented by the remoted object.
 /// </summary>
 /// <param name="methodId">Id of the method.</param>
 /// <param name="remotedObject">The remoted object instance.</param>
 /// <param name="requestBody">Request body.</param>
 /// <param name="remotingMessageBodyFactory">Remoting Message Body Factory implementation needed for creating response object.</param>
 /// <param name="cancellationToken">Cancellation token.</param>
 /// <returns>
 /// A <see cref="System.Threading.Tasks.Task">Task</see> that represents outstanding operation.
 /// The result of the task is the return value from the method.
 /// </returns>
 protected abstract Task <IActorResponseMessageBody> OnDispatchAsync(
     int methodId,
     object remotedObject,
     IActorRequestMessageBody requestBody,
     IActorMessageBodyFactory remotingMessageBodyFactory,
     CancellationToken cancellationToken);
Beispiel #7
0
 public ActorRequestMessage(IActorRequestMessageHeader header, IActorRequestMessageBody msgBody)
 {
     this.header  = header;
     this.msgBody = msgBody;
 }