Ejemplo n.º 1
0
        public Task <IServiceRemotingResponseMessageBody> InvokeAsync(ActorId actorId, int interfaceId, int methodId,
                                                                      string callContext,
                                                                      IServiceRemotingRequestMessageBody requestMsgBody,
                                                                      IServiceRemotingMessageBodyFactory remotingMessageBodyFactory,
                                                                      CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            this.ThrowIfClosed();

            var methodDispatcher   = this.actorService.MethodDispatcherMapV2.GetDispatcher(interfaceId, methodId);
            var actorMethodName    = methodDispatcher.GetMethodName(methodId);
            var actorMethodContext = ActorMethodContext.CreateForActor(actorMethodName);


            return(this.DispatchToActorAsync <IServiceRemotingResponseMessageBody>(
                       actorId: actorId,
                       actorMethodContext: actorMethodContext,
                       createIfRequired: true,
                       actorFunc:
                       (actor, innerCancellationToken) =>
                       this.ActorMethodDispatch(methodDispatcher, actor, interfaceId, methodId, requestMsgBody,
                                                remotingMessageBodyFactory,
                                                innerCancellationToken),
                       callContext: callContext,
                       timerCall: false,
                       cancellationToken: cancellationToken));
        }
Ejemplo n.º 2
0
        private void Initialize(ServiceRemotingMessageSerializersManager serializersManager, Binding clientBinding,
                                IServiceRemotingCallbackMessageHandler callbackClient, IEnumerable <IExceptionHandler> exceptionHandlers,
                                IServicePartitionResolver servicePartitionResolver, string traceId, Func <Binding, IEnumerable <IExceptionHandler>, IServicePartitionResolver, string, IServiceRemotingCallbackContract, WcfCommunicationClientFactory <IServiceRemotingContract> > createWcfClientFactory)
        {
            this.serializersManager = serializersManager;
            if (traceId == null)
            {
                traceId = Guid.NewGuid().ToString();
            }

            if (createWcfClientFactory == null)
            {
                this.wcfFactory = new WcfCommunicationClientFactory <IServiceRemotingContract>(
                    clientBinding,
                    GetExceptionHandlers(exceptionHandlers, traceId),
                    servicePartitionResolver,
                    traceId,
                    this.GetCallbackImplementation(callbackClient));
            }
            else
            {
                this.wcfFactory = createWcfClientFactory(
                    clientBinding,
                    GetExceptionHandlers(exceptionHandlers, traceId),
                    servicePartitionResolver,
                    traceId,
                    this.GetCallbackImplementation(callbackClient));
            }


            this.wcfFactory.ClientConnected    += this.OnClientConnected;
            this.wcfFactory.ClientDisconnected += this.OnClientDisconnected;

            this.remotingMessageBodyFactory = this.serializersManager.GetSerializationProvider().CreateMessageBodyFactory();
        }
Ejemplo n.º 3
0
        //V2 Stack Api

        internal void Initialize(
            Remoting.V2.Client.ActorServicePartitionClient client,
            IServiceRemotingMessageBodyFactory serviceRemotingMessageBodyFactory)
        {
            this.servicePartitionClientV2 = client;
            this.InitializeV2(serviceRemotingMessageBodyFactory);
            this.remotingClient = RemotingClient.V2Client;
        }
        /// <summary>
        /// Instantiates the ServiceRemotingDispatcher that uses the given service context and
        /// dispatches messages to the given service implementation.
        /// </summary>
        /// <param name="serviceContext">Service context</param>
        /// <param name="serviceImplementation">Service implementation that implements interfaces of type <see cref="IService"/></param>
        /// <param name="serviceRemotingMessageBodyFactory">This is the factory used by Dispatcher to create Remoting Response object</param>
        public ServiceRemotingMessageDispatcher(ServiceContext serviceContext,
                                                IService serviceImplementation,
                                                IServiceRemotingMessageBodyFactory serviceRemotingMessageBodyFactory = null)
        {
            var serviceTypeInformation = ServiceTypeInformation.Get(serviceImplementation.GetType());

            this.Initialize(serviceContext, serviceImplementation, serviceTypeInformation.InterfaceTypes, false, serviceRemotingMessageBodyFactory);
        }
