Esempio n. 1
0
 public CommandBridge(AgentCore ghost_provider, GhostRequest ghost_request)
 {
     RequestQueue  = this;
     ResponseQueue = this;
     _AgentCore    = ghost_provider;
     _GhostRequest = ghost_request;
 }
Esempio n. 2
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public RetryRequestExecutionTask(IQueryDistributionService service, IRequestQueue queue,
                                  IResponseStorage storage)
 {
     _service = service;
     _queue   = queue;
     _storage = storage;
 }
Esempio n. 3
0
        //public bool State { get; private set; }

        public PointTimer(IRequestQueue queue, PointAction action, uint duration)
        {
            Action   = action;
            Queue    = queue;
            Duration = duration;
            _timer   = new Timer(x => ExecuteFutureAction(), null, duration * 1000, Timeout.Infinite);
        }
Esempio n. 4
0
        public PointResponse SetPointState(int blockId, int pointId, bool state, uint duration = 0)
        {
            // This method is better because it doesn't need NHibernate

            // Compose Action object
            PointAction action = new PointAction(pointId, state);

            // SetPointState messages do not have a return value because we do not wait for any data back from Wago like we do in GetBlockState.

            // Get RequestQueue, and push data into queue
            IRequestQueue queue = QueueCollection.Current.Item(blockId);

            if (queue == null)
            {
                throw new InvalidOperationException($"Could not find queue with BlockID {blockId}");
            }

            // Send request for block state
            queue.Push(action);

            // Wait a bit for the the response to appear
            PointResponse result = (PointResponse)queue.GetResponse(action.MessageID);

            // When duration is zero only send one message otherwise send the first message and then send another using a Timer.
            if (!result.Error && duration > 0)
            {
                PointAction futureAction = new PointAction(pointId, !action.State);
                HandleFutureAction(queue, action, futureAction, duration);
            }

            return(result);
        }
Esempio n. 5
0
        /// <summary>
        /// Creates a new <see cref="RequestThrottlingMiddleware"/>.
        /// </summary>
        /// <param name="next">The <see cref="RequestDelegate"/> representing the next middleware in the pipeline.</param>
        /// <param name="loggerFactory">The <see cref="ILoggerFactory"/> used for logging.</param>
        /// <param name="options">The <see cref="RequestThrottlingOptions"/> containing the initialization parameters.</param>
        public RequestThrottlingMiddleware(RequestDelegate next, ILoggerFactory loggerFactory, IOptions <RequestThrottlingOptions> options)
        {
            _requestThrottlingOptions = options.Value;

            if (_requestThrottlingOptions.MaxConcurrentRequests == null)
            {
                throw new ArgumentException("The value of 'options.MaxConcurrentRequests' must be specified.", nameof(options));
            }
            if (_requestThrottlingOptions.MaxConcurrentRequests <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(options), "The value of `options.MaxConcurrentRequests` must be a positive integer.");
            }
            if (_requestThrottlingOptions.RequestQueueLimit < 0)
            {
                throw new ArgumentException("The value of 'options.RequestQueueLimit' must be a positive integer.", nameof(options));
            }

            if (_requestThrottlingOptions.OnRejected == null)
            {
                throw new ArgumentException("The value of 'options.OnRejected' must not be null.", nameof(options));
            }

            _next   = next;
            _logger = loggerFactory.CreateLogger <RequestThrottlingMiddleware>();

            if (_requestThrottlingOptions.ServerAlwaysBlocks)
            {
                // note: this option for testing only. Blocks all requests from entering the server.
                _requestQueue = new TailDrop(0, _requestThrottlingOptions.RequestQueueLimit);
            }
            else
            {
                _requestQueue = new TailDrop(_requestThrottlingOptions.MaxConcurrentRequests.Value, _requestThrottlingOptions.RequestQueueLimit);
            }
        }
Esempio n. 6
0
 public QueueCommandHandler(ILogger <QueueCommandHandler> logger, ITwitchClient twitchClient, AppSettings settings, IRequestQueue requestQueue)
 {
     this.logger       = logger;
     this.twitchClient = twitchClient;
     this.settings     = settings;
     this.requestQueue = requestQueue;
 }
