public virtual void OnMessage(QuickFix.FIX44.ApplicationRawDataReporting message, SessionID session) { try { //logger.InfoFormat("RawDataLength[{0}] getLength[{1}]", message.RawDataLength, message.RawData.getLength()); UmdfUtils.dumpFastData(UmdfUtils.ENCODING.GetBytes(message.RawData.getValue()), 0, Int32.Parse(message.RawDataLength.ToString())); string[] quebraApplReqID = message.ApplReqID.ToString().Split("|".ToCharArray()); string applReqID = quebraApplReqID[0]; string sessionIDResponse = quebraApplReqID[1]; // Retorna o applReqID original message.Set(new QuickFix.Fields.ApplReqID(quebraApplReqID[0])); // Inverte origem e destino da mensagem, para devolver a resposta ao cliente Fix message.Header.SetField(new QuickFix.Fields.SenderCompID(_dctSessionsFixClients[sessionIDResponse].TargetCompID)); message.Header.SetField(new QuickFix.Fields.SenderSubID(_dctSessionsFixClients[sessionIDResponse].TargetSubID)); message.Header.SetField(new QuickFix.Fields.TargetCompID(_dctSessionsFixClients[sessionIDResponse].SenderCompID)); message.Header.SetField(new QuickFix.Fields.TargetSubID(_dctSessionsFixClients[sessionIDResponse].SenderSubID)); logger.InfoFormat("SessionID[{0}]: ApplicationRawDataReporting enviando para sessionIDResponse[{1}] msg[{2}]", session.ToString(), sessionIDResponse, message.ToString()); bool bRet = Session.SendToTarget(message, _dctSessionsFixClients[sessionIDResponse]); if (!bRet) { logger.ErrorFormat("SessionID[{0}]: Falha ApplicationRawDataReporting sessionIDResponse[{1}] msg[{2}]", session.ToString(), sessionIDResponse, message.ToString()); } } catch (Exception ex) { logger.Error("onMessage(ApplicationRawDataReporting): " + ex.Message, ex); } }
private void fetchSymbols(Message message) { try { SequenceValue sequence; if (message.IsDefined("RelatedSymbols")) { sequence = message.GetSequence("RelatedSymbols"); } else { sequence = message.GetSequence("RelatedSym"); } int ocorrencias = sequence.Length; logger.Debug("LISTA_INSTRUMENTO Sequencial[" + message.GetInt("MsgSeqNum") + "] Ocorrencias[" + ocorrencias + "]"); List <Message> mensagens = UmdfUtils.splitMessage(message, channelConfig.MarketDepth, ConstantesUMDF.FAST_MSGTYPE_SECURITYLIST_SINGLE); foreach (Message newMessage in mensagens) { MDSUtils.EnqueueEventoUmdf(newMessage, this.channelConfig.SecurityListTemplateID, this.channelConfig.ChannelID, this.channelConfig.Segment, ConstantesUMDF.FAST_MSGTYPE_SECURITYLIST_SINGLE, channelConfig.MarketDepth, StreamTypeEnum.STREAM_TYPE_SECURITY_DEFINITION); } } catch (Exception e) { logger.Error("Campo nao encontrado na mensagem: " + e.Message, e); } }
public virtual void Start() { bKeepRunning = true; XMLMessageTemplateLoader loader = new XMLMessageTemplateLoader(); registry = UmdfUtils.loadTemplates(templateFile); thUdpPacketProcessor = new Thread(new ThreadStart(udpPacketProcessor)); thUdpPacketProcessor.Name = "threadUdpPacketProcessor" + channelID; thUdpPacketProcessor.Start(); thUmdfPacketAssembler = new Thread(new ThreadStart(umdfPacketAssembler)); thUmdfPacketAssembler.Name = "threadUmdfPacketAssembler" + channelID; thUmdfPacketAssembler.Start(); thUmdfPacketProcessor = new Thread(new ThreadStart(umdfPacketProcessor)); thUmdfPacketProcessor.Name = "threadUmdfPacketProcessor-" + channelID; thUmdfPacketProcessor.Start(); thUmdfMessageProcessor = new Thread(new ThreadStart(umdfMessageProcessor)); thUmdfMessageProcessor.Name = "threadUmdfMessageProcessor-" + channelID; thUmdfMessageProcessor.Start(); }
public FixInitiator(MarketIncrementalProcessor mktIncProc, ChannelUMDFConfig channelUmdfConfig, string templateFile, Queue <UdpPacket> qUdpPkt, Object replayLockObject) { logger = LogManager.GetLogger("FixInitiator-" + channelUmdfConfig.ChannelID); MDSUtils.AddAppender("FixInitiator-" + channelUmdfConfig.ChannelID, logger.Logger); XMLMessageTemplateLoader loader = new XMLMessageTemplateLoader(); registry = UmdfUtils.loadTemplates(templateFile); context = new Context(); context.TemplateRegistry = registry; _mktIncProc = mktIncProc; _channelUmdfConfig = channelUmdfConfig; if (!listaChannelQueues.ContainsKey(channelUmdfConfig.ChannelID)) { listaChannelQueues.Add(channelUmdfConfig.ChannelID, new ListChannelQueues(qUdpPkt, replayLockObject)); } logger.Info("Start(): iniciando sessao FIX..."); try { // Cria sessao FIX _session = new QuickFix.SessionID( _channelUmdfConfig.TCPConfig.BeginString, _channelUmdfConfig.TCPReplayConfig.SenderCompID, _channelUmdfConfig.TCPReplayConfig.SubID, _channelUmdfConfig.TCPReplayConfig.TargetCompID, _channelUmdfConfig.TCPReplayConfig.SubID); // Cria dicionario da configuracao QuickFix.Dictionary mainDic = new QuickFix.Dictionary(); mainDic.SetLong("SocketConnectPort", _channelUmdfConfig.TCPReplayConfig.SocketConnectPort); mainDic.SetLong("HeartBtInt", _channelUmdfConfig.TCPConfig.HeartBtInt); mainDic.SetLong("ReconnectInterval", _channelUmdfConfig.TCPConfig.ReconnectInterval); mainDic.SetBool("ResetOnLogon", _channelUmdfConfig.TCPConfig.ResetOnLogon); mainDic.SetBool("ResetOnLogout", _channelUmdfConfig.TCPConfig.ResetOnLogout); mainDic.SetBool("ResetOnDisconnect", _channelUmdfConfig.TCPConfig.ResetOnDisconnect); mainDic.SetBool("PersistMessages", _channelUmdfConfig.TCPConfig.PersistMessages); mainDic.SetString("ConnectionType", _channelUmdfConfig.TCPConfig.ConnectionType); mainDic.SetString("SocketConnectHost", _channelUmdfConfig.TCPReplayConfig.SocketConnectHost); mainDic.SetString("FileStorePath", _channelUmdfConfig.TCPConfig.FileStorePath); mainDic.SetString("FileLogPath", _channelUmdfConfig.TCPConfig.FileLogPath); mainDic.SetString("StartTime", _channelUmdfConfig.TCPReplayConfig.StartTime); mainDic.SetString("EndTime", _channelUmdfConfig.TCPReplayConfig.EndTime); QuickFix.Dictionary sessDic = new QuickFix.Dictionary(); sessDic.SetString("BeginString", _channelUmdfConfig.TCPConfig.BeginString); sessDic.SetString("SenderCompID", _channelUmdfConfig.TCPReplayConfig.SenderCompID); sessDic.SetString("SenderSubID", _channelUmdfConfig.TCPReplayConfig.SubID); sessDic.SetString("TargetCompID", _channelUmdfConfig.TCPReplayConfig.TargetCompID); sessDic.SetString("TargetSubID", _channelUmdfConfig.TCPReplayConfig.SubID); sessDic.SetString("DataDictionary", _channelUmdfConfig.TCPConfig.DataDictionary); sessDic.SetBool("UseDataDictionary", true); // Configure the session settings QuickFix.SessionSettings settings = new QuickFix.SessionSettings(); settings.Set(mainDic); settings.Set(_session, sessDic); MemoryStoreFactory store = new MemoryStoreFactory(); FileLogFactory log = new FileLogFactory(settings); IMessageFactory message = new DefaultMessageFactory(); // Cria o socket _initiator = new QuickFix.Transport.SocketInitiator(this, store, settings, log, message); _initiator.Start(); } catch (Exception ex) { logger.Error("Start():" + ex.Message, ex); } logger.Info("Start(): Sessao FIX iniciado!"); }
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"); } }
public FixServerAcceptor( TCPReplayConfig tcpReplayConfig, Dictionary <string, SessionID> dctSessionsFixClients, Dictionary <string, SessionID> dctSessionsFixChannels) { _tcpReplayConfig = tcpReplayConfig; _dctSessionsFixClients = dctSessionsFixClients; _dctSessionsFixChannels = dctSessionsFixChannels; logger = LogManager.GetLogger("FixServerAcceptor"); MDSUtils.AddAppender("FixServerAcceptor", logger.Logger); XMLMessageTemplateLoader loader = new XMLMessageTemplateLoader(); registry = UmdfUtils.loadTemplates(tcpReplayConfig.TemplateFile); context = new Context(); context.TemplateRegistry = registry; try { // Cria dicionario da configuracao QuickFix.Dictionary mainDic = new QuickFix.Dictionary(); mainDic.SetLong("SocketAcceptPort", tcpReplayConfig.SocketAcceptPort); mainDic.SetBool("ResetOnLogon", tcpReplayConfig.ResetOnLogon); mainDic.SetBool("ResetOnDisconnect", tcpReplayConfig.ResetOnDisconnect); mainDic.SetBool("PersistMessages", tcpReplayConfig.PersistMessages); mainDic.SetString("ConnectionType", tcpReplayConfig.ConnectionType); mainDic.SetString("FileStorePath", tcpReplayConfig.FileStorePath); mainDic.SetString("FileLogPath", tcpReplayConfig.FileLogPath); mainDic.SetString("StartTime", tcpReplayConfig.StartTime); mainDic.SetString("EndTime", tcpReplayConfig.EndTime); QuickFix.Dictionary sessDic = new QuickFix.Dictionary(); sessDic.SetString("BeginString", tcpReplayConfig.BeginString); sessDic.SetString("SenderCompID", tcpReplayConfig.SenderCompID); sessDic.SetString("TargetCompID", tcpReplayConfig.TargetCompID); sessDic.SetString("DataDictionary", tcpReplayConfig.DataDictionary); sessDic.SetBool("UseDataDictionary", true); // Configure the session settings QuickFix.SessionSettings settings = new QuickFix.SessionSettings(); settings.Set(mainDic); MemoryStoreFactory store = new MemoryStoreFactory(); FileLogFactory log = new FileLogFactory(settings); IMessageFactory message = new DefaultMessageFactory(); IEnumerable <int> rangeSenderSubID = Enumerable.Range( tcpReplayConfig.SubIDStartSeq, tcpReplayConfig.SubIDEndSeq); foreach (int item in rangeSenderSubID) { string subID = tcpReplayConfig.SubIDPrefix + item.ToString("D3"); // Cria sessao FIX SessionID sessionID = new QuickFix.SessionID( tcpReplayConfig.BeginString, tcpReplayConfig.SenderCompID, subID, tcpReplayConfig.TargetCompID, subID); sessDic.SetString("SenderSubID", subID); sessDic.SetString("TargetSubID", subID); settings.Set(sessionID, sessDic); } logger.InfoFormat("Start(): iniciando FIX ACCEPTOR na porta {0}...", tcpReplayConfig.SocketAcceptPort); _acceptor = new ThreadedSocketAcceptor(this, store, settings, log, message); _acceptor.Start(); } catch (Exception ex) { logger.Error("Start():" + ex.Message, ex); } logger.Info("Start(): Sessao FIX iniciada!"); }
public FixServerInitiator( string channelsID, TCPReplayConfig tcpReplayConfig, Dictionary <string, SessionID> dctSessionsFixClients, Dictionary <string, SessionID> dctSessionsFixChannels) { _tcpReplayConfig = tcpReplayConfig; _dctSessionsFixClients = dctSessionsFixClients; _dctSessionsFixChannels = dctSessionsFixChannels; logger = LogManager.GetLogger("FixServerInitiator-" + tcpReplayConfig.ChannelID); MDSUtils.AddAppender("FixServerInitiator-" + tcpReplayConfig.ChannelID, logger.Logger); XMLMessageTemplateLoader loader = new XMLMessageTemplateLoader(); registry = UmdfUtils.loadTemplates(tcpReplayConfig.TemplateFile); context = new Context(); context.TemplateRegistry = registry; try { // Cria dicionario da configuracao QuickFix.Dictionary mainDic = new QuickFix.Dictionary(); mainDic.SetString("SocketConnectHost", tcpReplayConfig.SocketConnectHost); mainDic.SetLong("SocketConnectPort", tcpReplayConfig.SocketConnectPort); if (!String.IsNullOrEmpty(tcpReplayConfig.SocketConnectHost1)) { mainDic.SetString("SocketConnectHost1", tcpReplayConfig.SocketConnectHost1); mainDic.SetLong("SocketConnectPort1", tcpReplayConfig.SocketConnectPort1); } mainDic.SetLong("HeartBtInt", tcpReplayConfig.HeartBtInt); mainDic.SetLong("ReconnectInterval", tcpReplayConfig.ReconnectInterval); mainDic.SetBool("ResetOnLogon", tcpReplayConfig.ResetOnLogon); mainDic.SetBool("PersistMessages", tcpReplayConfig.PersistMessages); mainDic.SetString("ConnectionType", tcpReplayConfig.ConnectionType); mainDic.SetString("FileStorePath", tcpReplayConfig.FileStorePath); mainDic.SetString("FileLogPath", tcpReplayConfig.FileLogPath); mainDic.SetString("StartTime", tcpReplayConfig.StartTime); mainDic.SetString("EndTime", tcpReplayConfig.EndTime); QuickFix.Dictionary sessDic = new QuickFix.Dictionary(); sessDic.SetString("BeginString", tcpReplayConfig.BeginString); sessDic.SetString("SenderCompID", tcpReplayConfig.SenderCompID); sessDic.SetString("TargetCompID", tcpReplayConfig.TargetCompID); sessDic.SetString("DataDictionary", tcpReplayConfig.DataDictionary); sessDic.SetBool("UseDataDictionary", true); // Configure the session settings QuickFix.SessionSettings settings = new QuickFix.SessionSettings(); settings.Set(mainDic); MemoryStoreFactory store = new MemoryStoreFactory(); FileLogFactory log = new FileLogFactory(settings); IMessageFactory message = new DefaultMessageFactory(); // Cria sessao FIX _sessionID = new QuickFix.SessionID( tcpReplayConfig.BeginString, tcpReplayConfig.SenderCompID, tcpReplayConfig.TargetCompID); settings.Set(_sessionID, sessDic); string[] quebraChannelsID = channelsID.Split(",".ToCharArray()); foreach (string channel in quebraChannelsID) { dctSessionsFixChannels.Add(channel, _sessionID); } logger.InfoFormat("Start(): iniciando FIX com sessionID[{0}]...", _sessionID.ToString()); _initiator = new QuickFix.Transport.SocketInitiator(this, store, settings, log, message); _initiator.Start(); } catch (Exception ex) { logger.Error("Start():" + ex.Message, ex); } logger.Info("Start(): Sessao FIX iniciada!"); }
protected override void umdfMessageProcessor() { try { logger.Debug("Processando mensagens de recovery"); string recoveryTemplateID = channelConfig.MDRecoveryTemplateID.ToString(); listaRecoveryTemplateID = recoveryTemplateID.Split(",".ToCharArray()); long lastLogTicks = 0; while (bKeepRunning) { try { //Message message = this.filaMensagensUMDF.take(); Message message; if (!queueToProcessor.TryDequeue(out message)) { Thread.Sleep(50); continue; } // Notifica o fim do snapshot para inicio do tratamento do incremental if (listaRecoveryTemplateID.Any(message.Template.Id.Contains)) { List <Message> mensagens = UmdfUtils.splitMessage(message, channelConfig.MarketDepth, ConstantesUMDF.FAST_MSGTYPE_SNAPSHOT_SINGLE); foreach (Message newMessage in mensagens) { MDSUtils.EnqueueEventoUmdf(newMessage, this.channelConfig.MDRecoveryTemplateID, this.channelConfig.ChannelID, this.channelConfig.Segment, ConstantesUMDF.FAST_MSGTYPE_SNAPSHOT_SINGLE, channelConfig.MarketDepth, StreamTypeEnum.STREAM_TYPE_MARKET_RECOVERY); if (MDSUtils.shouldLog(lastLogTicks)) { lastLogTicks = DateTime.UtcNow.Ticks; string msgTruncado = (message.ToString().Length < 200 ? message.ToString() : message.ToString().Substring(0, 200)); monitorConfig.channels[channelConfig.ChannelID].dateTimeStartedStopped = "Snapshot - " + DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + " - " + msgTruncado; monitorConfig.channels[channelConfig.ChannelID].AddDetails( "2) Snapshot", DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"), msgTruncado); } } if (message.IsDefined("MsgSeqNum") && message.IsDefined("TotNumReports")) { int seqNum = message.GetInt("MsgSeqNum"); //34 int totNumReports = message.GetInt("TotNumReports"); //911 if (seqNum == 1) { int LastMsgSeqNumProcessed = message.GetInt("LastMsgSeqNumProcessed"); bCanProcess = true; logger.Info("Inicio do processamento do snapshot: " + totNumReports + " msgs"); logger.Info("Notificando observers, LastMsgSeqNumProcessed:" + LastMsgSeqNumProcessed); RecoveryStartedEventArgs e = new RecoveryStartedEventArgs(); e.LastMsgSeqNumProcessed = message.GetInt("LastMsgSeqNumProcessed"); if (this.OnRecoveryStarted != null) { OnRecoveryStarted(this, e); } } if (seqNum == totNumReports && bCanProcess) { int LastMsgSeqNumProcessed = message.GetInt("LastMsgSeqNumProcessed"); logger.Info("Fim do processamento do snapshot: " + totNumReports + " msgs"); logger.Info("Notificando observers, LastMsgSeqNumProcessed:" + LastMsgSeqNumProcessed); RecoveryCompletedEventArgs e = new RecoveryCompletedEventArgs(); e.LastMsgSeqNumProcessed = message.GetInt("LastMsgSeqNumProcessed"); monitorConfig.channels[channelConfig.ChannelID].dateTimeStartedStopped = "Snapshot - " + DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + ": Snapshot completo!"; monitorConfig.channels[channelConfig.ChannelID].AddDetails( "2) Snapshot", DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"), "Snapshot completo! Ultimo SeqNum[" + e.LastMsgSeqNumProcessed + "]"); if (this.OnRecoveryCompleted != null) { OnRecoveryCompleted(this, e); } bKeepRunning = false; break; } } else { logger.Error("Template ID nao reconhecido [" + message.Template.Id + "]"); } } } catch (Exception ex) { logger.Error("umdfMessageProcessor: " + ex.Message, ex); bCanProcess = false; } } Stop(); logger.Debug("Fim"); } catch (Exception ex) { logger.Error("Damn: " + ex.Message, ex); monitorConfig.channels[channelConfig.ChannelID].RemoveDetails("2) Snapshot"); //bKeepRunning = false; } }
protected virtual void umdfPacketAssembler() { //UmdfPacket packet = null; int lastSeqNum = 0; UmdfPacket [] chunks = null; int receivedChunks = 0; Dictionary <int, long> dctSeqNum = new Dictionary <int, long>(); //StreamWriter tracewriter = new StreamWriter("d:\\turingoms\\servicos\\mdsnetpuma2\\logs\\Trace-" + this.channelID + "-" + this.multicastPortPRI + ".txt", true); while (bKeepRunning) { Context context = null; UmdfPacket packet = null; if (qUmdfPacket.TryDequeue(out packet)) { int totalBytes = packet.data.Length; try { //if (context != null) //{ // ((OpenFAST.Debug.BasicDecodeTrace)context.DecodeTrace).Writer.Close(); // ((OpenFAST.Debug.BasicDecodeTrace)context.DecodeTrace).Writer.Dispose(); // context = null; //} context = new Context(); context.TemplateRegistry = registry; //context.TraceEnabled = true; //context.StartTrace(); //((OpenFAST.Debug.BasicDecodeTrace)context.DecodeTrace).Writer = tracewriter; if (packet.noChunks > 1) { logger.Debug("pktAss() noChunks: " + packet.noChunks + " currChunk: " + packet.currChunk + " seqNum: " + packet.seqNum + " lastSeqNum:" + lastSeqNum); if (chunks == null || packet.seqNum != lastSeqNum) { logger.Debug("pktAss() Alocando array para [" + packet.noChunks + "] chunks: null ou seqNum!="); chunks = new UmdfPacket[packet.noChunks]; receivedChunks = 0; } // Verifica se ainda esta no mesmo chunk, e se ainda dentro da mesma // rodada do snapshot if (dctSeqNum.ContainsKey(packet.seqNum)) { TimeSpan ts = new TimeSpan(DateTime.Now.Ticks - dctSeqNum[packet.seqNum]); if (ts.TotalMilliseconds > PACKET_TIME_WINDOW && processorType.Equals(ProcessorType.MarketIncremental)) { logger.Debug("pktAss() REALOCANDO array para [" + packet.noChunks + "] chunks"); chunks = new UmdfPacket[packet.noChunks]; receivedChunks = 0; } dctSeqNum[packet.seqNum] = DateTime.Now.Ticks; } else { logger.Debug("pktAss() Alocando array para [" + packet.noChunks + "] chunks"); dctSeqNum.Add(packet.seqNum, DateTime.Now.Ticks); chunks = new UmdfPacket[packet.noChunks]; receivedChunks = 0; } if ((packet.currChunk - 1) < chunks.Length) { if (chunks[packet.currChunk - 1] == null) { receivedChunks++; } chunks[packet.currChunk - 1] = packet; } else { logger.Error("pktAss() Puts...[" + (packet.currChunk - 1) + "] <=> [" + chunks.Length + "] fdp furou!!!!"); continue; } logger.Debug("pktAss() noChunks: " + packet.noChunks + " currChunk: " + packet.currChunk); lastSeqNum = packet.seqNum; if (receivedChunks < packet.noChunks) { continue; } dctSeqNum.Remove(packet.seqNum); logger.Debug("pktAss() Remontando pacote noChunks=" + packet.noChunks + " received=" + receivedChunks + " length=" + chunks.Length); byte[] reassembled = UmdfUtils.reassemble(chunks); totalBytes = reassembled.Length; chunks = null; receivedChunks = 0; packet.data = reassembled; packet.msgLength = totalBytes; System.IO.MemoryStream byteIn = new System.IO.MemoryStream(packet.data, 0, packet.msgLength); FastDecoder decoder = new FastDecoder(context, byteIn); Message message = decoder.ReadMessage(); bool bsinaliza = queueToProcessor.IsEmpty; queueToProcessor.Enqueue(message); if (bsinaliza) { lock (syncQueueToProcessor) { Monitor.Pulse(syncQueueToProcessor); } } // testa se debug esta habilitado por conta do writegroup // mais performatico if (logger.IsDebugEnabled) { logger.Debug(UmdfUtils.writeGroup(message)); } } else { lastSeqNum = packet.seqNum; System.IO.MemoryStream byteIn = new System.IO.MemoryStream(packet.data, 0, packet.msgLength); FastDecoder decoder = new FastDecoder(context, byteIn); Message message = decoder.ReadMessage(); bool bsinaliza = queueToProcessor.IsEmpty; queueToProcessor.Enqueue(message); if (bsinaliza) { lock (syncQueueToProcessor) { Monitor.Pulse(syncQueueToProcessor); } } if (logger.IsDebugEnabled) { logger.Debug(UmdfUtils.writeGroup(message)); } } } catch (Exception ex) { logger.Error("pktAss() Erro: " + ex.Message, ex); // Bom, com uma exception dessas, acho melhor iniciar o canal, pode ser falha no decoder string msg = string.Format("Canal [{0}] precisa ser derrubado, pois deu falha grave no PacketAssembler().\r\n\r\n{1}\r\n\r\n{2}", channelID, ex.Message, ex); string titulo = string.Format("Derrubando canal [{0}] por falha em pktAss()", channelID); MDSUtils.EnviarEmail(titulo, msg); bKeepRunning = false; //lastpkt = 0; } continue; } lock (syncQueueUmdfPacket) { Monitor.Wait(syncQueueUmdfPacket, 100); } } }