Ejemplo n.º 5
0
 public WcfServiceRemotingCallbackClient(
     IServiceRemotingCallbackContract callbackChannel,
     ServiceRemotingMessageSerializersManager serializersManager)
 {
     this.callbackChannel            = callbackChannel;
     this.serializersManager         = serializersManager;
     this.remotingMessageBodyFactory = serializersManager.GetSerializationProvider().CreateMessageBodyFactory();
 }
 public FabricTransportServiceRemotingCallbackClient(
     FabricTransportCallbackClient fabricTransportCallbackClient,
     ServiceRemotingMessageSerializersManager serializersManager)
 {
     this.fabricTransportCallbackClient = fabricTransportCallbackClient;
     this.serializersManager            = serializersManager;
     this.remotingMessageBodyFactory    = this.serializersManager.GetSerializationProvider().CreateMessageBodyFactory();
 }
 public ActivityServiceRemotingMessageDispatcher(
     ServiceContext serviceContext,
     IService serviceImplementation,
     IServiceRemotingMessageBodyFactory serviceRemotingMessageBodyFactory) : base(
         serviceContext,
         serviceImplementation,
         serviceRemotingMessageBodyFactory)
 {
 }
 //V2 APi
 internal void Initialize(
     ServiceFabric.Services.Remoting.V2.Builder.ServiceProxyGenerator proxyGenerator,
     ServiceFabric.Services.Remoting.V2.Client.ServiceRemotingPartitionClient client,
     IServiceRemotingMessageBodyFactory serviceRemotingMessageBodyFactory)
 {
     this.partitionClientV2    = client;
     this.ServiceInterfaceType = proxyGenerator.ProxyInterfaceType;
     base.InitializeV2(serviceRemotingMessageBodyFactory);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Instantiates the ActorServiceRemotingDispatcher that can dispatch messages to an actor service and
 /// to the actors hosted in the service..
 /// </summary>
 /// <param name="actorService">An actor service instance.</param>
 /// <param name="serviceRemotingRequestMessageBodyFactory"></param>
 public ActorServiceRemotingDispatcher(ActorService actorService,
                                       IServiceRemotingMessageBodyFactory serviceRemotingRequestMessageBodyFactory)
     : base(GetContext(actorService),
            actorService,
            serviceRemotingRequestMessageBodyFactory)
 {
     this.actorService       = actorService;
     this.cancellationHelper = new ServiceRemotingCancellationHelper(actorService.Context.TraceId);
 }
        public ServiceProxy CreateServiceProxy
            (ServiceRemotingPartitionClient remotingPartitionClient,
            IServiceRemotingMessageBodyFactory remotingMessageBodyFactory)
        {
            var serviceProxy = (ServiceProxy)this.proxyActivator.CreateInstance();

            serviceProxy.Initialize(this, remotingPartitionClient, remotingMessageBodyFactory);
            return(serviceProxy);
        }
Ejemplo n.º 11
0
        public MyActorService(StatefulServiceContext context, ActorTypeInformation actorTypeInfo, Func <ActorService, ActorId, ActorBase> actorFactory = null, Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null, IActorStateProvider stateProvider = null, ActorServiceSettings settings = null) : base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings)
        {
            this.messageBodyFactory = new CustomMessageFactory();
            this.serviceContext     = context;
            var fabricClient = new FabricClient();

            var partitionInfo = (Int64RangePartitionInformation)fabricClient.QueryManager.GetPartitionAsync(this.Context.PartitionId).GetAwaiter().GetResult()[0].PartitionInformation;

            this.lowKey  = partitionInfo.LowKey;
            this.highkey = partitionInfo.HighKey;
        }
        public void GetRemotingMessageBodyFactory_PropagatesCalls()
        {
            IServiceRemotingMessageBodyFactory   expectedResult = new Mock <IServiceRemotingMessageBodyFactory>().Object;
            Mock <IServiceRemotingClientFactory> factoryMock    = new Mock <IServiceRemotingClientFactory>();

            factoryMock.Setup(f => f.GetRemotingMessageBodyFactory()).Returns(expectedResult);
            OmexServiceRemotingClientFactory wrapper = new OmexServiceRemotingClientFactory(factoryMock.Object);

            IServiceRemotingMessageBodyFactory actualResult = wrapper.GetRemotingMessageBodyFactory();

            factoryMock.Verify(f => f.GetRemotingMessageBodyFactory());

            Assert.AreEqual(expectedResult, actualResult);
        }
 public ActorServicePartitionClient(
     IServiceRemotingClientFactory remotingClientFactory,
     Uri serviceUri,
     ActorId actorId,
     string listenerName = null,
     OperationRetrySettings retrySettings = null)
     : base(remotingClientFactory, serviceUri,
            new ServicePartitionKey(actorId.GetPartitionKey()),
            TargetReplicaSelector.Default,
            listenerName,
            retrySettings)
 {
     this.ActorId            = actorId;
     this.messageBodyFactory = remotingClientFactory.GetRemotingMessageBodyFactory();
 }