Esempio n. 7
0
        protected virtual void InjectMoves(LoadContainer database, BatchName batchName, IEnumerable <LoadEntity> mailboxes, bool throwIfNotValid)
        {
            IRequestQueue          injectorQueue         = this.queueManager.GetInjectionQueue((DirectoryDatabase)database.DirectoryObject);
            IOperationRetryManager operationRetryManager = LoadBalanceOperationRetryManager.Create(this.logger);

            using (IEnumerator <LoadEntity> enumerator = mailboxes.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    LoadEntity mailbox = enumerator.Current;
                    if (mailbox.DirectoryObject == null)
                    {
                        this.logger.Log(MigrationEventType.Warning, "Not injecting move for {0} because its DirectoryObject is null", new object[]
                        {
                            mailbox
                        });
                    }
                    else
                    {
                        OperationRetryManagerResult operationRetryManagerResult = operationRetryManager.TryRun(delegate
                        {
                            DirectoryObject directoryObject = mailbox.DirectoryObject;
                            ConstraintValidationResult constraintValidationResult = database.Constraint.Accept(mailbox);
                            if (constraintValidationResult.Accepted)
                            {
                                database.CommittedLoad += mailbox.ConsumedLoad;
                                if (directoryObject.SupportsMoving)
                                {
                                    DirectoryObject directoryObject2 = database.DirectoryObject;
                                    IRequest request = directoryObject.CreateRequestToMove(directoryObject2.Identity, batchName.ToString(), this.logger);
                                    injectorQueue.EnqueueRequest(request);
                                    return;
                                }
                                if (throwIfNotValid)
                                {
                                    throw new ObjectCannotBeMovedException(mailbox.DirectoryObjectIdentity.ObjectType.ToString(), mailbox.DirectoryObjectIdentity.ToString());
                                }
                            }
                            else
                            {
                                this.logger.Log(MigrationEventType.Warning, "Not injecting move for {0} because it violates the target database constraints: {1}", new object[]
                                {
                                    mailbox,
                                    constraintValidationResult
                                });
                                if (throwIfNotValid)
                                {
                                    constraintValidationResult.Constraint.ValidateAccepted(mailbox);
                                }
                            }
                        });
                        if (!operationRetryManagerResult.Succeeded && throwIfNotValid)
                        {
                            throw operationRetryManagerResult.Exception;
                        }
                    }
                }
            }
        }
Esempio n. 8
0
 public SoulProvider(IRequestQueue peer, IResponseQueue queue, IProtocol protocol)
 {
     _Queue     = queue;
     _Protocol  = protocol;
     _Serialize = protocol.GetSerialize();
     _Peer      = peer;
     _Peer.OnInvokeMethodEvent += _InvokeMethod;
 }
Esempio n. 9
0
 public ReplayIdRequestHandler(ILogger <ReplayIdRequestHandler> logger, IRewardRequestFactory requestFactory, ITwitchClient twitchClient, IRequestQueue queue, AppSettings settings)
 {
     this.logger         = logger;
     this.requestFactory = requestFactory;
     this.twitchClient   = twitchClient;
     this.queue          = queue;
     this.settings       = settings;
 }
Esempio n. 10
0
 public void Start(IIpcStream ipcStream, IRequestQueue requestQueue)
 {
     _ipcStream     = ipcStream;
     _requestQeueue = requestQueue;
     new Thread(Run)
     {
         IsBackground = true
     }.Start();
 }
Esempio n. 11
0
 /// <summary>
 /// This method initializes the RequestManager for request dispatching.
 /// </summary>
 /// <typeparam name="TRequestDispatcher">The concrete type of an <see cref="IRequestDispatcher"/>.</typeparam>
 /// <param name="theRequestQueue">Queue for the pending requests.</param>
 /// <param name="theDeadLetterQueue">Queue for the failures.</param>
 /// <param name="theConnectionMonitor">IConnectionMonitor for connectivity events and info.</param>
 /// <param name="theEndpointCatalog">Catalog to get the Endpoint especific information for the dispatching.</param>
 public void Initialize <TRequestDispatcher>(
     IRequestQueue theRequestQueue,
     IRequestQueue theDeadLetterQueue,
     IConnectionMonitor theConnectionMonitor,
     IEndpointCatalog theEndpointCatalog) where TRequestDispatcher : IRequestDispatcher, new()
 {
     Initialize(theRequestQueue, theDeadLetterQueue, theConnectionMonitor, new TRequestDispatcher(),
                theEndpointCatalog);
 }
