protected override void umdfMessageProcessor() { try { logger.Info("Carregando lista de Templates:"); String securityListTemplateID = this.channelConfig.SecurityListTemplateID; listaSecurityListTemplateID = securityListTemplateID.Split(",".ToCharArray()); String mdIncrementalTemplateID = this.channelConfig.MDIncrementalTemplateID; listaMDIncrementalTemplateID = mdIncrementalTemplateID.Split(",".ToCharArray()); String securityStatusTemplateID = this.channelConfig.SecurityStatusTemplateID; listaSecurityStatusTemplateID = securityStatusTemplateID.Split(",".ToCharArray()); String newsTemplateID = this.channelConfig.NewTemplateID; listaNewsTemplateID = newsTemplateID.Split(",".ToCharArray()); foreach (string templateID in listaSecurityListTemplateID) { logger.Info("SecurityList template [" + templateID + "]"); } foreach (string templateID in listaMDIncrementalTemplateID) { logger.Info("MDIncremental template [" + templateID + "]"); } foreach (string templateID in listaSecurityStatusTemplateID) { logger.Info("SecurityStatus template [" + templateID + "]"); } foreach (string templateID in listaNewsTemplateID) { logger.Info("News template [" + templateID + "]"); } long lastLogTicks = 0; while (bKeepRunning) { int seqNum = 0; int tcpSeqNum = 0; if (ProcessamentoMensagensEnabled == false) { lock (ProcessamentoMensagensLockObject) { Monitor.Wait(ProcessamentoMensagensLockObject, 100); continue; } } Message message; if (!queueToProcessor.TryDequeue(out message)) { lock (syncQueueToProcessor) { Monitor.Wait(syncQueueToProcessor, 50); } continue; } //TODO: revisar o algoritmo de conciliacao das filas /* * if ( message == null ) * { * logger.Debug("Timeout aguardando pacote FAST"); * continue; * }*/ // Tratamento de Sequence Reset //if (ConstantesMDSUMDF.FAST_MSGTYPE_SEQUENCERESET.equals(message.GetString("MsgType"))) string msgType; if (message.Template.HasField("MsgType")) { msgType = message.GetString("MsgType"); } else { msgType = message.GetString("MessageType"); } if (msgType.Equals(ConstantesUMDF.FAST_MSGTYPE_SEQUENCERESET)) { lastMsgSeqNum = 0; if (message.Template.HasField("NewSeqNo")) { lastMsgSeqNum = message.GetInt("NewSeqNo"); } logger.InfoFormat("Recebido SequenceReset - lastMsgSeqNum[{0}]", lastMsgSeqNum); seqContador = lastMsgSeqNum; continue; } if (msgType.Equals(ConstantesUMDF.FAST_MSGTYPE_HEARTBEAT)) { logger.Info("Recebeu Hearbeat"); continue; } String sendingTime = message.GetString("SendingTime").Substring(0, 8); // Descarta as mensagens ja recebidas no snapshot if (message.IsDefined("MsgSeqNum")) { seqNum = message.GetInt("MsgSeqNum"); if (seqNum <= lastMsgSeqNum) { if (lastSendingTime.Equals("")) { lastSendingTime = sendingTime; } if (sendingTime.CompareTo(lastSendingTime) > 0) { logger.Info("Virou o dia! [" + sendingTime + "]"); lastMsgSeqNum = seqNum; seqContador = lastMsgSeqNum; } else { logger.Info("Descartando msg [" + seqNum + "]"); continue; } } } /* * while ( this.filaTCPReplay.size() > 0 ) * { * logger.Debug("Mensagens na fila do TCP-Replay: " + this.filaTCPReplay.size()); * * messageTcp = this.filaTCPReplay.take(); * tcpSeqNum = messageTcp.getInt("MsgSeqNum"); * * if ( tcpSeqNum <= this.lastMsgSeqNum ) * { * logger.Error("Descartando msg replay [" + tcpSeqNum + "]"); * continue; * } * * if (tcpSeqNum >= seqNum ) * { * logger.Debug("tcpSeqNum[" + tcpSeqNum + "] >= seqNum[" + seqNum + "] - saindo do loop da fila TCP-Replay"); * break; * } * * logger.Debug("Processando msg replay [" + tcpSeqNum + "]"); * * processMD(messageTcp); * this.lastMsgSeqNum = tcpSeqNum; * } */ if (logger.IsDebugEnabled) { logger.Debug("Processando msg [" + message.ToString() + "]"); } if (MDSUtils.shouldLog(lastLogTicks)) { string convertedmsg = message.ToString(); lastLogTicks = DateTime.UtcNow.Ticks; logger.Info("Tamanho da fila: " + this.queueToProcessor.Count); string msgTruncado = (convertedmsg.Length < 200 ? convertedmsg : convertedmsg.Substring(0, 200)); monitorConfig.channels[channelConfig.ChannelID].dateTimeStartedStopped = "Incr - " + DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + " - " + msgTruncado; monitorConfig.channels[channelConfig.ChannelID].AddDetails( "3) Incremental", DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"), msgTruncado); } if (listaMDIncrementalTemplateID.Any(message.Template.Id.Contains) || listaSecurityListTemplateID.Any(message.Template.Id.Contains)) { List <Message> mensagens = UmdfUtils.splitMessage(message, channelConfig.MarketDepth, ConstantesUMDF.FAST_MSGTYPE_INCREMENTAL_SINGLE); string templateID = ConstantesUMDF.FAST_MSGTYPE_INCREMENTAL_SINGLE; if (listaSecurityListTemplateID.Any(message.Template.Id.Contains)) { templateID = ConstantesUMDF.FAST_MSGTYPE_SECURITYLIST_SINGLE; } foreach (Message newMessage in mensagens) { MDSUtils.EnqueueEventoUmdf(newMessage, newMessage.Template.Id, channelConfig.ChannelID, channelConfig.Segment, templateID, channelConfig.MarketDepth, StreamTypeEnum.STREAM_TYPE_MARKET_INCREMENTAL); } } else if (listaSecurityStatusTemplateID.Any(message.Template.Id.Contains)) { MDSUtils.EnqueueEventoUmdf(message, message.Template.Id, channelConfig.ChannelID, channelConfig.Segment, channelConfig.MarketDepth, StreamTypeEnum.STREAM_TYPE_MARKET_INCREMENTAL); } else if (listaNewsTemplateID.Any(message.Template.Id.Contains)) { MDSUtils.EnqueueEventoUmdfNews(message, message.Template.Id, channelConfig.ChannelID, channelConfig.Segment, ConstantesUMDF.FAST_MSGTYPE_NEWS, StreamTypeEnum.STREAM_TYPE_MARKET_INCREMENTAL); } else { logger.Error("Template ID nao reconhecido [" + message.Template.Id + "]"); } lastMsgSeqNum = seqNum; lastSendingTime = sendingTime; } // main loop logger.Info("Fim"); } catch (Exception ex) { logger.Error("Damn: " + ex.Message, ex); bKeepRunning = false; monitorConfig.channels[channelConfig.ChannelID].RemoveDetails("3) Incremental"); } }