Exemple #1
0
        /// <summary>
        ///     Initializes a new silo server.
        /// </summary>
        /// <param name="args">The command line arguments given to the Main() method</param>
        /// <param name="customTypeResolver">The type resolver, if any, responsible for resolving Type objects by their assembly qualified name</param>
        /// <param name="codeGenerator">The code generator to create proxy and servant types</param>
        /// <param name="heartbeatSettings">The settings for heartbeat mechanism, if none are specified, then default settings are used</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="endPointName">The name of this silo, used for debugging (and logging)</param>
        public OutOfProcessSiloServer(string[] args,
                                      ITypeResolver customTypeResolver    = null,
                                      ICodeGenerator codeGenerator        = null,
                                      HeartbeatSettings heartbeatSettings = null,
                                      LatencySettings latencySettings     = null,
                                      EndPointSettings endPointSettings   = null,
                                      string endPointName = null)
        {
            Log.InfoFormat("Silo Server starting, args ({0}): \"{1}\", {2} custom type resolver",
                           args.Length,
                           string.Join(" ", args),
                           customTypeResolver != null ? "with" : "without"
                           );

            int pid;

            if (args.Length >= 1 && int.TryParse(args[0], out pid))
            {
                _parentProcessId = pid;
                _parentProcess   = Process.GetProcessById(pid);
                _parentProcess.EnableRaisingEvents = true;
                _parentProcess.Exited += ParentProcessOnExited;
            }

            if (Log.IsDebugEnabled)
            {
                Log.DebugFormat("Args.Length: {0}", args.Length);
            }

            _registry           = new DefaultImplementationRegistry();
            _waitHandle         = new ManualResetEvent(false);
            _customTypeResolver = customTypeResolver;

            _endPoint = new SocketEndPoint(EndPointType.Server,
                                           endPointName,
                                           codeGenerator: codeGenerator,
                                           heartbeatSettings: heartbeatSettings,
                                           latencySettings: latencySettings,
                                           endPointSettings: endPointSettings
                                           );

            _endPoint.OnConnected    += EndPointOnOnConnected;
            _endPoint.OnDisconnected += EndPointOnOnDisconnected;
            _endPoint.OnFailure      += EndPointOnOnFailure;
        }
Exemple #2
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));
        }
Exemple #3
0
        public SubjectHost(IRemotingEndPoint endpoint,
                           DefaultImplementationRegistry registry,
                           Action onDisposed = null,
                           ITypeResolver customTypeResolver = null)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException(nameof(endpoint));
            }
            if (registry == null)
            {
                throw new ArgumentNullException(nameof(registry));
            }

            _registry           = registry;
            _customTypeResolver = customTypeResolver;
            _endpoint           = endpoint;
            _onDisposed         = onDisposed;
            _syncRoot           = new object();
            _servants           = new Dictionary <ulong, IServant>();
            _subjects           = new Dictionary <ulong, object>();
        }