Esempio n. 12
0
 /// <summary>
 /// 构造函数
 /// </summary>
 private RequestManager()
 {
     this.requestQueue      = new MemoryRequestQueue();
     this.deadLetterQueue   = new MemoryRequestQueue();
     this.connectionManager = new ConnectionManager(new WinNetDetectionStrategy(), 1);
     this.dispatchCommands  = new Queue <Command>();
     this.requestDispatcher = new OfflineRequestDispatcher();
     this.connectionManager.Start();
 }
Esempio n. 13
0
        /// <summary>
        /// 构造函数
        /// </summary>
		private RequestManager()
		{
            this.requestQueue = new MemoryRequestQueue();
            this.deadLetterQueue = new MemoryRequestQueue();
            this.connectionManager = new ConnectionManager(new WinNetDetectionStrategy(), 1);
            this.dispatchCommands = new Queue<Command>();
            this.requestDispatcher = new OfflineRequestDispatcher();
            this.connectionManager.Start();
		}
Esempio n. 14
0
 /// <summary>
 /// This method initializes the RequestManager for request dispatching with all the configurable elements.
 /// </summary>
 /// <param name="theRequestQueue">Queue for the pending requests.</param>
 /// <param name="theDeadLetterQueue">Queue for the failures.</param>
 /// <param name="theConnectionMonitor">IConnectionMonitor for connectivity events and info.</param>
 /// <param name="theEndpointCatalog">Catalog to get the Endpoint especific information for the dispatching.</param>
 public void Initialize(
     IRequestQueue theRequestQueue,
     IRequestQueue theDeadLetterQueue,
     IConnectionMonitor theConnectionMonitor,
     IEndpointCatalog theEndpointCatalog)
 {
     Initialize <RequestDispatcher>(theRequestQueue, theDeadLetterQueue, theConnectionMonitor,
                                    theEndpointCatalog);
 }
Esempio n. 15
0
        public void ProcessRebalanceRequest(BandMailboxRebalanceData rebalanceRequest)
        {
            AnchorUtil.ThrowOnNullArgument(rebalanceRequest, "rebalanceRequest");
            BandRebalanceRequest request         = new BandRebalanceRequest(rebalanceRequest, this.clientFactory, this.logger);
            LoadContainer        sourceDatabase  = rebalanceRequest.SourceDatabase;
            IRequestQueue        processingQueue = this.GetProcessingQueue(sourceDatabase);

            processingQueue.EnqueueRequest(request);
        }
Esempio n. 16
0
        private void EnqueueNewRequest(IRequestQueue requestQueue, string endpoint, string tag, int stamps)
        {
            Request request = new Request();

            request.Endpoint        = endpoint;
            request.Behavior.Tag    = tag;
            request.Behavior.Stamps = stamps;
            requestQueue.Enqueue(request);
        }
Esempio n. 17
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public QueryDistributionService(IStatisticsStorage statisticsStorage, IResponseStorage responseStorage,
                                 IOptions <BalancerConfiguration> options, IQueryExecutor queryExecutor, IRequestQueue queue, IServerDecider decider)
 {
     _statisticsStorage = statisticsStorage;
     _queryExecutor     = queryExecutor;
     _responseStorage   = responseStorage;
     _queue             = queue;
     _configuration     = options.Value;
     _serverDecider     = decider;
 }
Esempio n. 18
0
 public ElevatorRequestHandlerFactory(
     ILogMovementService logger,
     IWaiterService waiterService,
     IRequestQueue <ElevatorRequest> requestQueue
     )
 {
     _logger        = logger;
     _waiterService = waiterService;
     _requestQueue  = requestQueue;
 }
