private void CreateNativeClient(
            FabricTransportSettings transportSettings,
            string connectionAddress,
            IFabricTransportClientEventHandler eventHandler,
            IFabricTransportCallbackMessageHandler contract,
            NativeFabricTransport.IFabricTransportMessageDisposer messageMessageDisposer)
        {
            var iid = typeof(NativeFabricTransport.IFabricTransportClient).GetTypeInfo().GUID;

            using (var pin = new PinCollection())
            {
                var nativeTransportSettings = transportSettings.ToNativeV2(pin);
                var messageHandler          = new FabricTransportCallbackHandlerBroker(contract);
                var nativeConnectionAddress = pin.AddBlittable(connectionAddress);
                var nativeEventHandler      = new FabricTransportClientConnectionEventHandlerBroker(eventHandler);
                this.nativeClient =
                    NativeFabricTransport.CreateFabricTransportClient(
                        ref iid,
                        nativeTransportSettings,
                        nativeConnectionAddress,
                        messageHandler,
                        nativeEventHandler,
                        messageMessageDisposer);
            }
        }
Example #2
0
        /// <summary>
        /// Loads the FabricTransport settings from a sectionName specified in the configuration file
        /// Configuration File can be specified using the filePath or using the name of the configuration package specified in the service manifest .
        /// It will first try to load config using configPackageName . if configPackageName is not specified then try to load  from filePath.
        /// </summary>
        /// <param name="sectionName">Name of the section within the configuration file. If not found section in configuration file, it will throw ArgumentException</param>
        /// <param name="filepath"> Full path of the file where the settings will be loaded from.
        ///  If not specified , it will first try to load from default Config Package"Config" , if not found then load from Settings "ClientExeName.Settings.xml" present in Client Exe directory. </param>
        ///  <param name="configPackageName"> Name of the configuration package.If its null or empty,it will check for file in filePath</param>
        /// <returns>FabricTransportRemotingSettings</returns>
        /// <remarks>
        /// The following are the parameter names that should be provided in the configuration file,to be recognizable by service fabric to load the transport settings.
        ///
        ///     1. MaxQueueSize - <see cref="MaxQueueSize"/>value in long.
        ///     2. MaxMessageSize - <see cref="MaxMessageSize"/>value in bytes.
        ///     3. MaxConcurrentCalls - <see cref="MaxConcurrentCalls"/>value in long.
        ///     4. SecurityCredentials - <see cref="SecurityCredentials"/> value.
        ///     5. OperationTimeoutInSeconds - <see cref="OperationTimeout"/> value in seconds.
        ///     6. KeepAliveTimeoutInSeconds - <see cref="KeepAliveTimeout"/> value in seconds.
        /// </remarks>
        public static FabricTransportRemotingSettings LoadFrom(string sectionName, string filepath = null,
                                                               string configPackageName            = null)
        {
            var fabricTransportSettings = FabricTransportSettings.LoadFrom(sectionName, filepath, configPackageName);

            return(new FabricTransportRemotingSettings(fabricTransportSettings));
        }
Example #3
0
        /// <summary>
        /// FabricTransportRemotingSettings returns the default Settings .Loads the configuration file from default Config Package"Config" , if not found then try to load from  default config file "ClientExeName.Settings.xml"  from Client Exe directory.
        ///</summary>
        /// <param name="sectionName">Name of the section within the configuration file. If not found section in configuration file, it will return the default Settings</param>
        /// <returns></returns>
        internal static FabricTransportRemotingSettings GetDefault(string sectionName = DefaultSectionName)
        {
            FabricTransportSettings transportSettings;

            transportSettings = FabricTransportSettings.GetDefault(sectionName);
            return(new FabricTransportRemotingSettings(transportSettings));
        }
 public FabricTransportServiceRemotingClient(
     FabricTransportClient nativeClient,
     FabricTransportRemotingClientConnectionHandler remotingClientConnectionHandler)
 {
     this.settings          = nativeClient.Settings;
     this.ConnectionAddress = nativeClient.ConnectionAddress;
     this.IsValid           = true;
     this.nativeClient      = nativeClient;
     this.RemotingClientConnectionHandler = remotingClientConnectionHandler;
 }