Ejemplo n.º 14
0
        ////Why we pass IServiceRemotingMessageBodyFactory to this function instead of
        /// setting at class level?. Since we cache MethodDispatcher for each interface ,
        /// we can't set IServiceRemotingMessageBodyFactory at class level .
        /// These can be cases where multiple IServiceRemotingMessageBodyFactory implmenetation
        ///  but single dispatcher class .
        /// <summary>
        ///This method is used to dispatch request to the specified methodId of the
        /// interface implemented by the remoted object.
        /// </summary>
        /// <param name="objectImplementation"></param>
        /// <param name="methodId"></param>
        /// <param name="requestBody"></param>
        /// <param name="remotingMessageBodyFactory"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task <IServiceRemotingResponseMessageBody> DispatchAsync(object objectImplementation, int methodId,
                                                                        IServiceRemotingRequestMessageBody requestBody,
                                                                        IServiceRemotingMessageBodyFactory remotingMessageBodyFactory,
                                                                        CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

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

            return(dispatchTask);
        }
Ejemplo n.º 15
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));
        }
        /// <summary>
        /// Instantiates the ServiceRemotingDispatcher that uses the given service context and
        /// dispatches messages to the given service implementation.
        /// This dispatcher can be used to dispatch request to the specified Remoting types.
        /// </summary>
        /// <param name="remotingTypes">Types to which you can dispatch request to  </param>
        /// <param name="serviceContext">Service context</param>
        /// <param name="serviceImplementation">Service implementation that implements specified remoting interfaces</param>
        /// <param name="serviceRemotingMessageBodyFactory"></param>
        public ServiceRemotingMessageDispatcher(
            IEnumerable <Type> remotingTypes,
            ServiceContext serviceContext,
            object serviceImplementation,
            IServiceRemotingMessageBodyFactory serviceRemotingMessageBodyFactory = null)
        {
            var allRemotingTypes = new List <Type>();

            foreach (var type in remotingTypes)
            {
                foreach (var baseType in type.GetAllBaseInterfaces())
                {
                    if (!allRemotingTypes.Contains(baseType))
                    {
                        allRemotingTypes.Add(baseType);
                    }
                }
            }
            this.Initialize(serviceContext, serviceImplementation, allRemotingTypes, true, serviceRemotingMessageBodyFactory);
        }
 private void Initialize(FabricTransportRemotingSettings remotingSettings,
                         IServiceRemotingCallbackMessageHandler remotingCallbackMessageHandler,
                         IServicePartitionResolver servicePartitionResolver,
                         IEnumerable <IExceptionHandler> exceptionHandlers,
                         string traceId,
                         IServiceRemotingMessageBodyFactory messageBodyFactory,
                         ServiceRemotingMessageSerializersManager serializersManager)
 {
     this.remotingMessageBodyFactory = messageBodyFactory;
     this.clientFactoryImpl          = new FabricTransportServiceRemotingClientFactoryImpl(
         serializersManager,
         remotingSettings,
         remotingCallbackMessageHandler,
         servicePartitionResolver,
         exceptionHandlers,
         traceId
         );
     this.clientFactoryImpl.ClientConnected    += this.OnClientConnected;
     this.clientFactoryImpl.ClientDisconnected += this.OnClientDisconnected;
 }
        private void Initialize(ServiceContext serviceContext, object serviceImplementation,
                                IEnumerable <Type> remotedInterfaces, bool nonServiceInterface,
                                IServiceRemotingMessageBodyFactory serviceRemotingMessageBodyFactory)
        {
            this.serviceRemotingMessageBodyFactory = serviceRemotingMessageBodyFactory ?? new DataContractRemotingMessageFactory();

            this.cancellationHelper = new ServiceRemotingCancellationHelper(serviceContext.TraceId);

            this.methodDispatcherMap   = new Dictionary <int, MethodDispatcherBase>();
            this.serviceImplementation = serviceImplementation;

            if (serviceImplementation != null)
            {
                var interfaceDescriptions = new List <ServiceInterfaceDescription>();
                foreach (var interfaceType in remotedInterfaces)
                {
                    MethodDispatcherBase methodDispatcher;
                    if (nonServiceInterface)
                    {
                        methodDispatcher = ServiceCodeBuilder.GetOrCreateMethodDispatcherForNonMarkerInterface(interfaceType);
                        interfaceDescriptions.Add(ServiceInterfaceDescription.CreateUsingCRCId(interfaceType, false));
                    }
                    else
                    {
                        methodDispatcher = ServiceCodeBuilder.GetOrCreateMethodDispatcher(interfaceType);
                        interfaceDescriptions.Add(ServiceInterfaceDescription.CreateUsingCRCId(interfaceType, true));
                    }
                    this.methodDispatcherMap.Add(methodDispatcher.InterfaceId, methodDispatcher);
                }

                this.servicePerformanceCounterProvider =
                    new ServicePerformanceCounterProvider(serviceContext.PartitionId,
                                                          serviceContext.ReplicaOrInstanceId,
                                                          interfaceDescriptions,
                                                          false);
            }
        }
 /// <inheritdoc/>
 public ExtendedActorServiceRemotingDispatcher(ActorService actorService, IServiceRemotingMessageBodyFactory serviceRemotingRequestMessageBodyFactory)
     : base(actorService, serviceRemotingRequestMessageBodyFactory)
 {
 }
