Beispiel #1
0
        /// <nodoc />
        protected LocalContentServerBase(
            ILogger logger,
            IAbsFileSystem fileSystem,
            string scenario,
            Func <AbsolutePath, TStore> contentStoreFactory,
            LocalServerConfiguration localContentServerConfiguration,
            IGrpcServiceEndpoint[]?additionalEndpoints)
        {
            Contract.Requires(logger != null);
            Contract.Requires(fileSystem != null);
            Contract.Requires(localContentServerConfiguration != null);
            Contract.Requires(localContentServerConfiguration.GrpcPort > 0, "GrpcPort must be provided");

            logger.Debug($"{Name} process id {Process.GetCurrentProcess().Id}");
            logger.Debug($"{Name} constructing {nameof(ServiceConfiguration)}: {localContentServerConfiguration}");

            GrpcEnvironment.Initialize(logger, localContentServerConfiguration.GrpcEnvironmentOptions, overwriteSafeOptions: true);

            FileSystem = fileSystem;
            Logger     = logger;
            Config     = localContentServerConfiguration;

            _additionalEndpoints     = additionalEndpoints ?? Array.Empty <IGrpcServiceEndpoint>();
            _serviceReadinessChecker = new ServiceReadinessChecker(logger, scenario);
            _sessionHandles          = new ConcurrentDictionary <int, ISessionHandle <TSession, TSessionData> >();

            var storesByName = new Dictionary <string, TStore>();

            foreach (var kvp in localContentServerConfiguration.NamedCacheRoots)
            {
                fileSystem.CreateDirectory(kvp.Value);
                var store = contentStoreFactory(kvp.Value);
                storesByName.Add(kvp.Key, store);
            }
            StoresByName = new ReadOnlyDictionary <string, TStore>(storesByName);

            foreach (var kvp in localContentServerConfiguration.NamedCacheRoots)
            {
                _tempFolderForStreamsByCacheName[kvp.Key] = kvp.Value / "TempFolder";
            }

            if (!string.IsNullOrEmpty(localContentServerConfiguration.GrpcPortFileName))
            {
                var portSharingFactory = new MemoryMappedFileGrpcPortSharingFactory(logger, localContentServerConfiguration.GrpcPortFileName);
                var portExposer        = portSharingFactory.GetPortExposer();
                _portDisposer = portExposer.Expose(localContentServerConfiguration.GrpcPort);
            }
        }
        /// <nodoc />
        protected LocalContentServerBase(
            ILogger logger,
            IAbsFileSystem fileSystem,
            string scenario,
            Func <AbsolutePath, TStore> contentStoreFactory,
            LocalServerConfiguration localContentServerConfiguration)
        {
            Contract.Requires(logger != null);
            Contract.Requires(fileSystem != null);
            Contract.Requires(localContentServerConfiguration != null);
            Contract.Requires(localContentServerConfiguration.GrpcPort > 0, "GrpcPort must be provided");

            logger.Debug($"{Name} process id {Process.GetCurrentProcess().Id}");
            logger.Debug($"{Name} constructing {nameof(ServiceConfiguration)}: {localContentServerConfiguration}");

            FileSystem = fileSystem;
            Logger     = logger;
            Config     = localContentServerConfiguration;

            _serviceReadinessChecker = new ServiceReadinessChecker(Tracer, logger, scenario);
            _sessionHandles          = new ConcurrentDictionary <int, SessionHandle <TSession> >();

            foreach (var kvp in localContentServerConfiguration.NamedCacheRoots)
            {
                fileSystem.CreateDirectory(kvp.Value);
                var store = contentStoreFactory(kvp.Value);
                StoresByName.Add(kvp.Key, store);
            }

            foreach (var kvp in localContentServerConfiguration.NamedCacheRoots)
            {
                _tempFolderForStreamsByCacheName[kvp.Key] = kvp.Value / "TempFolder";
            }

            if (!string.IsNullOrEmpty(localContentServerConfiguration.GrpcPortFileName))
            {
                var portSharingFactory = new MemoryMappedFileGrpcPortSharingFactory(logger, localContentServerConfiguration.GrpcPortFileName);
                var portExposer        = portSharingFactory.GetPortExposer();
                _portDisposer = portExposer.Expose(localContentServerConfiguration.GrpcPort);
            }
        }
Beispiel #3
0
 /// <summary>
 ///     Attempt to open event that will signal an imminent service shutdown or restart.
 /// </summary>
 public static EventWaitHandle OpenShutdownEvent(Context context, string scenario) => ServiceReadinessChecker.OpenShutdownEvent(context, scenario);
Beispiel #4
0
 /// <summary>
 ///     Check if the service is running.
 /// </summary>
 public static bool EnsureRunning(Context context, string scenario, int waitMs) => ServiceReadinessChecker.EnsureRunning(context, scenario, waitMs);