Ejemplo n.º 1
0
 internal ActorManager(ActorService actorService)
 {
     this.actorService            = actorService;
     this.traceId                 = actorService.Context.TraceId;
     this.diagnosticsManager      = new DiagnosticsManager(actorService);
     this.diagnosticsEventManager = this.diagnosticsManager.DiagnosticsEventManager;
     this.eventManager            = new ActorEventManager(actorService.ActorTypeInformation);
     this.isClosed                = false;
     this.activeActors            = new ConcurrentDictionary <ActorId, ActorBase>();
     this.remindersByActorId      = new ConcurrentDictionary <ActorId, ConcurrentDictionary <string, ActorReminder> >();
     this.reminderMethodContext   = ActorMethodContext.CreateForReminder(ReceiveReminderMethodName);
     this.gcTimer                 = new Timer(this.RunGarbageCollection, null, Timeout.Infinite, Timeout.Infinite);
 }
Ejemplo n.º 2
0
        private Task <byte[]> ActorMethodDispatch(
            Remoting.V1.Builder.ActorMethodDispatcherBase methodDispatcher,
            ActorBase actor,
            int interfaceId,
            int methodId,
            object requestBody,
            CancellationToken innerCancellationToken)
        {
            var actorInterfaceMethodKey = DiagnosticsEventManager.GetInterfaceMethodKey((uint)interfaceId,
                                                                                        (uint)methodId);

            this.DiagnosticsEventManager.ActorMethodStart(actorInterfaceMethodKey, actor, RemotingListener.V1Listener);

            Task <object> dispatchTask;

            try
            {
                dispatchTask = methodDispatcher.DispatchAsync(actor, methodId, requestBody, innerCancellationToken);
            }
            catch (Exception e)
            {
                this.DiagnosticsEventManager.ActorMethodFinish(actorInterfaceMethodKey, actor, e,
                                                               RemotingListener.V1Listener);
                throw;
            }

            return(dispatchTask.ContinueWith(
                       t =>
            {
                object responseMsgBody = null;
                try
                {
                    responseMsgBody = t.GetAwaiter().GetResult();
                }
                catch (Exception e)
                {
                    this.DiagnosticsEventManager.ActorMethodFinish(actorInterfaceMethodKey, actor, e,
                                                                   RemotingListener.V1Listener);
                    throw;
                }
                this.DiagnosticsEventManager.ActorMethodFinish(actorInterfaceMethodKey, actor, null,
                                                               RemotingListener.V1Listener);

                var serializationStartTime = DateTime.UtcNow;
                var serializedResponse = methodDispatcher.SerializeResponseMessageBody(responseMsgBody);
                this.DiagnosticsEventManager.ActorResponseSerializationFinish(serializationStartTime);

                return serializedResponse;
            },
                       TaskContinuationOptions.ExecuteSynchronously));
        }
Ejemplo n.º 3
0
        private Task <IServiceRemotingResponseMessageBody> ActorMethodDispatch(
            Remoting.V2.Builder.ActorMethodDispatcherBase methodDispatcher, ActorBase actor, int interfaceId,
            int methodId,
            IServiceRemotingRequestMessageBody requestBody,
            IServiceRemotingMessageBodyFactory remotingMessageBodyFactory, CancellationToken innerCancellationToken)
        {
            var actorInterfaceMethodKey =
                DiagnosticsEventManager.GetInterfaceMethodKey((uint)interfaceId, (uint)methodId);

            this.DiagnosticsEventManager.ActorMethodStart(actorInterfaceMethodKey, actor, RemotingListener.V2Listener);

            Task <IServiceRemotingResponseMessageBody> dispatchTask;

            try
            {
                dispatchTask = methodDispatcher.DispatchAsync(actor, methodId, requestBody, remotingMessageBodyFactory,
                                                              innerCancellationToken);
            }
            catch (Exception e)
            {
                this.DiagnosticsEventManager.ActorMethodFinish(actorInterfaceMethodKey, actor, e,
                                                               RemotingListener.V2Listener);
                throw;
            }

            return(dispatchTask.ContinueWith(
                       t =>
            {
                IServiceRemotingResponseMessageBody responseMsgBody = null;
                try
                {
                    responseMsgBody = t.GetAwaiter().GetResult();
                }
                catch (Exception e)
                {
                    this.DiagnosticsEventManager.ActorMethodFinish(actorInterfaceMethodKey, actor, e,
                                                                   RemotingListener.V2Listener);
                    throw;
                }
                this.DiagnosticsEventManager.ActorMethodFinish(actorInterfaceMethodKey, actor, null,
                                                               RemotingListener.V2Listener);


                return responseMsgBody;
            },
                       TaskContinuationOptions.ExecuteSynchronously));
        }