Example #5
0
        /// <summary>
        ///  FabricTransportSettings returns the default Settings .Loads the configuration file from default Config Package"Config" , if not found then try to load from  default config file "ClientExeName.Settings.xml"  from Client Exe directory.
        /// </summary>
        /// <param name="sectionName">Name of the section within the configuration file. If not found section in configuration file, it will return the default Settings</param>
        /// <returns></returns>
        private static FabricTransportSettings GetDefaultFabricTransportSettings(string sectionName = "TransportSettings")
        {
            FabricTransportSettings settings = (FabricTransportSettings)null;

            if (!FabricTransportSettings.TryLoadFrom(sectionName, out settings, (string)null, (string)null))
            {
                settings = new FabricTransportSettings();
            }
            return(settings);
        }
Example #6
0
        /// <summary>
        ///     Creates a service remoting client factory to connect to the remoted actor interfaces.
        /// </summary>
        /// <param name="callbackClient">
        ///     Client implementation where the callbacks should be dispatched.
        /// </param>
        /// <returns>
        ///     A <see cref="T:Microsoft.ServiceFabric.Actors.Remoting.FabricTransport.FabricTransportActorRemotingClientFactory" />
        ///     as <see cref="T:Microsoft.ServiceFabric.Services.Remoting.Client.IServiceRemotingClientFactory" />
        ///     that can be used with <see cref="T:Microsoft.ServiceFabric.Actors.Client.ActorProxyFactory" /> to
        ///     generate actor proxy to talk to the actor over remoted actor interface.
        /// </returns>
        public override IServiceRemotingClientFactory CreateServiceRemotingClientFactory(IServiceRemotingCallbackClient callbackClient)
        {
            FabricTransportSettings fabricTransportSettings = GetDefaultFabricTransportSettings("TransportSettings");

            fabricTransportSettings.MaxMessageSize   = this.GetAndValidateMaxMessageSize(fabricTransportSettings.MaxMessageSize);
            fabricTransportSettings.OperationTimeout = this.GetandValidateOperationTimeout(fabricTransportSettings.OperationTimeout);
            fabricTransportSettings.KeepAliveTimeout = this.GetandValidateKeepAliveTimeout(fabricTransportSettings.KeepAliveTimeout);
            var exceptionHandlers = new IExceptionHandler[] { new ActorExceptionHandler() };

            return((IServiceRemotingClientFactory) new FabricTransportActorRemotingClientFactory(fabricTransportSettings, callbackClient, (IServicePartitionResolver)null, exceptionHandlers, (string)null));
        }
Example #7
0
 public FabricTransportClient(
     FabricTransportSettings transportSettings,
     string connectionAddress,
     IFabricTransportClientConnectionHandler eventHandler,
     IFabricTransportCallbackMessageHandler contract = null)
 {
     this.ConnectionAddress = connectionAddress;
     this.settings          = transportSettings;
     Utility.WrapNativeSyncInvokeInMTA(
         () => this.CreateNativeClient(transportSettings, connectionAddress, eventHandler, contract),
         "FabricTransportClient.Create");
 }
        internal static IntPtr ToNativeV2(this FabricTransportSettings transportSettings, PinCollection pin)
        {
            var nativeObj = new NativeFabricTransport.FABRIC_TRANSPORT_SETTINGS();

            nativeObj.Reserved = IntPtr.Zero;

            if (transportSettings.SecurityCredentials != null)
            {
                nativeObj.SecurityCredentials = transportSettings.SecurityCredentials.ToNative(pin);
            }
            else
            {
                nativeObj.SecurityCredentials = IntPtr.Zero;
            }

            if (transportSettings.OperationTimeout.TotalSeconds < 0)
            {
                nativeObj.OperationTimeoutInSeconds = 0;
            }
            else
            {
                nativeObj.OperationTimeoutInSeconds = (uint)transportSettings.OperationTimeout.TotalSeconds;
            }

            if (transportSettings.KeepAliveTimeout.TotalSeconds < 0)
            {
                nativeObj.KeepAliveTimeoutInSeconds = 0;
            }
            else
            {
                nativeObj.KeepAliveTimeoutInSeconds = (uint)transportSettings.KeepAliveTimeout.TotalSeconds;
            }


            Helper.ThrowIfValueOutOfBounds(transportSettings.MaxMessageSize, "MaxMessageSize");

            nativeObj.MaxMessageSize = (uint)transportSettings.MaxMessageSize;

            Helper.ThrowIfValueOutOfBounds(transportSettings.MaxConcurrentCalls, "MaxConcurrentCalls");
            nativeObj.MaxConcurrentCalls = (uint)transportSettings.MaxConcurrentCalls;

            Helper.ThrowIfValueOutOfBounds(transportSettings.MaxQueueSize, "MaxQueueSize");

            nativeObj.MaxQueueSize = (uint)transportSettings.MaxQueueSize;

            return(pin.AddBlittable(nativeObj));
        }
