Exemplo n.º 1
0
        private IFlowController CreateFlowController(FlowControlStrategy strategy)
        {
            if (strategy == null)
            {
                throw new ArgumentNullException("FlowControllerFactory.CreateFlowController.strategy");
            }

            IFlowController controller = null;

            switch (strategy.StrategyType)
            {
            case FlowControlStrategyType.TPS:
                controller = new TPSFlowController(strategy);
                break;

            case FlowControlStrategyType.Delay:
                controller = new DelayFlowController(strategy);
                break;

            case FlowControlStrategyType.Sum:
                controller = new SumFlowController(strategy);
                break;

            default:
                break;
            }

            return(controller);
        }
Exemplo n.º 2
0
 public Scheduler(
     [NotNull] IStateSynchronizer synchronizer,
     [NotNull] IFlowController controller,
     [NotNull] IJobWaiter jobWaiter,
     [NotNull] IJobHandler jobHandler)
 {
     this.synchronizer = synchronizer;
     this.controller   = controller;
     this.jobWaiter    = jobWaiter;
     this.jobHandler   = jobHandler;
 }
        /// <exclude />
        public static void CancelFlow(FlowToken flowToken)
        {
            if (flowToken == null)
            {
                throw new ArgumentNullException("flowToken");
            }

            IFlowController flowExecutor = FlowControllerCache.GetFlowController(flowToken, new FlowControllerServicesContainer());

            flowExecutor.CancelFlow(flowToken);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 等待可用
        /// </summary>
        /// <param name="strategy">流控策略</param>
        /// <param name="controller">流控器</param>
        /// <param name="waitTimespan">等待时间</param>
        /// <param name="count">请求次数</param>
        private static void WaitForAvailable(FlowControlStrategy strategy, IFlowController controller, TimeSpan waitTimespan, int count)
        {
            var timespan = waitTimespan;

            if (strategy.StrategyType == FlowControlStrategyType.Delay)
            {
                Thread.Sleep(timespan);
                return;
            }

            while (controller.ShouldThrottle(count, out timespan))
            {
                Thread.Sleep(timespan);
            }
        }
        /// <exclude />
        public static IFlowUiDefinition GetCurrentUiDefinition(FlowToken flowToken, FlowControllerServicesContainer flowControllerServicesContainer)
        {
            if (flowToken == null)
            {
                throw new ArgumentNullException("flowToken");
            }

            IFlowController flowExecutor = FlowControllerCache.GetFlowController(flowToken, flowControllerServicesContainer);

            IFlowUiDefinition flowResult = flowExecutor.GetCurrentUiDefinition(flowToken);

            if (flowResult == null)
            {
                flowResult = new NullFlowUiDefinition();
            }

            return(flowResult);
        }
Exemplo n.º 6
0
        public void TestSetup()
        {
            synchronizer = Substitute.For <IStateSynchronizer>();

            controller = Substitute.For <IFlowController>();
            controller.ShouldStillOperateOn(Arg.Any <SchedulerState>()).Returns(true, true, true, true, false); // 2 iterations

            completedTask1 = Task.FromResult(true);
            completedTask2 = Task.FromResult(true);

            jobWaiter = Substitute.For <IJobWaiter>();
            jobWaiter
            .WaitForNextCompletedJob(Arg.Any <SchedulerState>())
            .Returns(completedTask1, completedTask2);

            jobHandler = Substitute.For <IJobHandler>();

            scheduler = new Hercules.Client.Sink.Scheduler.Scheduler(synchronizer, controller, jobWaiter, jobHandler);
        }
Exemplo n.º 7
0
        public override void Build()
        {
            GetAddOns();

            subBlocks = new List <SimulationBlock>();
            foreach (Transform child in transform)
            {
                SimulationBlock block;
                if (child.gameObject.TryGetComponent(out block))
                {
                    subBlocks.Add(block);
                    block.Build();
                }
            }
            processFlowController = FlowControllerFactory.GetFlowController(ProcessFlowType, subBlocks.ToArray());

            ProcessStartedStream.Subscribe(_ => started  = true);
            ProgressUpdateStream.Subscribe(x => progress = x);
            ProcessCompletedStream.Subscribe(raport => { completed = true; completedCorrectly = raport.CompletedCorrectly; });
        }