/// <summary> /// 按优先级获得命令 /// </summary> /// <param name="priority"></param> /// <returns></returns> public byte[] Get(CommandPriority priority) { if (this._CmdCache.Count <= 0) { return(new byte[] {}); } rwLock.AcquireReaderLock(lockTimeOut); try { byte[] data = new byte[] { }; if (priority == CommandPriority.Normal) { data = this._CmdCache[0].CommandBytes; this._CmdCache.RemoveAt(0); } else if (priority == CommandPriority.High) { ICommand cmd = this._CmdCache.FirstOrDefault(c => c.Priority == CommandPriority.High); if (cmd != null) { data = cmd.CommandBytes; this._CmdCache.Remove(cmd); } } return(data); } finally { rwLock.ReleaseReaderLock(); } }
public CommandMapping(string name, string @class, bool enabled = true, CommandPriority priority = CommandPriority.Normal) { Name = name; Enabled = enabled; Class = @class; Priority = priority; }
public CommandModel Push <TCommand>(TCommand command, CommandPriority priority = CommandPriority.Normal, CommandTrigger trigger = CommandTrigger.Unspecified) where TCommand : Command { Ensure.That(command, () => command).IsNotNull(); _logger.Trace("Publishing {0}", command.Name); _logger.Trace("Checking if command is queued or started: {0}", command.Name); var existingCommands = QueuedOrStarted(command.Name); var existing = existingCommands.SingleOrDefault(c => CommandEqualityComparer.Instance.Equals(c.Body, command)); if (existing != null) { _logger.Trace("Command is already in progress: {0}", command.Name); return(existing); } var commandModel = new CommandModel { Name = command.Name, Body = command, QueuedAt = DateTime.UtcNow, Trigger = trigger, Priority = priority, Status = CommandStatus.Queued }; _logger.Trace("Inserting new command: {0}", commandModel.Name); _repo.Insert(commandModel); _commandQueue.Add(commandModel); return(commandModel); }
public async Task Patrol(Vector2D[] newPosition, CommandPriority prio) { if (prio > CurrentPriority) { Positions = newPosition.Take(1); // take only the first position } await Task.CompletedTask; }
public RoutedFromDescriptor On(string listenEndpoint, CommandPriority priority = CommandPriority.Normal) { if (listenEndpoint.Length == 0) { throw new ArgumentException("Endpoint list is empty", "listenEndpoint"); } return(new RoutedFromDescriptor(m_Registration, m_Types, listenEndpoint, priority)); }
public GenericDbCommand(string sourceName, CommandPriority priority, string queryId, string datbase, string table) { SourceName = sourceName; Priority = priority; QueryId = queryId; _MyDb = datbase; _MyTable = table; }
public LocalBoundedContextRegistration RoutedFrom(string publishEndpoint, CommandPriority priority = CommandPriority.Normal) { m_Registration.AddCommandsRoute(m_Types, publishEndpoint, priority); foreach (var endpoint in m_ListenEndpoints) { m_Registration.AddSubscribedCommands(m_Types, endpoint.Key, endpoint.Value); } return(m_Registration); }
public RoutedFromDescriptor On(string listenEndpoint, CommandPriority priority = CommandPriority.Normal) { if (string.IsNullOrEmpty(listenEndpoint)) { throw new ArgumentException("Endpoint is empty", "listenEndpoint"); } m_ListenEndpoints[listenEndpoint] = priority; return(this); }
public CommandModel Push(string commandName, DateTime?lastExecutionTime, CommandPriority priority = CommandPriority.Normal, CommandTrigger trigger = CommandTrigger.Unspecified) { dynamic command = GetCommand(commandName); command.LastExecutionTime = lastExecutionTime; command.Trigger = trigger; return(Push(command, priority, trigger)); }
public void Add(string cmdkey, byte[] cmdbytes, CommandPriority priority) { rwLock.AcquireWriterLock(lockTimeOut); try { Command cmd = new Command(cmdkey, cmdbytes, priority); this._CmdCache.Add(cmd); } finally { rwLock.ReleaseWriterLock(); } }
public void AddCommandsRoute(IEnumerable <Type> types, string endpoint, CommandPriority priority) { foreach (var type in types) { if (m_CommandRoutes.ContainsKey(Tuple.Create(type, priority))) { throw new ConfigurationErrorsException(string.Format("Route for command '{0}' with priority {1} is already registered", type, priority)); } m_CommandRoutes.Add(Tuple.Create(type, priority), endpoint); } }
public void SendCommand <T>(T command, string boundedContext, CommandPriority priority = CommandPriority.Normal) { /* var context = BoundedContexts.FirstOrDefault(bc => bc.Name == boundedContext); * if (context == null) * throw new ArgumentException(string.Format("bound context {0} not found",boundedContext),"boundedContext"); * string route; * if (!context.CommandRoutes.TryGetValue(Tuple.Create(typeof (T),priority), out route)) * { * throw new InvalidOperationException(string.Format("bound context '{0}' does not support command '{1}' with priority {2}",boundedContext,typeof(T),priority)); * } * m_MessagingEngine.Send(command, m_EndpointResolver.Resolve(context.LocalBoundedContext, boundedContext, route, typeof(T), RouteType.Commands), route);*/ SendCommand((object)command, boundedContext, priority); }
public void Dispatch(object command, CommandPriority priority, AcknowledgeDelegate acknowledge, Endpoint commandOriginEndpoint, string route) { Func <object, Endpoint, string, CommandHandlingResult> handler; if (!m_Handlers.TryGetValue(command.GetType(), out handler)) { m_Logger.Warn("Failed to handle command {0} in bound context {1}, no handler was registered for it", command, m_BoundedContext); acknowledge(m_FailedCommandRetryDelay, false); return; } m_TaskFactories[priority].StartNew(() => handle(command, acknowledge, handler, commandOriginEndpoint, route)); }
private CommandPriority _GetHighestNonEmptyPriority() { CommandPriority priority = _commandsToExecute.Count > 0 ? CommandPriority.Normal : CommandPriority.Lowest; foreach (KeyValuePair <CommandPriority, ThreadSafeMultiQueue <string, IDBCommand> > keyValuePair in _queues) { if (keyValuePair.Key < priority && !keyValuePair.Value.IsEmpty()) { priority = keyValuePair.Key; } } return(priority); }
public override void UpdateForEachInputs(IList <Tuple <string, string> > updates) { if (updates == null) { return; } foreach (var t in updates) { if (t.Item1 == CommandFileName) { CommandFileName = t.Item2; } else if (t.Item1 == CommandPriority.ToString()) { CommandPriority = (ProcessPriorityClass)Enum.Parse(typeof(ProcessPriorityClass), t.Item2, true); } } }
/// <summary> /// Safely remove 1 by 1 commands from the queue and execute it /// </summary> public void Execute() { try { while (Count > 0) //as long as not all commands are in DB { CommandPriority priority = _GetHighestNonEmptyPriority(); ThreadSafeMultiQueue <string, IDBCommand> multiQueue = _queues[priority]; _ExecuteNonFilteredQueue(multiQueue, priority); } } catch (Exception e) { GatLogger.Instance.AddMessage(string.Format("DB Command failed with following message {0}\n{1}", e.Message, e.StackTrace)); ErrorEventHandler(e); throw; } }
public void SendCommand(object command, string boundedContext, CommandPriority priority = CommandPriority.Normal) { if (command == null) { throw new ArgumentNullException("command"); } var context = BoundedContexts.FirstOrDefault(bc => bc.Name == boundedContext); if (context == null) { throw new ArgumentException(string.Format("bound context {0} not found", boundedContext), "boundedContext"); } string route; if (!context.CommandRoutes.TryGetValue(Tuple.Create(command.GetType(), priority), out route)) { throw new InvalidOperationException(string.Format("bound context '{0}' does not support command '{1}' with priority {2}", boundedContext, command.GetType(), priority)); } m_MessagingEngine.Send(command, m_EndpointResolver.Resolve(context.LocalBoundedContext, boundedContext, route, command.GetType(), RouteType.Commands), route); }
public void Register(IRocketCommand command, string alias, CommandPriority priority) { string name = command.Name; if (alias != null) { name = alias; } string className = getCommandIdentity(command, name); //Add CommandMapping if not already existing /*if(commandMappings.Instance.CommandMappings.Where(m => m.Class == className && m.Name == name).FirstOrDefault() == null){ * commandMappings.Instance.CommandMappings.Add(new CommandMapping(name,className,true,priority)); * }*/ var mappings = commandMappings.Instance.CommandMappings; foreach (var map in mappings) { if (map.Class == className && map.Name == name) { goto BREAK; } } mappings.Add(new CommandMapping(name, className, true, priority)); BREAK: checkDuplicateCommandMappings(className); foreach (CommandMapping mapping in mappings) { if (mapping.Enabled && mapping.Class == className) { commands.Add(new RegisteredRocketCommand(mapping.Name.ToLower(), command)); Logging.Logger.Log("[registered] /" + mapping.Name.ToLower() + " (" + mapping.Class + ")", ConsoleColor.Green); } } }
public void AddSubscribedCommands(IEnumerable <Type> types, string endpoint, CommandPriority priority) { foreach (var type in types) { if (m_EventsSubscriptions.ContainsKey(type)) { throw new ConfigurationErrorsException(string.Format("Can not register {0} as command in bound context {1}, it is already registered as event", type, m_Name)); } if (m_EventsSubscriptions.ContainsValue(endpoint)) { throw new ConfigurationErrorsException(string.Format("Can not register endpoint '{0}' as events endpoint in bound context {1}, it is already registered as commands endpoint", endpoint, m_Name)); } CommandSubscription commandSubscription = m_CommandsSubscriptions.FirstOrDefault(t => t.Endpoint == endpoint); if (commandSubscription == null) { commandSubscription = new CommandSubscription { Endpoint = endpoint }; m_CommandsSubscriptions.Add(commandSubscription); } commandSubscription.Types[type] = priority; } }
/// <summary> /// 3 priority 3 Queue /// </summary> /// <param name="item"></param> /// <param name="priority"></param> public void Enqueue(BaseCommand item, CommandPriority priority = CommandPriority.Normal) { lock (m_lock) { switch (priority) { case CommandPriority.High: m_QueueArray[0].Enqueue(item); break; case CommandPriority.AboveNormal: m_QueueArray[1].Enqueue(item); break; case CommandPriority.Normal: m_QueueArray[2].Enqueue(item); break; default: m_QueueArray[2].Enqueue(item); break; } } }
public override IList <DsfForEachItem> GetForEachInputs() { return(GetForEachItems(CommandFileName, CommandPriority.ToString())); }
public CommandKeyword(CommandPriority priority, IKeywordFilter filter) { Priority = priority; Filter = filter; }
/// <summary> /// Filters and executes the commands until multi queue getting full again and or command is new is queue /// </summary> private void _FilterAndExecuteCommands(ThreadSafeMultiQueue <string, IDBCommand> multiQueue, CommandPriority currentPriority) { bool queueTooLoaded = multiQueue.Count() > ct_queueThreshold; while (_commandsToExecute.Count > 0) { if (_GetHighestNonEmptyPriority() < currentPriority) { return; } if (queueTooLoaded) { //if filtering process began when queue was too loaded or there is blocking command in queue //all commands that passed in the filter will be executed regardless of //how much time they were in queue _ExecuteCommand(_commandsToExecute.Dequeue()); } else if (_MinimumCommandQueueTime.HasValue) { //If commands was not in queue for enough time the execution process is halted IDBCommand nextCommand = _commandsToExecute.Peek(); DateTime filterThreshold = nextCommand.GetQueueInsertionTime() + _MinimumCommandQueueTime.Value; if (_lastFilterEndTime < filterThreshold) { return; } _ExecuteCommand(_commandsToExecute.Dequeue()); } else { throw new GatDataBaseException( "filterAndExecuteCommands was called when queueTooLoaded = false and !parameters.MinimumCommandQueueTime.HasValue"); } //If queue is getting loaded the execution process is halted if (multiQueue.Count() >= ct_queueThreshold) { return; } } }
private void _ExecuteNonFilteredQueue(ThreadSafeMultiQueue <string, IDBCommand> multiQueue, CommandPriority currentPriority) { while (multiQueue.Count() > 0) { foreach (IDBCommand command in multiQueue) { _ExecuteCommand(command); if (_GetHighestNonEmptyPriority() < currentPriority) { break; } } } GatLogger.Instance.AddMessage("DB Queue is empty. You can exit at anytime.", LogMode.LogAndScreen); }
public Task Scout(Vector2D[] newPos, CommandPriority commandedPrio) { throw new NotImplementedException(); }
public void SendCommand(object command, string boundedContext, CommandPriority priority = CommandPriority.Normal) { CqrsEngine.SendCommand(command, boundedContext, priority); }
protected void RegisterKeyword(CommandPriority priority, IKeywordFilter keywordFilter) { keywords.Add(new CommandKeyword(priority, keywordFilter)); }
public RemoteBoundedContextRegistration On(string publishEndpoint, CommandPriority priority = CommandPriority.Normal) { m_Registration.AddCommandsRoute(m_Types, publishEndpoint, priority); return(m_Registration); }
public ScheduledTask() { Priority = CommandPriority.Low; }
protected void RegisterKeyword(CommandPriority priority, string[] prefixes, string word, string[] surfixes) { RegisterKeyword(priority, new FixAsLikeKeywordFilter(word, prefixes, surfixes)); }