Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="param"></param>
        protected void messageFixThreadWork(object param)
        {
            FIXMessageWorkerState workerstate = param as FIXMessageWorkerState;
            long lastTick       = 0;
            long threadWatchDog = 0;

            if (workerstate != null)
            {
                logger.Info("Iniciando messageFixThreadWork para channelID [" + workerstate.ChannelID + "]");

                while (bKeepRunning)
                {
                    if (MDSUtils.shouldLog(threadWatchDog, 30))
                    {
                        logger.Info("messageFixThreadWork(" + workerstate.ChannelID + ") ativo");
                        threadWatchDog = DateTime.UtcNow.Ticks;
                    }

                    try
                    {
                        EventoFIX evento;
                        if (workerstate.QueueMensagens.TryDequeue(out evento))
                        {
                            trataMensagemFIX(evento);

                            if (MDSUtils.shouldLog(lastTick))
                            {
                                logger.Info("messageFixThreadWork(" + workerstate.ChannelID + ") msgs na fila: " + workerstate.QueueMensagens.Count);
                                lastTick = DateTime.UtcNow.Ticks;
                            }

                            continue;
                        }

                        lock (workerstate.SyncObjFIX)
                        {
                            Monitor.Wait(workerstate.SyncObjFIX, 50);
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error("messageFixThreadWork(" + workerstate.ChannelID + "): " + ex.Message, ex);
                    }
                }

                logger.Info("Finalizando messageFixThreadWork para channelID [" + workerstate.ChannelID + "]");
            }
        }
Example #2
0
        protected virtual void processaMensagemFIX(EventoFIX evento)
        {
            // Se nao existe thread para tratar o evento, cria
            FIXMessageWorkerState workerState = null;

            if (evento == null)
            {
                logger.Error("Mensagem FIX nao pode ser nula");
                return;
            }

            if (String.IsNullOrEmpty(evento.ChannelID))
            {
                logger.Error("Eita porra....channelID nulo");
                return;
            }

            if (!poolFixWorkers.TryGetValue(evento.ChannelID, out workerState))
            {
                logger.Info("Criando worker para  channel [" + evento.ChannelID + "]");
                workerState             = new FIXMessageWorkerState();
                workerState.ChannelID   = evento.ChannelID;
                workerState.Thread      = new Thread(new ParameterizedThreadStart(messageFixThreadWork));
                workerState.Thread.Name = myThreadName + "-Worker-" + workerState.ChannelID;
                workerState.Thread.Start(workerState);

                poolFixWorkers.Add(evento.ChannelID, workerState);
            }

            bool bsinaliza = workerState.QueueMensagens.IsEmpty;

            workerState.QueueMensagens.Enqueue(evento);
            if (MDSUtils.shouldLog(workerState.lastEnqueueLog, 30))
            {
                logger.Info("processaMensagemFIX para channelID [" + workerState.ChannelID + "] fila:" + workerState.QueueMensagens.Count);
                workerState.lastEnqueueLog = DateTime.UtcNow.Ticks;
            }

            //if (bsinaliza)
            //{
            //    lock (workerState.SyncObjFIX)
            //    {
            //        Monitor.Pulse(workerState.SyncObjFIX);
            //    }
            //}
        }