예제 #1
0
        private IActorRemotingMessageHeaders CreateActorHeader(ActorRemotingDispatchHeaders actorDispatchHeaders)
        {
            InterfaceDetails details;

            if (ActorCodeBuilder.TryGetKnownTypes(actorDispatchHeaders.ActorInterfaceName, out details))
            {
                var headers = new ActorRemotingMessageHeaders();
                headers.ActorId     = actorDispatchHeaders.ActorId;
                headers.InterfaceId = details.Id;
                if (String.IsNullOrEmpty(actorDispatchHeaders.CallContext))
                {
                    headers.CallContext = Helper.GetCallContext();
                }
                else
                {
                    headers.CallContext = actorDispatchHeaders.CallContext;
                }

                var headersMethodId = 0;
                if (!details.MethodNames.TryGetValue(actorDispatchHeaders.MethodName, out headersMethodId))
                {
                    throw new NotSupportedException("This Actor Method is not Supported" + actorDispatchHeaders.MethodName);
                }
                headers.MethodId = headersMethodId;

                return(headers);
            }

            throw new NotSupportedException("This Actor Interface is not Supported" + actorDispatchHeaders.ActorInterfaceName);
        }
예제 #2
0
        internal InterfaceDetails GetInterfaceDetails(int interfaceId)
        {
            if (!ActorCodeBuilder.TryGetKnownTypes(interfaceId, out var interfaceDetails))
            {
                throw new ArgumentException("No interface found with this Id  " + interfaceId);
            }

            return(interfaceDetails);
        }
예제 #3
0
        /// <summary>
        /// Create a proxy, this method is also sued by ACtorReference also to create proxy.
        /// </summary>
        /// <param name="actorId">Actor Id.</param>
        /// <param name="actorInterfaceType">Actor Interface Type.</param>
        /// <param name="actorType">Actor implementation Type.</param>
        /// <returns>Returns Actor Proxy.</returns>
        internal object CreateActorProxy(ActorId actorId, Type actorInterfaceType, string actorType)
        {
            var remotingClient = new ActorRemotingClient(this.daprInteractor);
            var proxyGenerator = ActorCodeBuilder.GetOrCreateProxyGenerator(actorInterfaceType);
            var actorProxy     = proxyGenerator.CreateActorProxy();

            actorProxy.Initialize(remotingClient, actorId, actorType);

            return(actorProxy);
        }
        public ActorMethodDispatcherMap(ActorTypeInformation actorTypeInformation)
        {
            this.map = new Dictionary <int, ActorMethodDispatcherBase>();

            foreach (var actorInterfaceType in actorTypeInformation.InterfaceTypes)
            {
                var methodDispatcher = ActorCodeBuilder.GetOrCreateMethodDispatcher(actorInterfaceType);
                this.map.Add(methodDispatcher.InterfaceId, methodDispatcher);
            }
        }
예제 #5
0
        internal override InterfaceDetails GetInterfaceDetails(int interfaceId)
        {
            InterfaceDetails interfaceDetails;

            if (ActorCodeBuilder.TryGetKnownTypes(interfaceId, out interfaceDetails))
            {
                return(interfaceDetails);
            }
            //if not found in Actor Store, Check if its there in service store for actor service request
            return(base.GetInterfaceDetails(interfaceId));
        }
예제 #6
0
        public ActorEventProxy GetActorEventProxy(ActorId actorId, Type eventType)
        {
            var eventProxyMap = this.actorIdToEventProxyMap.GetOrAdd(
                actorId,
                new ConcurrentDictionary <Type, ActorEventProxy>());

            var eventProxy = eventProxyMap.GetOrAdd(
                eventType,
                t =>
            {
                var eventProxyGenerator = ActorCodeBuilder.GetOrCreateEventProxyGenerator(t);
                return(eventProxyGenerator.CreateActorEventProxy());
            });

            return(eventProxy);
        }
        /// <summary>
        /// Creates a proxy to the actor object that implements an actor interface.
        /// </summary>
        /// <typeparam name="TActorInterface">
        /// The actor interface implemented by the remote actor object.
        /// The returned proxy object will implement this interface.
        /// </typeparam>
        /// <param name="serviceUri">Uri of the actor service.</param>
        /// <param name="actorId">Actor Id of the proxy actor object. Methods called on this proxy will result in requests
        /// being sent to the actor with this id.</param>
        /// <param name="listenerName">
        /// By default an actor service has only one listener for clients to connect to and communicate with.
        /// However it is possible to configure an actor service with more than one listeners, the listenerName parameter specifies the name of the listener to connect to.
        /// </param>
        /// <returns>An actor proxy object that implements <see cref="IActorProxy"/> and TActorInterface.</returns>
        public TActorInterface CreateActorProxy <TActorInterface>(
            Uri serviceUri,
            ActorId actorId,
            string listenerName = null) where TActorInterface : IActor
        {
            var actorInterfaceType          = typeof(TActorInterface);
            var proxyGenerator              = ActorCodeBuilder.GetOrCreateProxyGenerator(actorInterfaceType);
            var actorServicePartitionClient = new ActorServicePartitionClient(
                this.GetOrCreateServiceRemotingClientFactory(actorInterfaceType),
                serviceUri,
                actorId,
                listenerName,
                this.retrySettings);

            return((TActorInterface)(object)proxyGenerator.CreateActorProxy(actorServicePartitionClient));
        }
        internal object CreateActorProxy(
            Type actorInterfaceType,
            Uri serviceUri,
            ActorId actorId,
            string listenerName = null)
        {
            var proxyGenerator = ActorCodeBuilder.GetOrCreateProxyGenerator(actorInterfaceType);
            var actorServicePartitionClient = new ActorServicePartitionClient(
                this.GetOrCreateServiceRemotingClientFactory(actorInterfaceType),
                serviceUri,
                actorId,
                listenerName,
                this.retrySettings);

            return(proxyGenerator.CreateActorProxy(actorServicePartitionClient));
        }
예제 #9
0
        public async Task ActorCodeBuilder_BuildDispatcher()
        {
            var host = ActorHost.CreateForTest <TestActor>();

            var dispatcher = ActorCodeBuilder.GetOrCreateMethodDispatcher(typeof(ITestActor));
            var methodId   = MethodDescription.Create("test", typeof(ITestActor).GetMethod("GetCountAsync"), true).Id;

            var impl     = new TestActor(host);
            var request  = new ActorRequestMessageBody(0);
            var response = new WrappedRequestMessageFactory();

            var body = (WrappedMessage)await dispatcher.DispatchAsync(impl, methodId, request, response, default);

            dynamic bodyValue = body.Value;

            Assert.Equal(5, (int)bodyValue.retVal);
        }
예제 #10
0
 public void TestBuildActorProxyGenerator()
 {
     ActorProxyGenerator proxyGenerator = ActorCodeBuilder.GetOrCreateProxyGenerator(typeof(ITestActor));
 }