Example #9
0
        /// <summary>
        /// Try to load the FabricTransport settings from a sectionName specified in the configuration file.
        /// Configuration File can be specified using the filePath or using the name of the configuration package specified in the service manifest .
        /// It will first try to load config using configPackageName . if configPackageName is not specified then try to load  from filePath.
        /// </summary>
        /// <param name="sectionName">Name of the section within the configuration file. If not found section in configuration file, it return false</param>
        /// <param name="filepath"> Full path of the file where the settings will be loaded from.
        ///  If not specified , it will first try to load from default Config Package"Config" , if not found then load from Settings "ClientExeName.Settings.xml" present in Client Exe directory. </param>
        ///  <param name="configPackageName"> Name of the configuration package. If its null or empty,it will check for file in filePath</param>
        /// <param name="settings">When this method returns it sets the <see cref="FabricTransportRemotingSettings"/> settings if load from Config succeeded. If fails ,its sets settings to null/> </param>
        /// <returns><see cref="bool"/> specifies whether the settings get loaded successfully from Config.
        /// It returns true when load from Config succeeded, else return false. </returns>
        /// <remarks>
        /// The following are the parameter names that should be provided in the configuration file,to be recognizable by service fabric to load the transport settings.
        ///
        ///     1. MaxQueueSize - <see cref="MaxQueueSize"/>value in long.
        ///     2. MaxMessageSize - <see cref="MaxMessageSize"/>value in bytes.
        ///     3. MaxConcurrentCalls - <see cref="MaxConcurrentCalls"/>value in long.
        ///     4. SecurityCredentials - <see cref="SecurityCredentials"/> value.
        ///     5. OperationTimeoutInSeconds - <see cref="OperationTimeout"/> value in seconds.
        ///     6. KeepAliveTimeoutInSeconds - <see cref="KeepAliveTimeout"/> value in seconds.
        /// </remarks>
        public static bool TryLoadFrom(string sectionName, out FabricTransportRemotingSettings settings,
                                       string filepath          = null,
                                       string configPackageName = null)
        {
            FabricTransportSettings transportSettings;
            var isSucceded = FabricTransportSettings.TryLoadFrom(sectionName, out transportSettings, filepath,
                                                                 configPackageName);

            if (isSucceded)
            {
                settings = new FabricTransportRemotingSettings(transportSettings);
                return(true);
            }

            settings = null;
            return(isSucceded);
        }
        public FabricTransportListener(
            FabricTransportSettings transportSettings,
            FabricTransportListenerAddress listenerAddress,
            IFabricTransportMessageHandler serviceImplementation,
            IFabricTransportConnectionHandler remotingConnectionHandler)
        {
            //TODO: Remove this address update  after Bug :1225032 gets resolved
            //Update the Address Path if Settings is Secure
            var isNotSecureEndpoint = transportSettings.SecurityCredentials.CredentialType.Equals(CredentialType.None);

            listenerAddress.Path = !isNotSecureEndpoint
                ? string.Format(CultureInfo.InvariantCulture, "{0}-{1}", listenerAddress.Path, Helper.Secure)
                : listenerAddress.Path;

            Utility.WrapNativeSyncInvokeInMTA(
                () =>
                this.CreateNativeListener(serviceImplementation, transportSettings, listenerAddress,
                                          remotingConnectionHandler),
                "FabricTransportListener");
        }
        /// <summary>
        /// Returns the default Settings. Loads the configuration file from default Config Package"Config", if not found then try to load from  default config file "ClientExeName.Settings.xml"  from Client Exe directory.
        ///</summary>
        /// <param name="sectionName">The name of the section within the configuration file. If not found section in configuration file, it will return the default Settings.</param>
        /// <returns></returns>
        internal static FabricTransportRemotingSettings GetDefault(string sectionName = DefaultSectionName)
        {
            FabricTransportSettings transportSettings;

            transportSettings = FabricTransportSettings.GetDefault(sectionName);
            var settings = new FabricTransportRemotingSettings(transportSettings);

            AppTrace.TraceSource.WriteInfo(
                Tracetype,
                "MaxMessageSize: {0} , MaxConcurrentCalls: {1} , MaxQueueSize: {2} , OperationTimeoutInSeconds: {3} KeepAliveTimeoutInSeconds : {4} , SecurityCredentials {5} , HeaderBufferSize {6}," +
                "HeaderBufferCount {7}",
                settings.MaxMessageSize,
                settings.MaxConcurrentCalls,
                settings.MaxQueueSize,
                settings.OperationTimeout.TotalSeconds,
                settings.KeepAliveTimeout.TotalSeconds,
                settings.SecurityCredentials.CredentialType,
                settings.HeaderBufferSize,
                settings.HeaderMaxBufferCount);
            return(settings);
        }
        private void CreateNativeListener(
            IFabricTransportMessageHandler contract,
            FabricTransportSettings transportSettings,
            FabricTransportListenerAddress listenerAddress,
            IFabricTransportConnectionHandler connectionHandler)
        {
            var iid = typeof(NativeServiceCommunication.IFabricServiceCommunicationListener).GetTypeInfo().GUID;

            using (var pin = new PinCollection())
            {
                var nativeTransportSettings = transportSettings.ToNative(pin);
                var nativeListenerAddress   = listenerAddress.ToNative(pin);
                var nativeConnectionHandler = new FabricTransportServiceConnectionHandlerBroker(connectionHandler);
                var messageHandler          = new FabricTransportMessageHandlerBroker(contract, connectionHandler);
                this.nativeListner = NativeServiceCommunication.CreateServiceCommunicationListener(
                    ref iid,
                    nativeTransportSettings,
                    nativeListenerAddress,
                    messageHandler,
                    nativeConnectionHandler);
            }
        }
