Beispiel #1
0
        /// <summary>
        /// Initializes a new silo that hosts all objects in the same process it is used in, but with
        /// proxy and servant implementations in between.
        /// Is only really useful for debugging remoting.
        /// </summary>
        /// <param name="customTypeResolver">The type resolver, if any, that is used to resolve types by their assembly qualified name</param>
        public InProcessRemotingSilo(ITypeResolver customTypeResolver = null)
        {
            _customTypeResolver = customTypeResolver;
            const int subjectHostId = 0;

            _nextObjectId = subjectHostId + 1;

            _client           = new SocketEndPoint(EndPointType.Client);
            _subjectHostProxy = _client.CreateProxy <ISubjectHost>(subjectHostId);

            _syncRoot = new object();

            _server      = new SocketEndPoint(EndPointType.Server);
            _registry    = new DefaultImplementationRegistry();
            _subjectHost = new SubjectHost(_server, _registry);
            _server.CreateServant(subjectHostId, (ISubjectHost)_subjectHost);
            _server.Bind(IPAddress.Loopback);

            _client.Connect(_server.LocalEndPoint, TimeSpan.FromSeconds(5));
        }
        /// <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;
        }