Esempio n. 1
0
        /// <summary>
        ///     Initializes a new instance of this silo with the specified options.
        ///     The given host process will only be started once <see cref="Start" /> is called.
        /// </summary>
        /// <param name="process"></param>
        /// <param name="options"></param>
        /// <param name="codeGenerator">The code generator to create proxy and servant types</param>
        /// <param name="latencySettings">
        ///     The settings for latency measurements, if none are specified, then default settings are
        ///     used
        /// </param>
        /// <param name="endPointSettings">The settings for the endpoint itself (max. number of concurrent calls, etc...)</param>
        /// <param name="failureSettings">
        ///     The settings specifying when a failure is assumed to have occured in the host process -
        ///     if none are specified, then defaults are used
        /// </param>
        /// <param name="failureHandler">
        ///     The object responsible for deciding how failures are dealt with - if none is specified
        ///     then a new <see cref="ZeroFailureToleranceStrategy" /> is used
        /// </param>
        /// <param name="endPointName">The name of the endpoint - used in log messages to differentiate between different endpoints</param>
        /// <exception cref="ArgumentNullException">When <paramref name="process" /> is null</exception>
        /// <exception cref="ArgumentException">When <paramref name="process" /> is contains only whitespace</exception>
        public OutOfProcessSilo(
            string process                    = ProcessWatchdog.SharpRemoteHost,
            ProcessOptions options            = ProcessOptions.HideConsole,
            ICodeGenerator codeGenerator      = null,
            LatencySettings latencySettings   = null,
            EndPointSettings endPointSettings = null,
            FailureSettings failureSettings   = null,
            IFailureHandler failureHandler    = null,
            string endPointName               = null
            )
        {
            if (process == null)
            {
                throw new ArgumentNullException(nameof(process));
            }
            if (string.IsNullOrWhiteSpace(process))
            {
                throw new ArgumentException("process");
            }
            if (failureSettings != null)
            {
                if (failureSettings.ProcessReadyTimeout <= TimeSpan.Zero)
                {
                    throw new ArgumentOutOfRangeException(nameof(failureSettings), "ProcessReadyTimeout should be greater than zero");
                }

                if (failureSettings.EndPointConnectTimeout <= TimeSpan.Zero)
                {
                    throw new ArgumentOutOfRangeException(nameof(failureSettings),
                                                          "EndPointConnectTimeout should be greater than zero");
                }
            }

            failureSettings = failureSettings ?? new FailureSettings();
            failureHandler  = failureHandler ?? new ZeroFailureToleranceStrategy();

            _endPoint = new SocketEndPoint(EndPointType.Client,
                                           endPointName,
                                           codeGenerator: codeGenerator,
                                           heartbeatSettings: failureSettings.HeartbeatSettings,
                                           latencySettings: latencySettings,
                                           endPointSettings: endPointSettings,
                                           waitUponReadWriteError: true);

            _subjectHost = _endPoint.CreateProxy <ISubjectHost>(Constants.SubjectHostId);

            _syncRoot = new object();

            _process = new ProcessWatchdog(
                process,
                options
                );

            _process.OnHostOutputWritten += EmitHostOutputWritten;

            _queue = new OutOfProcessQueue(
                _process,
                _endPoint,
                failureHandler,
                failureSettings
                );
            _queue.OnHostStarted += QueueOnOnHostStarted;
        }