Esempio n. 1
0
 /// <summary> Add <see cref="IAccessQueue{TResource}" /> service with given shared resources reuse <paramref name="strategy" /> </summary>
 /// <param name="services"> Service collection </param>
 /// <param name="resourceFactory"> Shared resource factory function </param>
 /// <param name="strategy"> Conveyor machines reuse strategy <seealso cref="ReuseStrategy" /></param>
 /// <param name="maxResourceInstances"> Max allowed shared resource instances count </param>
 /// <param name="maxAttempts"> Max allowed retry on fail attempts </param>
 /// <typeparam name="TResource"> Shared resource type </typeparam>
 /// <exception cref="InvalidOperationException"> Thrown if service already exists </exception>
 /// <exception cref="ArgumentNullException"> Thrown if <paramref name="resourceFactory" /> is NULL </exception>
 /// <exception cref="InvalidEnumArgumentException"> Thrown if <paramref name="strategy" /> has incorrect value </exception>
 public static IServiceCollection AddAccessQueue <TResource>(this IServiceCollection services, Func <IServiceProvider, TResource> resourceFactory,
                                                             ReuseStrategy strategy, int maxResourceInstances = 1, int maxAttempts = int.MaxValue)
     where TResource : notnull
 {
     if (services.Any(service => service.ImplementationType == typeof(IAccessQueue <TResource>)))
     {
         throw new InvalidOperationException("Service already exists");
     }
     return(services.AddSingleton(services.CreateAccessQueue(resourceFactory, strategy, maxResourceInstances, maxAttempts)));
 }
Esempio n. 2
0
 /// <summary>
 ///     Add <see cref="IPriorityAccessQueue{TResource}" /> and <see cref="IAccessQueue{TResource}" /> services with given shared resources reuse
 ///     <paramref name="strategy" />
 /// </summary>
 /// <param name="services"> Service collection </param>
 /// <param name="strategy"> Conveyor machines reuse strategy <seealso cref="ReuseStrategy" /></param>
 /// <param name="maxResourceInstances"> Max allowed shared resource instances count </param>
 /// <param name="maxPriority"> Max allowed operation priority </param>
 /// <param name="maxAttempts"> Max allowed retry on fail attempts </param>
 /// <typeparam name="TResource"> Shared resource type </typeparam>
 /// <exception cref="InvalidOperationException"> Thrown if service already exists </exception>
 /// <exception cref="InvalidEnumArgumentException"> Thrown if <paramref name="strategy" /> has incorrect value </exception>
 public static IServiceCollection AddPriorityAccessQueue <TResource>(this IServiceCollection services, ReuseStrategy strategy,
                                                                     int maxResourceInstances = 1, int maxPriority = 100, int maxAttempts = int.MaxValue)
     where TResource : notnull
 => services.AddPriorityAccessQueue(provider => provider.GetRequiredService <TResource>(),
                                    strategy,
                                    maxResourceInstances,
                                    maxPriority,
                                    maxAttempts);