Ejemplo n.º 20
0
 public CustomActorMessageHandler(ActorService actorService, IServiceRemotingMessageBodyFactory serviceRemotingRequestMessageBodyFactory)
     : base(actorService, serviceRemotingRequestMessageBodyFactory)
 {
 }
Ejemplo n.º 21
0
 public Task <IServiceRemotingResponseMessageBody> InvokeAsync(ActorId actorId, int interfaceId, int methodId, string callContext,
                                                               IServiceRemotingRequestMessageBody requestMsgBody, IServiceRemotingMessageBodyFactory remotingMessageBodyFactory,
                                                               CancellationToken cancellationToken)
 {
     return(TaskDone <IServiceRemotingResponseMessageBody> .Done);
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Internal - used by Service remoting
 /// </summary>
 /// <param name="methodName"></param>
 /// <param name="remotingMessageBodyFactory"></param>
 /// <param name="task">continuation task</param>
 /// <param name="interfaceName"></param>
 /// <returns>
 /// A <see cref="System.Threading.Tasks.Task">Task</see> that represents outstanding operation.
 /// </returns>
 protected Task <IServiceRemotingResponseMessageBody> ContinueWithResult <TRetVal>(string interfaceName, string methodName,
                                                                                   IServiceRemotingMessageBodyFactory remotingMessageBodyFactory,
                                                                                   Task <TRetVal> task)
 {
     return(task.ContinueWith(
                t => this.CreateResponseMessageBody(interfaceName, methodName, remotingMessageBodyFactory, t.GetAwaiter().GetResult()),
                TaskContinuationOptions.ExecuteSynchronously));
 }
Ejemplo n.º 23
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>
 protected abstract Task <IServiceRemotingResponseMessageBody> OnDispatchAsync(int methodId, object remotedObject, IServiceRemotingRequestMessageBody requestBody, IServiceRemotingMessageBodyFactory remotingMessageBodyFactory, CancellationToken cancellationToken);
 /// <inheritdoc/>
 public ExtendedServiceRemotingMessageDispatcher(ServiceContext serviceContext, IService service, IServiceRemotingMessageBodyFactory serviceRemotingMessageBodyFactory = null)
     : base(serviceContext, service, serviceRemotingMessageBodyFactory)
 {
 }
        //V2 Stack Api

        internal void InitializeV2(
            IServiceRemotingMessageBodyFactory serviceRemotingMessageBodyFactory)
        {
            this.serviceRemotingMessageBodyFactory = serviceRemotingMessageBodyFactory;
        }
 /// <inheritdoc/>
 public ExtendedServiceRemotingMessageDispatcher(IEnumerable <Type> remotingTypes, ServiceContext serviceContext, object serviceImplementation, IServiceRemotingMessageBodyFactory serviceRemotingMessageBodyFactory = null)
     : base(remotingTypes, serviceContext, serviceImplementation, serviceRemotingMessageBodyFactory)
 {
 }
 public PerActorMethodScopedLifestyleMessageHandler(ActorService actorService, IServiceRemotingMessageBodyFactory serviceRemotingRequestMessageBodyFactory)
     : base(actorService, serviceRemotingRequestMessageBodyFactory)
 {
 }
Ejemplo n.º 28
0
        /// <summary>
        /// This method is used ti create the remoting response from the specified return value
        /// </summary>
        /// <param name="interfaceName"></param>
        /// <param name="methodName"></param>
        /// <param name="remotingMessageBodyFactory"></param>
        /// <param name="response"></param>
        /// <returns></returns>
        protected IServiceRemotingResponseMessageBody CreateResponseMessageBody(string interfaceName, string methodName, IServiceRemotingMessageBodyFactory remotingMessageBodyFactory, object response)
        {
            var msg = remotingMessageBodyFactory.CreateResponse(interfaceName, methodName);

            msg.Set(response);
            return(msg);
        }