public CommandBridge(AgentCore ghost_provider, GhostRequest ghost_request) { RequestQueue = this; ResponseQueue = this; _AgentCore = ghost_provider; _GhostRequest = ghost_request; }
/// <summary> /// Constructor. /// </summary> public RetryRequestExecutionTask(IQueryDistributionService service, IRequestQueue queue, IResponseStorage storage) { _service = service; _queue = queue; _storage = storage; }
//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); }
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); }
/// <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); } }
public QueueCommandHandler(ILogger <QueueCommandHandler> logger, ITwitchClient twitchClient, AppSettings settings, IRequestQueue requestQueue) { this.logger = logger; this.twitchClient = twitchClient; this.settings = settings; this.requestQueue = requestQueue; }
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; } } } } }
public SoulProvider(IRequestQueue peer, IResponseQueue queue, IProtocol protocol) { _Queue = queue; _Protocol = protocol; _Serialize = protocol.GetSerialize(); _Peer = peer; _Peer.OnInvokeMethodEvent += _InvokeMethod; }
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; }
public void Start(IIpcStream ipcStream, IRequestQueue requestQueue) { _ipcStream = ipcStream; _requestQeueue = requestQueue; new Thread(Run) { IsBackground = true }.Start(); }
/// <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); }
/// <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(); }
/// <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(); }
/// <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); }
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); }
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); }
/// <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; }
public ElevatorRequestHandlerFactory( ILogMovementService logger, IWaiterService waiterService, IRequestQueue <ElevatorRequest> requestQueue ) { _logger = logger; _waiterService = waiterService; _requestQueue = requestQueue; }
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; }
public ServerProcessProxy( IServerProcessLauncher serverProcessLauncher, IProtoBufSerializer serializer, IReceiveResponsesThread receiveResponsesThread, IRequestQueue requestQueue, ISendRequestsThread sendRequestsThread) { _serializer = serializer; _receiveResponsesThread = receiveResponsesThread; _requestQueue = requestQueue; _sendRequestsThread = sendRequestsThread; _serverProcessLauncher = serverProcessLauncher; }
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 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; }
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}"); }
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); }
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; }
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); } } } }
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); }
/// <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 }); }
public IntegerCalculatorServiceDisconnectedAgent(IRequestQueue requestQueue) { this.requestQueue = requestQueue; }
/// <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"); }
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(); }