Esempio n. 19
0
        public SoulProvider(IRequestQueue peer, IResponseQueue queue, IProtocol protocol)
        {
            _IdLandlord = new IdLandlord();
            _Queue      = queue;
            _Protocol   = protocol;

            _EventProvider = protocol.GetEventProvider();

            _Serializer              = protocol.GetSerialize();
            _Peer                    = peer;
            _Peer.InvokeMethodEvent += _InvokeMethod;
        }
Esempio n. 20
0
 public ServerProcessProxy(
   IServerProcessLauncher serverProcessLauncher,
   IProtoBufSerializer serializer,
   IReceiveResponsesThread receiveResponsesThread,
   IRequestQueue requestQueue,
   ISendRequestsThread sendRequestsThread) {
   _serializer = serializer;
   _receiveResponsesThread = receiveResponsesThread;
   _requestQueue = requestQueue;
   _sendRequestsThread = sendRequestsThread;
   _serverProcessLauncher = serverProcessLauncher;
 }
Esempio n. 21
0
 public Engine(ISpider spider, IScheduler scheduler, IDownloader downloader, ILoggerFactory factory, ItemPipeline[] piplelines = null)
 {
     this._spider        = spider;
     this._scheduler     = scheduler;
     this._downloader    = downloader;
     this._logger        = factory.Create("engine");
     this._startRequests = new MemoryQueue();
     this.Runing         = false;
     this._actives       = new ConcurrentBag <Request>();
     this._piplelines    = piplelines;
     this._uncompleted   = new ConcurrentBag <Request>();
 }
 public ServerProcessProxy(
     IServerProcessLauncher serverProcessLauncher,
     IProtoBufSerializer serializer,
     IReceiveResponsesThread receiveResponsesThread,
     IRequestQueue requestQueue,
     ISendRequestsThread sendRequestsThread)
 {
     _serializer             = serializer;
     _receiveResponsesThread = receiveResponsesThread;
     _requestQueue           = requestQueue;
     _sendRequestsThread     = sendRequestsThread;
     _serverProcessLauncher  = serverProcessLauncher;
 }
Esempio n. 23
0
 public ElevatorSystem(
     IElevatorRequestHandlerFactory requestHandlerFactory,
     IWaiterService waiterService,
     IRequestQueue <ElevatorRequest> queue
     )
 {
     _workers               = new List <Task>();
     _requestsHandler       = new List <ElevatorRequestHandler>();
     _requests              = new List <ElevatorRequest>();
     _requestHandlerFactory = requestHandlerFactory;
     _waiterService         = waiterService;
     _queue = queue;
 }
Esempio n. 24
0
        private async Task RqTestDefaultWorkflow(IRequestQueue rq, long crawlId)
        {
            TestContext.WriteLine($"CrawlId = {crawlId}");

            var sw = new Stopwatch();

            sw.Start();

            // Enqueue 3 Urls
            await rq.EnqueueAsync(crawlId, new[] { "j1", "j2", "j3" });

            //Dequeue and finish 1
            await foreach (var d in rq.DequeueAsync(crawlId, 1, DateTimeOffset.UtcNow.AddSeconds(10)))
            {
                TestContext.WriteLine($"[{crawlId}] rocessing... {d}");
                await Task.Delay(200);

                await rq.DeleteAsync(crawlId, d);
            }

            // Dequeue 1 and fail to finish in time
            await foreach (var d in rq.DequeueAsync(crawlId, 1, DateTimeOffset.UtcNow.AddSeconds(-1)))
            {
                TestContext.WriteLine($"[{crawlId}] Failing... {d}");
                await Task.Delay(200);
            }

            // Enqueue 2 more
            rq.Enqueue(crawlId, new[] { "j4", "j5" });

            // Dequeue up to 10
            var d1 = rq.Dequeue(crawlId, 10, DateTimeOffset.UtcNow.AddSeconds(10));

            foreach (var d in d1)
            {
                TestContext.WriteLine($"[{crawlId}] Processing... {d}");
            }
            rq.Delete(crawlId, d1);

            // that should hav been 3 from the queue and 1 from the failed jobs
            Assert.AreEqual(4, d1.Count);


            // Queue should be empty
            var d2 = rq.Dequeue(crawlId, 10, DateTimeOffset.UtcNow.AddSeconds(10));

            Assert.AreEqual(0, d2.Count, message: $"[{crawlId}] Unexpected: {string.Join(",", d2)}");

            sw.Stop();
            TestContext.WriteLine($"[{crawlId}] ElapsedMilliseconds: {sw.ElapsedMilliseconds}");
        }