Esempio n. 3
0
        /// <summary>
        ///     Create <see cref="IPriorityAccessQueue{TResource}" /> with given shared resources reuse <paramref name="strategy" /> without service
        ///     registration
        /// </summary>
        /// <param name="services"> Service collection </param>
        /// <param name="resourceFactory"> Shared resource factory function </param>
        /// <param name="strategy"> Conveyor machines reuse strategy <seealso cref="ReuseStrategy" /></param>
        /// <param name="maxResourceInstances"> Max allowed shared resource instances count </param>
        /// <param name="maxPriority"> Max allowed operation priority </param>
        /// <param name="maxAttempts"> Max allowed retry on fail attempts </param>
        /// <typeparam name="TResource"> Shared resource type </typeparam>
        /// <exception cref="ArgumentNullException"> Thrown if <paramref name="resourceFactory" /> is NULL </exception>
        /// <exception cref="InvalidEnumArgumentException"> Thrown if <paramref name="strategy" /> has incorrect value </exception>
        public static IPriorityAccessQueue <TResource> CreatePriorityAccessQueue <TResource>(this IServiceCollection services,
                                                                                             Func <IServiceProvider, TResource> resourceFactory, ReuseStrategy strategy, int maxResourceInstances = 1, int maxPriority = 100,
                                                                                             int maxAttempts = int.MaxValue)
            where TResource : notnull
        {
            if (resourceFactory == null)
            {
                throw new ArgumentNullException(nameof(resourceFactory));
            }
            if (strategy != ReuseStrategy.Static && strategy != ReuseStrategy.Reuse && strategy != ReuseStrategy.OneTime)
            {
                throw new InvalidEnumArgumentException(nameof(strategy), (int)strategy, typeof(ReuseStrategy));
            }
            var manager = new PriorityAccessQueueManager <TResource>(maxPriority, maxAttempts);

            services.AddHostedService(provider => new TaskWorker <TResource, int>(provider,
                                                                                  manager,
                                                                                  ProcessorFactory.CreateProcessor <TResource, int>(resourceFactory, strategy, provider, maxResourceInstances)));
            return(manager);
        }
Esempio n. 4
0
 /// <summary>
 /// Creates a new AnalyzerWrapper with the given reuse strategy.
 /// <p>If you want to wrap a single delegate Analyzer you can probably
 /// reuse its strategy when instantiating this subclass:
 /// {@code super(delegate.getReuseStrategy());}.
 /// <p>If you choose different analyzers per field, use
 /// <seealso cref="#PER_FIELD_REUSE_STRATEGY"/>. </summary>
 /// <seealso cref= #getReuseStrategy() </seealso>
 protected internal AnalyzerWrapper(ReuseStrategy reuseStrategy)
     : base(reuseStrategy)
 {
 }
Esempio n. 5
0
 public AnalyzerAnonymousInnerClassHelper(TestBlockPostingsFormat3 outerInstance, ReuseStrategy PER_FIELD_REUSE_STRATEGY)
     : base(PER_FIELD_REUSE_STRATEGY)
 {
     this.OuterInstance = outerInstance;
 }
Esempio n. 6
0
 public AnalyzerWrapperAnonymousInnerClassHelper(FreeTextSuggester outerInstance, ReuseStrategy reuseStrategy, Analyzer other)
     : base(reuseStrategy)
 {
     this.outerInstance = outerInstance;
     this.other         = other;
 }
Esempio n. 7
0
 public AnalyzerWrapperAnonymousInnerClassHelper(AnalyzingInfixSuggester outerInstance, ReuseStrategy reuseStrategy)
     : base(reuseStrategy)
 {
     this.outerInstance = outerInstance;
 }
Esempio n. 8
0
 /// <summary>
 /// Expert: create a new Analyzer with a custom <seealso cref="ReuseStrategy"/>.
 /// <p>
 /// NOTE: if you just want to reuse on a per-field basis, its easier to
 /// use a subclass of <seealso cref="AnalyzerWrapper"/> such as
 /// <a href="{@docRoot}/../analyzers-common/Lucene.Net.Analysis/miscellaneous/PerFieldAnalyzerWrapper.html">
 /// PerFieldAnalyerWrapper</a> instead.
 /// </summary>
 protected Analyzer(ReuseStrategy reuseStrategy)
 {
     this._reuseStrategy = reuseStrategy;
 }
Esempio n. 9
0
 /// <summary>
 /// Expert: create a new Analyzer with a custom <seealso cref="ReuseStrategy"/>.
 /// <p>
 /// NOTE: if you just want to reuse on a per-field basis, its easier to
 /// use a subclass of <seealso cref="AnalyzerWrapper"/> such as
 /// <a href="{@docRoot}/../analyzers-common/Lucene.Net.Analysis/miscellaneous/PerFieldAnalyzerWrapper.html">
 /// PerFieldAnalyerWrapper</a> instead.
 /// </summary>
 public Analyzer(ReuseStrategy reuseStrategy)
 {
     this.ReuseStrategy_Renamed = reuseStrategy;
 }
