Beispiel #1
0
        internal ActorManager(
            ActorRegistration registration,
            ActorActivator activator,
            JsonSerializerOptions jsonSerializerOptions,
            ILoggerFactory loggerFactory,
            IActorProxyFactory proxyFactory,
            IDaprInteractor daprInteractor)
        {
            this.registration          = registration;
            this.activator             = activator;
            this.jsonSerializerOptions = jsonSerializerOptions;
            this.loggerFactory         = loggerFactory;
            this.proxyFactory          = proxyFactory;
            this.daprInteractor        = daprInteractor;

            this.timerManager = new DefaultActorTimerManager(this.daprInteractor);

            // map for remoting calls.
            this.methodDispatcherMap = new ActorMethodDispatcherMap(this.registration.Type.InterfaceTypes);

            // map for non-remoting calls.
            this.actorMethodInfoMap    = new ActorMethodInfoMap(this.registration.Type.InterfaceTypes);
            this.activeActors          = new ConcurrentDictionary <ActorId, ActorActivatorState>();
            this.reminderMethodContext = ActorMethodContext.CreateForReminder(ReceiveReminderMethodName);
            this.timerMethodContext    = ActorMethodContext.CreateForTimer(TimerMethodName);
            this.serializersManager    = IntializeSerializationManager(null);
            this.messageBodyFactory    = new WrappedRequestMessageFactory();

            this.logger = loggerFactory.CreateLogger(this.GetType());
        }
Beispiel #2
0
 public ActorRemotingClient(
     IDaprInteractor daprInteractor,
     IActorMessageBodySerializationProvider serializationProvider = null)
 {
     this.daprInteractor             = daprInteractor;
     this.serializersManager         = IntializeSerializationManager(serializationProvider);
     this.remotingMessageBodyFactory = this.serializersManager.GetSerializationProvider().CreateMessageBodyFactory();
 }
Beispiel #3
0
 /// <summary>
 /// Initialize whencACtorProxy is created for Remoting.
 /// </summary>
 internal void Initialize(
     ActorRemotingClient client,
     ActorId actorId,
     string actorType)
 {
     this.actorRemotingClient     = client;
     this.ActorId                 = actorId;
     this.ActorType               = actorType;
     this.ActorMessageBodyFactory = client.GetRemotingMessageBodyFactory();
 }
Beispiel #4
0
 /// <summary>
 /// Internal - used by Service remoting.
 /// </summary>
 /// <param name="interfaceName">Interface Name of the remoting Interface.</param>
 /// <param name="methodName">Method Name of the remoting method.</param>
 /// <param name="methodId">MethodId of the remoting method.</param>
 /// <param name="remotingMessageBodyFactory">MessageFactory for the remoting Interface.</param>
 /// <param name="task">continuation task.</param>
 /// <returns>
 /// A <see cref="System.Threading.Tasks.Task">Task</see> that represents outstanding operation.
 /// </returns>
 /// <typeparam name="TRetVal">The response type for the remoting method.</typeparam>
 protected Task <IActorResponseMessageBody> ContinueWithResult <TRetVal>(
     string interfaceName,
     string methodName,
     int methodId,
     IActorMessageBodyFactory remotingMessageBodyFactory,
     Task <TRetVal> task)
 {
     return(task.ContinueWith(
                t => this.CreateResponseMessageBody(interfaceName, methodName, methodId, remotingMessageBodyFactory, t.GetAwaiter().GetResult()),
                TaskContinuationOptions.ExecuteSynchronously));
 }
Beispiel #5
0
 /// <summary>
 /// Initialize when ActorProxy is created for Remoting.
 /// </summary>
 internal void Initialize(
     ActorRemotingClient client,
     ActorId actorId,
     string actorType,
     ActorProxyOptions options)
 {
     this.actorRemotingClient     = client;
     this.ActorId                 = actorId;
     this.ActorType               = actorType;
     this.ActorMessageBodyFactory = client.GetRemotingMessageBodyFactory();
     this.JsonSerializerOptions   = options?.JsonSerializerOptions ?? this.JsonSerializerOptions;
 }
Beispiel #6
0
        internal ActorManager(ActorService actorService)
        {
            this.actorService = actorService;

            // map for remoting calls.
            this.methodDispatcherMap = new ActorMethodDispatcherMap(this.actorService.ActorTypeInfo.InterfaceTypes);

            // map for non-remoting calls.
            this.actorMethodInfoMap    = new ActorMethodInfoMap(this.actorService.ActorTypeInfo.InterfaceTypes);
            this.activeActors          = new ConcurrentDictionary <ActorId, Actor>();
            this.reminderMethodContext = ActorMethodContext.CreateForReminder(ReceiveReminderMethodName);
            this.timerMethodContext    = ActorMethodContext.CreateForReminder(TimerMethodName);
            this.serializersManager    = IntializeSerializationManager(null);
            this.messageBodyFactory    = new WrappedRequestMessageFactory();
        }
Beispiel #7
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 #8
0
        /// <summary>
        /// This method is used to create the remoting response from the specified return value.
        /// </summary>
        /// <param name="interfaceName">Interface Name of the remoting Interface.</param>
        /// <param name="methodName">Method Name of the remoting method.</param>
        /// <param name="methodId">MethodId of the remoting method.</param>
        /// <param name="remotingMessageBodyFactory">MessageFactory for the remoting Interface.</param>
        /// <param name="response">Response returned by remoting method.</param>
        /// <returns>Actor Response Message Body.</returns>
        protected IActorResponseMessageBody CreateResponseMessageBody(
            string interfaceName,
            string methodName,
            int methodId,
            IActorMessageBodyFactory remotingMessageBodyFactory,
            object response)
        {
            var msg = remotingMessageBodyFactory.CreateResponseMessageBody(
                interfaceName,
                methodName,
                this.CreateWrappedResponseBody(methodId, response));

            if (!(msg is WrappedMessage))
            {
                msg.Set(response);
            }

            return(msg);
        }
Beispiel #9
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);