Esempio n. 25
0
 public ServerProcessProxy(
     IServerProcessLauncher serverProcessLauncher,
     IProtoBufSerializer serializer,
     IReceiveResponsesThread receiveResponsesThread,
     IRequestQueue requestQueue,
     ISendRequestsThread sendRequestsThread)
 {
     _serializer             = serializer;
     _receiveResponsesThread = receiveResponsesThread;
     _requestQueue           = requestQueue;
     _sendRequestsThread     = sendRequestsThread;
     _serverProcessLauncher  = serverProcessLauncher;
     _createProcessTask      = new Lazy <Task>(CreateProcessLazyWorker, LazyThreadSafetyMode.ExecutionAndPublication);
 }
Esempio n. 26
0
        public SoulProvider(IRequestQueue peer, IResponseQueue queue, IProtocol protocol)
        {
            _WaitValues  = new Dictionary <long, IValue>();
            _Souls       = new System.Collections.Concurrent.ConcurrentDictionary <long, SoulProxy>();
            _EventFilter = new Queue <byte[]>();
            _IdLandlord  = new IdLandlord();
            _Queue       = queue;
            _Protocol    = protocol;

            _EventProvider = protocol.GetEventProvider();

            _Serializer              = protocol.GetSerialize();
            _Peer                    = peer;
            _Peer.InvokeMethodEvent += _InvokeMethod;
        }
Esempio n. 27
0
        private void HandleFutureAction(IRequestQueue queue, PointAction action, PointAction futureAction, uint duration)
        {
            //send the future message

            //cancel any existing timers for this point
            if (FutureActionManager.Current.TryRemove(action.PointID, out PointTimer pointTimer))
            {
                pointTimer.Cancel(false);
            }

            //create a new PointTimer for this point
            pointTimer = new PointTimer(queue, futureAction, duration);

            //keep track of this timer in case it is cancelled
            FutureActionManager.Current.TryAdd(pointTimer);
        }
        private void BeginProcessingMailbox(DirectoryMailbox mailbox)
        {
            IRequestQueue requestQueue = (mailbox.Parent != null) ? this.context.QueueManager.GetProcessingQueue(mailbox.Parent) : this.context.QueueManager.MainProcessingQueue;

            string[] source = LoadBalanceADSettings.Instance.Value.ExcludedMailboxProcessors.Split(new char[]
            {
                ','
            });
            IList <MailboxProcessor> list = this.processors(this.context.QueueManager) ?? ((IList <MailboxProcessor>)Array <MailboxProcessor> .Empty);

            foreach (MailboxProcessor mailboxProcessor in list)
            {
                if (source.Contains(mailboxProcessor.Name))
                {
                    this.context.Logger.LogVerbose("Skipping processor {0} because it is disabled.", new object[]
                    {
                        mailboxProcessor.Name
                    });
                }
                else if (!mailboxProcessor.ShouldProcess(mailbox))
                {
                    this.context.Logger.LogVerbose("Processor {0} doesn't want to process the mailbox, ignored.", new object[]
                    {
                        mailboxProcessor.Name
                    });
                }
                else if (mailboxProcessor.RequiresRunspace)
                {
                    requestQueue.EnqueueRequest(new ProcessMailboxRequest(mailbox, mailboxProcessor, this.context.Logger, this.context.CmdletPool));
                }
                else
                {
                    using (OperationTracker.Create(this.context.Logger, "Applying processor {0} to mailbox {1}.", new object[]
                    {
                        mailboxProcessor.GetType().FullName,
                        mailbox.Identity
                    }))
                    {
                        mailboxProcessor.ProcessMailbox(mailbox, null);
                    }
                }
            }
        }