Esempio n. 10
0
 public AnalyzerWrapperAnonymousInnerClassHelper(TestMockAnalyzer outerInstance, ReuseStrategy getReuseStrategy, Analyzer @delegate)
     : base(getReuseStrategy)
 {
     this.OuterInstance = outerInstance;
     this.@delegate = @delegate;
 }
Esempio n. 11
0
 public AnalyzerWrapperAnonymousInnerClassHelper2(TestMockAnalyzer outerInstance, ReuseStrategy getReuseStrategy, int positionGap, int offsetGap, Analyzer @delegate)
     : base(getReuseStrategy)
 {
     this.OuterInstance = outerInstance;
     this.PositionGap = positionGap;
     this.OffsetGap = offsetGap;
     this.@delegate = @delegate;
 }
Esempio n. 12
0
 public NGramAnalyzer(ReuseStrategy reuseStrategy) : base(reuseStrategy)
 {
 }
Esempio n. 13
0
 /// <summary>
 ///     Add <see cref="IPriorityConveyor{TData, TResult}" /> and <see cref="IConveyor{TData, TResult}" /> services with given conveyor machines
 ///     reuse <paramref name="strategy" />
 /// </summary>
 /// <param name="services"> Service collection </param>
 /// <param name="strategy"> Conveyor machines reuse strategy <seealso cref="ReuseStrategy" /></param>
 /// <param name="maxParallelMachines"> Max allowed parallel conveyor machines </param>
 /// <param name="maxPriority"> Max allowed operation priority </param>
 /// <param name="maxAttempts"> Max allowed retry on fail attempts </param>
 /// <typeparam name="TData"> Input data type </typeparam>
 /// <typeparam name="TResult"> Processing result type </typeparam>
 /// <typeparam name="TConveyorMachine"> Conveyor machine type </typeparam>
 /// <exception cref="InvalidOperationException"> Thrown if service already exists </exception>
 /// <exception cref="InvalidEnumArgumentException"> Thrown if <paramref name="strategy" /> has incorrect value </exception>
 public static IServiceCollection AddPriorityConveyor <TData, TResult, TConveyorMachine>(this IServiceCollection services, ReuseStrategy strategy,
                                                                                         int maxParallelMachines = 1, int maxPriority = 100, int maxAttempts = int.MaxValue)
     where TData : notnull
     where TConveyorMachine : IConveyorMachine <TData, TResult>
 => services.AddPriorityConveyor(provider => provider.GetRequiredService <TConveyorMachine>(),
                                 strategy,
                                 maxParallelMachines,
                                 maxPriority,
                                 maxAttempts);
Esempio n. 14
0
        /// <summary>
        ///     Add <see cref="IPriorityConveyor{TData, TResult}" /> and <see cref="IConveyor{TData, TResult}" /> services with given conveyor machines
        ///     reuse <paramref name="strategy" />
        /// </summary>
        /// <param name="services"> Service collection </param>
        /// <param name="conveyorMachineFactory"> Conveyor machine factory function </param>
        /// <param name="strategy"> Conveyor machines reuse strategy <seealso cref="ReuseStrategy" /></param>
        /// <param name="maxParallelMachines"> Max allowed parallel conveyor machines </param>
        /// <param name="maxPriority"> Max allowed operation priority </param>
        /// <param name="maxAttempts"> Max allowed retry on fail attempts </param>
        /// <typeparam name="TData"> Input data type </typeparam>
        /// <typeparam name="TResult"> Processing result type </typeparam>
        /// <exception cref="InvalidOperationException"> Thrown if service already exists </exception>
        /// <exception cref="ArgumentNullException"> Thrown if <paramref name="conveyorMachineFactory" /> is NULL </exception>
        /// <exception cref="InvalidEnumArgumentException"> Thrown if <paramref name="strategy" /> has incorrect value </exception>
        public static IServiceCollection AddPriorityConveyor <TData, TResult>(this IServiceCollection services,
                                                                              Func <IServiceProvider, IConveyorMachine <TData, TResult> > conveyorMachineFactory, ReuseStrategy strategy, int maxParallelMachines = 1,
                                                                              int maxPriority = 100, int maxAttempts = int.MaxValue)
            where TData : notnull
        {
            if (services.Any(service => service.ImplementationType == typeof(IConveyor <TData, TResult>)))
            {
                throw new InvalidOperationException("Service already exists");
            }
            var conveyor = services.CreatePriorityConveyor(conveyorMachineFactory, strategy, maxParallelMachines, maxPriority, maxAttempts);

            return(services.AddSingleton <IConveyor <TData, TResult> >(conveyor).AddSingleton(conveyor));
        }
