Beispiel #1
0
        public void ZipInContainer()
        {
            this.BuildClientSettingsProps();

            this.RegisterType <MsgContainerHandler>();
            this.RegisterType <GZipPackedHandler>();

            var contanerMessage = new MsgContainer
            {
                Messages = new[]
                {
                    new TContainerMessage
                    {
                        Body = new TgZipPacked
                        {
                            PackedData = ZipObject(new TBoolTrue())
                        }
                    }
                }
            };

            // ---
            var channel = new EmbeddedChannel(this.Resolve <MsgContainerHandler>(), this.Resolve <GZipPackedHandler>());

            channel.WriteInbound(contanerMessage);

            // ---

            Assert.NotNull(channel.ReadInbound <TBoolTrue>());
        }
Beispiel #2
0
 public void Consume(MsgContainer msgContainer,string key)
 {
     Msg msg;
     msgContainer.Messages.TryGetValue(key, out msg);
     if (msg != null)
     {
             msgContainer.Messages.TryRemove(key, out msg);
     }
     Thread.Sleep(2);
 }
Beispiel #3
0
 public void Consume(MsgContainer msgContainer,string key)
 {
     int result;
     for (int i = 0; i < 10000; i++)
     {
         for (int k=0;k<1000;k++)
         {
             result = i* k;
         }
     }
 }
Beispiel #4
0
        private void StatisticListenerTask(ZContext ctx)
        {
            using (var listener = new ZSocket(ctx, ZSocketType.PAIR))
            {
                listener.Connect("inproc://listener");

                //checking each message, if new prefix receives, creating new Taskcomponent, adding
                while (true)
                {
                    ZError   error;
                    ZMessage msg;
                    if (null == (msg = listener.ReceiveMessage(out error)))
                    {
                        if (error == ZError.ETERM)
                        {
                            return; // Interrupted
                        }
                        throw new ZException(error);
                    }
                    if (msg.Count < 3)
                    {
                        continue;
                    }
                    bool doBreak = false;
                    WorkloadStatisticsContext wlStatCtx;
                    using (var groupFrame = msg[0])
                        using (var taskFrame = msg[1])
                            using (var statlogFrame = msg[2])
                            {
                                Guid groupGuid;
                                doBreak |= !Guid.TryParse(groupFrame.ReadString(), out groupGuid);
                                Guid taskGuid;
                                doBreak |= !Guid.TryParse(taskFrame.ReadString(), out taskGuid);
                                doBreak |= !WorkloadStatisticsContext.TryParse(groupGuid, taskGuid, statlogFrame.ReadString(), out wlStatCtx);
                            }
                    if (doBreak)
                    {
                        continue;
                    }

                    var    key          = wlStatCtx.GetKey();
                    UInt64 cnt          = _msgContainerByKey.ContainsKey(key) ? _msgContainerByKey[key].NmsReceived + 1L : 1L;
                    var    msgContainer = new MsgContainer(wlStatCtx, cnt);

                    if (!_msgContainerByKey.ContainsKey(key))
                    {
                        _newKeyQueue.Enqueue(key);
                    }
                    _msgContainerByKey[key] = msgContainer;
                }
            }
        }
        /*
         * private void Subscriber(ZContext ctx, string endpoint, IEnumerable<string> subscription, CancellationToken ctParent, CancellationToken ct)
         * {
         *  using (var subsct = ZSocket.Create(ctx, ZSocketType.SUB))
         *  {
         *      subsct.Connect(endpoint);
         *      foreach (var subs in subscription)
         *          subsct.Subscribe(subs);
         *
         *      var msgi = 0;
         *
         *      while (!ct.IsCancellationRequested && !ctParent.IsCancellationRequested)
         *      {
         *          ZError error;
         *          ZFrame frm;
         *          if (null == (frm = subsct.ReceiveFrame(out error)))
         *          {
         *              if (error == ZError.ETERM)
         *                  return; // Interrupted
         *              throw new ZException(error);
         *          }
         *          else
         *          {
         *              using (frm)
         *              {
         *                  var s = frm.ToString();//Encoding.UTF8);
         *                  //##Todocheck UpdateCounter(new MsgContainer(s, ++msgi));
         *              }
         *          }
         *      }
         *  }
         * }
         */

        public void UpdateCounter(MsgContainer msgCont)
        {
            if (msgCont == null || MaxNms == msgCont.NmsReceived)
            {
                return;
            }
            _udtCnt++;
            MaxNms = msgCont.NmsReceived;
            // MsgCnt = msgCont.NmsReceived;// vi;//++;// = vi;

            var nmsMsg = msgCont.WorkloadStatistics.NumberOfMessagesSeen;
            var incMsg = msgCont.WorkloadStatistics.IncQueueMsgCnt;
            var outMsg = msgCont.WorkloadStatistics.OutQueueMsgCnt;

            MsgCnt = nmsMsg;
            if (incMsg > MaxIncCnt)
            {
                MaxIncCnt = incMsg;
            }
            if (outMsg > MaxOutnCnt)
            {
                MaxOutnCnt = outMsg;
            }

            IncCnt  = incMsg;
            OutnCnt = outMsg;

            Title = msgCont.WorkloadStatistics.Context; // msgCont.TaskMsg; // taskMsg;// message.Split("Title: ".ToCharArray(),21)[20];

            var pcv = incMsg <= 0
                        ? 0M
                        : incMsg >= MaxIncCnt
                            ? 100M
                            : 100M / MaxIncCnt * incMsg;

            var pcv1 = outMsg <= 0
                        ? 0M
                        : outMsg >= MaxOutnCnt
                            ? 100M
                            : 100M / MaxOutnCnt * outMsg;

            try
            {
                perfChart.AddValue(pcv);
                perfChart1.AddValue(pcv1);
            }
            catch (Exception)
            {
                //throw;
                _addPerfExCnt++;
            }
        }
Beispiel #6
0
        public void MsgContainer()
        {
            var container = new MsgContainer()
            {
                Messages = new [] { new TContainerMessage
                                    {
                                        Body = new TPong()
                                    }, }
            };

            var buffer = Serializer.Serialize(container);

            Serializer.Deserialize(buffer);
        }
Beispiel #7
0
 public void Consume(MsgContainer msgContainer,string key)
 {
     Thread.Sleep(sleepTime);
 }
Beispiel #8
0
 public MsgContext()
 {
     RequestMsgs = new MsgContainer<IRequestMsgBase>(MaxRecordCount);
     ResponseMsgs = new MsgContainer<IResponseMsgBase>(MaxRecordCount);
     LastActiveTime = DateTime.Now;
 }