Esempio n. 29
0
        public BlockResponse GetBlockState(int blockId)
        {
            // Compose Action object
            BlockAction action = new BlockAction(blockId);

            // Get RequestQueue, and push data into queue
            IRequestQueue queue = QueueCollection.Current.Item(blockId);

            if (queue == null)
            {
                throw new InvalidOperationException($"Could not find queue with BlockID {blockId}");
            }

            // Send request for block state
            queue.Push(action);

            // Wait a bit for the the response to appear
            BlockResponse result = (BlockResponse)queue.GetResponse(action.MessageID);

            return(result);
        }
Esempio n. 30
0
        /// <summary>
        /// This method initializes the RequestManager for request dispatching with all the configurable elements.
        /// </summary>
        /// <param name="theRequestQueue">Queue for the pending requests.</param>
        /// <param name="theDeadLetterQueue">Queue for the failures.</param>
        /// <param name="theConnectionMonitor">IConnectionMonitor for connectivity events and info.</param>
        /// <param name="theRequestDispatcher">Dispatcher to be used by the manager.</param>
        /// <param name="theEndpointCatalog">Catalog to get the Endpoint especific information for the dispatching.</param>
        private void Initialize(
            IRequestQueue theRequestQueue,
            IRequestQueue theDeadLetterQueue,
            IConnectionMonitor theConnectionMonitor,
            IRequestDispatcher theRequestDispatcher,
            IEndpointCatalog theEndpointCatalog)
        {
            Guard.ArgumentNotNull(theRequestQueue, "requestQueue");
            Guard.ArgumentNotNull(theDeadLetterQueue, "deadLetterQueue");
            Guard.ArgumentNotNull(theConnectionMonitor, "connectionMonitor");
            Guard.ArgumentNotNull(theRequestDispatcher, "requestDispatcher");
            Guard.ArgumentNotNull(theEndpointCatalog, "endpointCatalog");

            requestQueue      = theRequestQueue;
            requestDispatcher = theRequestDispatcher;
            endpointCatalog   = theEndpointCatalog;
            deadLetterQueue   = theDeadLetterQueue;
            connectionMonitor = theConnectionMonitor;
            dispatchCommands  = new Queue <Command>();
            dispatcherRunning = false;
        }
 public ElevatorSystemWithTestData(
     IElevatorRequestHandlerFactory requestHandlerFactory,
     IWaiterService waiterService,
     IRequestQueue <ElevatorRequest> queue
     ) : base(requestHandlerFactory, waiterService, queue)
 {
     AddElevator(new Elevator {
         Name = "Aufzug 1"
     });
     AddElevator(new Elevator {
         Name = "Aufzug 2"
     });
     AddRequest(new ElevatorRequest {
         FromFloor = 0, ToFloor = 5
     });
     AddRequest(new ElevatorRequest {
         FromFloor = 10, ToFloor = 0
     });
     AddRequest(new ElevatorRequest {
         FromFloor = 5, ToFloor = 0
     });
 }
Esempio n. 32
0
 public IntegerCalculatorServiceDisconnectedAgent(IRequestQueue requestQueue)
 {
     this.requestQueue = requestQueue;
 }
Esempio n. 33
0
 /// <summary>
 /// 采用db4o数据库作为缓存队列存储方案
 /// </summary>
 /// <param name="databaseService">db4o数据库服务</param>
 public void Initilize(IDb4oDatabaseService databaseService)
 {
     this.requestQueue = new db4oRequestQueue(databaseService, "OfflineProxy.Requests.yap");
     this.deadLetterQueue = new db4oRequestQueue(databaseService, "OfflineProxy.DeadRequests.yap");
 }
Esempio n. 34
0
 public Agent(IRequestQueue requestQueue)
 {
     this.requestQueue = requestQueue;
 }
 public CoreThreadRequestHandler(IRequestQueue requester)
 {
     _Requester = requester;
 }
 public void Start(IIpcStream ipcStream, IRequestQueue requestQueue)
 {
     _ipcStream = ipcStream;
       _requestQeueue = requestQueue;
       new Thread(Run) {IsBackground = true}.Start();
 }