Esempio n. 15
0
        /// <summary>
        ///     Create <see cref="IPriorityConveyor{TData, TResult}" /> with given conveyor machines reuse <paramref name="strategy" /> without service
        ///     registration
        /// </summary>
        /// <param name="services"> Service collection </param>
        /// <param name="conveyorMachineFactory"> Conveyor machine factory function </param>
        /// <param name="strategy"> Conveyor machines reuse strategy <seealso cref="ReuseStrategy" /></param>
        /// <param name="maxParallelMachines"> Max allowed parallel conveyor machines </param>
        /// <param name="maxPriority"> Max allowed operation priority </param>
        /// <param name="maxAttempts"> Max allowed retry on fail attempts </param>
        /// <typeparam name="TData"> Input data type </typeparam>
        /// <typeparam name="TResult"> Processing result type </typeparam>
        /// <exception cref="ArgumentNullException"> Thrown if <paramref name="conveyorMachineFactory" /> is NULL </exception>
        /// <exception cref="InvalidEnumArgumentException"> Thrown if <paramref name="strategy" /> has incorrect value </exception>
        public static IPriorityConveyor <TData, TResult> CreatePriorityConveyor <TData, TResult>(this IServiceCollection services,
                                                                                                 Func <IServiceProvider, IConveyorMachine <TData, TResult> > conveyorMachineFactory, ReuseStrategy strategy, int maxParallelMachines = 1,
                                                                                                 int maxPriority = 100, int maxAttempts = int.MaxValue)
            where TData : notnull
        {
            if (conveyorMachineFactory == null)
            {
                throw new ArgumentNullException(nameof(conveyorMachineFactory));
            }
            if (strategy != ReuseStrategy.Static && strategy != ReuseStrategy.Reuse && strategy != ReuseStrategy.OneTime)
            {
                throw new InvalidEnumArgumentException(nameof(strategy), (int)strategy, typeof(ReuseStrategy));
            }
            var manager = new PriorityConveyorManager <TData, TResult>(maxPriority, maxAttempts);

            services.AddHostedService(provider => new TaskWorker <IConveyorMachine <TData, TResult>, int>(provider,
                                                                                                          manager,
                                                                                                          ProcessorFactory.CreateProcessor <IConveyorMachine <TData, TResult>, int>(conveyorMachineFactory,
                                                                                                                                                                                    strategy,
                                                                                                                                                                                    provider,
                                                                                                                                                                                    maxParallelMachines)));
            return(manager);
        }
Esempio n. 16
0
 /// <summary>
 /// </summary>
 /// <param name="originalResult">
 /// Return original string.
 /// Don't use when you are doing segments.
 /// </param>
 public PanGuAnalyzer(bool originalResult, MatchOptions options, MatchParameter parameters, ReuseStrategy reuseStrategy)
     : base(reuseStrategy)
 {
     this.Initialize(originalResult, options, parameters);
 }