Example #13
0
        private void CreateNativeClient(
            FabricTransportSettings transportSettings,
            string connectionAddress,
            IFabricTransportClientConnectionHandler eventHandler,
            IFabricTransportCallbackMessageHandler contract)
        {
            var iid = typeof(NativeServiceCommunication.IFabricServiceCommunicationClient2).GetTypeInfo().GUID;

            using (var pin = new PinCollection())
            {
                var nativeTransportSettings = transportSettings.ToNative(pin);
                var messageHandler          = new FabricTransportCallbackHandlerBroker(contract);
                var nativeConnectionAddress = pin.AddBlittable(connectionAddress);
                var nativeEventHandler      = new FabricTransportNativeClientConnectionEventHandler(eventHandler);
                this.nativeClient =
                    (NativeServiceCommunication.IFabricServiceCommunicationClient2)
                    NativeServiceCommunication.CreateServiceCommunicationClient(
                        ref iid,
                        nativeTransportSettings,
                        nativeConnectionAddress,
                        messageHandler,
                        nativeEventHandler);
            }
        }
Example #14
0
 internal FabricTransportRemotingSettings(FabricTransportSettings fabricTransportSettings)
 {
     this.fabricTransportSettings = fabricTransportSettings;
 }
Example #15
0
 /// <summary>
 /// Creates a new FabricTransportRemotingSettings with default Values.
 /// </summary>
 public FabricTransportRemotingSettings()
 {
     this.fabricTransportSettings = new FabricTransportSettings();
 }
 /// <summary>
 /// Creates a new FabricTransportRemotingSettings with default Values.
 /// </summary>
 public FabricTransportRemotingSettings()
 {
     this.fabricTransportSettings = new FabricTransportSettings();
     this.headerBufferSize        = Constants.DefaultHeaderBufferSize;
     this.headerMaxBufferCount    = Constants.DefaultHeaderMaxBufferCount;
 }