Exemple #4
0
        /// <summary>
        ///     Initializes a new silo server.
        /// </summary>
        /// <param name="args">The command line arguments given to the Main() method</param>
        /// <param name="customTypeResolver">The type resolver, if any, responsible for resolving Type objects by their assembly qualified name</param>
        /// <param name="codeGenerator">The code generator to create proxy and servant types</param>
        /// <param name="postMortemSettings">
        ///     Settings to control how and if minidumps are collected - when set to null, default values are used (
        ///     <see
        ///         cref="PostMortemSettings" />
        ///     )
        /// </param>
        /// <param name="heartbeatSettings">The settings for heartbeat mechanism, if none are specified, then default settings are used</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="endPointName">The name of this silo, used for debugging (and logging)</param>
        public OutOfProcessSiloServer(string[] args,
                                      ITypeResolver customTypeResolver      = null,
                                      ICodeGenerator codeGenerator          = null,
                                      PostMortemSettings postMortemSettings = null,
                                      HeartbeatSettings heartbeatSettings   = null,
                                      LatencySettings latencySettings       = null,
                                      EndPointSettings endPointSettings     = null,
                                      string endPointName = null)
        {
            if (postMortemSettings != null && !postMortemSettings.IsValid)
            {
                throw new ArgumentException("postMortemSettings");
            }

            Log.InfoFormat("Silo Server starting, args ({0}): \"{1}\", {2} custom type resolver",
                           args.Length,
                           string.Join(" ", args),
                           customTypeResolver != null ? "with" : "without"
                           );

            int pid;

            if (args.Length >= 1 && int.TryParse(args[0], out pid))
            {
                _parentProcessId = pid;
                _parentProcess   = Process.GetProcessById(pid);
                _parentProcess.EnableRaisingEvents = true;
                _parentProcess.Exited += ParentProcessOnExited;
            }

            if (Log.IsDebugEnabled)
            {
                Log.DebugFormat("Args.Length: {0}", args.Length);
            }

            if (args.Length >= 10)
            {
                if (postMortemSettings != null)
                {
                    Log.Info("Ignoring post-mortem settings specified from the command-line");
                }
                else
                {
                    var settings = new PostMortemSettings();
                    bool.TryParse(args[1], out settings.CollectMinidumps);
                    bool.TryParse(args[2], out settings.SuppressErrorWindows);
                    bool.TryParse(args[3], out settings.HandleAccessViolations);
                    bool.TryParse(args[4], out settings.HandleCrtAsserts);
                    bool.TryParse(args[5], out settings.HandleCrtPureVirtualFunctionCalls);
                    int tmp;
                    int.TryParse(args[6], out tmp);
                    settings.RuntimeVersions = (CRuntimeVersions)tmp;
                    int.TryParse(args[7], out settings.NumMinidumpsRetained);
                    settings.MinidumpFolder = args[8];
                    settings.MinidumpName   = args[9];

                    if (!settings.IsValid)
                    {
                        Log.ErrorFormat("Received invalid post-mortem debugger settings: {0}", settings);
                    }
                    else
                    {
                        postMortemSettings = settings;
                    }
                }
            }

            _registry           = new DefaultImplementationRegistry();
            _waitHandle         = new ManualResetEvent(false);
            _customTypeResolver = customTypeResolver;

            _postMortemSettings = postMortemSettings;
            if (_postMortemSettings != null)
            {
                Log.InfoFormat("Using post-mortem debugger: {0}", _postMortemSettings);

                if (!NativeMethods.LoadPostmortemDebugger())
                {
                    int err = Marshal.GetLastWin32Error();
                    Log.ErrorFormat("Unable to load the post-mortem debugger dll: {0}",
                                    err);
                }

                if (_postMortemSettings.CollectMinidumps)
                {
                    if (NativeMethods.InitDumpCollection(_postMortemSettings.NumMinidumpsRetained,
                                                         _postMortemSettings.MinidumpFolder,
                                                         _postMortemSettings.MinidumpName))
                    {
                        Log.InfoFormat("Installed post-mortem debugger; up to {0} mini dumps will automatically be saved to: {1}",
                                       _postMortemSettings.NumMinidumpsRetained,
                                       _postMortemSettings.MinidumpFolder
                                       );
                    }
                }

                NativeMethods.InstallPostmortemDebugger(_postMortemSettings.HandleAccessViolations,
                                                        _postMortemSettings.SuppressErrorWindows,
                                                        _postMortemSettings.HandleCrtAsserts,
                                                        _postMortemSettings.HandleCrtPureVirtualFunctionCalls,
                                                        _postMortemSettings.RuntimeVersions);
            }

            _endPoint = new SocketEndPoint(EndPointType.Server,
                                           endPointName,
                                           codeGenerator: codeGenerator,
                                           heartbeatSettings: heartbeatSettings,
                                           latencySettings: latencySettings,
                                           endPointSettings: endPointSettings
                                           );

            _endPoint.OnConnected    += EndPointOnOnConnected;
            _endPoint.OnDisconnected += EndPointOnOnDisconnected;
            _endPoint.OnFailure      += EndPointOnOnFailure;
        }
Exemple #5
0
 /// <summary>
 ///     Initializes a new silo that hosts objects in the very same process it is used from.
 /// </summary>
 /// <param name="customTypeResolver">The type resolver, if any, that is used to resolve types by their assembly qualified name</param>
 public InProcessSilo(ITypeResolver customTypeResolver = null)
 {
     _customTypeResolver = customTypeResolver;
     _registry           = new DefaultImplementationRegistry();
 }