Esempio n. 1
0
        public static void Init()
        {
            Queue = new BufferQueue <SystemLogEntity>();
            var td = new System.Threading.Thread(() =>
            {
                using (var scope = new ScopeDbContext())
                {
                    var db = scope.GetDbContext();
                    db.ChangeTracker.AutoDetectChangesEnabled = false;
                    while (true)
                    {
                        Queue.Read((item, index) =>
                        {
                            item.Node = ConfigurationCache.NodeSetting?.IdentityName;
                            db.SystemLogs.Add(item);
                        });
                        if (db.ChangeTracker.HasChanges())
                        {
                            db.SaveChanges();
                        }
                        foreach (var item in db.ChangeTracker.Entries())
                        {
                            item.State = Microsoft.EntityFrameworkCore.EntityState.Detached;
                        }
                        System.Threading.Thread.Sleep(5000);
                    }
                }
            });

            td.IsBackground = true;
            td.Start();
        }
Esempio n. 2
0
        private bool InitData()
        {
            byte[] data;
            if (BufferQueue.TryDequeue(out data))
            {
                if (BufferLenght <= 0)
                {
                    _send.SetBuffer(data, 0, data.Length);

                    return(true);
                }
                else
                {
                    int length = BufferLenght;

                    if (length > data.Length)
                    {
                        length = data.Length;
                    }

                    _send.SetBuffer(data, 0, length);

                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }
Esempio n. 3
0
        public static void Init()
        {
            Queue = new BufferQueue <SystemLogEntity>();
            var td = new System.Threading.Thread(() =>
            {
                using (var scope = new ScopeDbContext())
                {
                    var db = scope.GetDbContext();
                    while (true)
                    {
                        Queue.Read((item, index) =>
                        {
                            item.Node = ConfigurationCache.NodeSetting?.IdentityName;
                            ///item.CreateTime = DateTime.Now;
                            db.SystemLogs.Add(item);
                        });
                        db.SaveChanges();
                        System.Threading.Thread.Sleep(5000);
                    }
                }
            });

            td.IsBackground = true;
            td.Start();
        }
Esempio n. 4
0
                               private void InitConsumer()
                               {
                                   ConnectionFactory factory = new ConnectionFactory();

                                   factory.Uri = connString;
                                   conn        = factory.CreateConnection();
                                   channel     = conn.CreateModel();
                                   channel.BasicQos(0, prefetchCount, false);
                                   buffer = new BufferQueue();

                                   consumer = new EventingBasicConsumer(channel);
                                   channel.BasicConsume(queueName, false, consumer);

                                   // when message is recieved do following
                                   consumer.Received += (model, message) =>
                                   {
                                       if (buffer.Count() > DEFAULT_ACK_COUNT)
                                       {
                                           Thread.Sleep(3000);
                                       }

                                       buffer.Enqueue(message);

                                       if (buffer.Count() == 0 || buffer.Count() == ackCount)
                                       {
                                           channel.BasicAck(message.DeliveryTag, true);
                                       }
                                   };
                               }
Esempio n. 5
0
            internal char this[int index]
            {
                get
                {
                    char ch = '\0';
                    if (_CurrentBuffer == null)
                    {
                        if (BufferQueue.Count > 0)
                        {
                            _CurrentBuffer = (Buffer)BufferQueue.Dequeue();
                        }
                        else
                        {
                            return(ch);
                        }
                    }

                    if (!((_CurrentBuffer._offset + index - Offset) < _CurrentBuffer._size))
                    {
                        Offset         = index;
                        _CurrentBuffer = (BufferQueue.Count > 0) ? (Buffer)BufferQueue.Dequeue() : null;
                    }

                    if (_CurrentBuffer != null)
                    {
                        ch = _CurrentBuffer._charBuffer[_CurrentBuffer._offset + (index - Offset)];
                    }
                    return(ch);
                }
            }
Esempio n. 6
0
 public FileStreamingServer(int receiveBufferSize)
 {
     m_bufQueue          = new BufferQueue(receiveBufferSize);
     clientList          = new ArrayList();
     byteData            = new byte[receiveBufferSize];
     readBuffer          = new byte[receiveBufferSize];
     m_receiveBufferSize = receiveBufferSize;
 }
Esempio n. 7
0
 public TrainPlugin(PluginLoadData pluginLoadData) : base(pluginLoadData)
 {
     worldTrains = new List <WorldTrain>();
     queue       = new BufferQueue();
     playerHasInitializedTrain         = new List <IClient>();
     ClientManager.ClientConnected    += OnClientConnected;
     ClientManager.ClientDisconnected += OnClientDisconnect;
 }
Esempio n. 8
0
File: Udp.cs Progetto: doruu12/NetUV
        internal Udp(LoopContext loop, ByteBufferAllocator allocator)
            : base(loop, uv_handle_type.UV_UDP)
        {
            Contract.Requires(allocator != null);

            this.allocator   = allocator;
            this.bufferQueue = new BufferQueue();
        }
 internal BufferedOutputAsyncStream(Stream stream, int bufferSize, int bufferLimit)
 {
     this.stream      = stream;
     this.bufferSize  = bufferSize;
     this.bufferLimit = bufferLimit;
     this.buffers     = new BufferQueue(this.bufferLimit);
     this.buffers.Add(new ByteBuffer(this, this.bufferSize, stream));
     this.availableBufferCount = 1;
 }
Esempio n. 10
0
        public void Load()
        {
            _bufferQueue  = new BufferQueue <MessageLogRecord>("MessageBufferQueue", BrokerController.Instance.Setting.MessageWriteQueueThreshold, PersistMessages, _logger);
            _chunkManager = new ChunkManager("MessageChunk", BrokerController.Instance.Setting.MessageChunkConfig, BrokerController.Instance.Setting.IsMessageStoreMemoryMode);
            _chunkWriter  = new ChunkWriter(_chunkManager);
            _chunkReader  = new ChunkReader(_chunkManager, _chunkWriter);

            _chunkManager.Load(ReadMessage);
        }
Esempio n. 11
0
        private void Client_BinaryInput(byte[] buffer)
        {
            BufferQueue.Write(buffer);

            byte[] datax;
            while (BufferQueue.Read(out datax))
            {
                BufferIn(datax);
            }
        }
Esempio n. 12
0
        private void Free()
        {
            _send.SetBuffer(null, 0, 0);

            byte[] tmp;
            for (int i = 0; i < BufferQueue.Count; i++)
            {
                BufferQueue.TryDequeue(out tmp);
            }
        }
Esempio n. 13
0
 public UdpClientBase(int id = -1, SendType type = SendType.Normal) : base()
 {
     _tempRecvBuffer = new byte[1024000];//1MByte
     _id             = id;
     _sendType       = type;
     //_isEndConnection = true;
     _callBackFunc = null;
     _queue        = new BufferQueue();
     _functions    = new InterfaceFunctions(this, _queue);
 }
Esempio n. 14
0
        internal Pipeline(StreamHandle streamHandle, ByteBufferAllocator allocator)
        {
            Contract.Requires(streamHandle != null);
            Contract.Requires(allocator != null);

            this.streamHandle = streamHandle;
            this.allocator    = allocator;
            this.receiveBufferSizeEstimate = new ReceiveBufferSizeEstimate();
            this.bufferQueue = new BufferQueue();
        }
Esempio n. 15
0
 public UdpClientBase(Byte[] tempRecvBuffer, SendType type = SendType.Normal, int id = -1)
     : base()
 {
     _tempRecvBuffer = tempRecvBuffer;
     _id             = id;
     _sendType       = type;
     //_isEndConnection = true;
     _callBackFunc = null;
     _queue        = new BufferQueue();
     _functions    = new InterfaceFunctions(this, _queue);
 }
Esempio n. 16
0
        public void Load()
        {
            var messageWriteQueueThreshold = BrokerController.Instance.Setting.MessageWriteQueueThreshold;

            _bufferQueue  = new BufferQueue <MessageLogRecord>("MessageBufferQueue", messageWriteQueueThreshold, PersistMessages, _logger);
            _chunkManager = new ChunkManager(this.GetType().Name, BrokerController.Instance.Setting.MessageChunkConfig);
            _chunkWriter  = new ChunkWriter(_chunkManager);
            _chunkReader  = new ChunkReader(_chunkManager, _chunkWriter);

            _chunkManager.Load(ReadMessage);
        }
Esempio n. 17
0
        public SendMessageRequestHandler(BrokerController brokerController)
        {
            _brokerController            = brokerController;
            _suspendedPullRequestManager = ObjectContainer.Resolve <SuspendedPullRequestManager>();
            _messageStore             = ObjectContainer.Resolve <IMessageStore>();
            _queueStore               = ObjectContainer.Resolve <IQueueStore>();
            _notifyWhenMessageArrived = _brokerController.Setting.NotifyWhenMessageArrived;
            _logger = ObjectContainer.Resolve <ILoggerFactory>().Create(GetType().FullName);
            var messageWriteQueueThreshold = brokerController.Setting.MessageWriteQueueThreshold;

            _bufferQueue = new BufferQueue <StoreContext>("QueueBufferQueue", messageWriteQueueThreshold, AddQueueMessage, _logger);
        }
Esempio n. 18
0
        public void StartFile(uint width, uint height, uint framesPerSecond)
        {
            this.width = width;
              this.height = height;
              this.framesPerSecond = framesPerSecond;

              bufferQueue = new BufferQueue();
              bufferQueue.WorkAvailable += OnBufferQueueWorkAvailable;
              bufferQueue.Shutdown += OnBufferQueueShutdown;

              SyncWriteFileHeader();
        }
 public SendMessageRequestHandler(BrokerController brokerController)
 {
     _brokerController = brokerController;
     _suspendedPullRequestManager = ObjectContainer.Resolve<SuspendedPullRequestManager>();
     _messageStore = ObjectContainer.Resolve<IMessageStore>();
     _queueStore = ObjectContainer.Resolve<IQueueStore>();
     _tpsStatisticService = ObjectContainer.Resolve<ITpsStatisticService>();
     _notifyWhenMessageArrived = _brokerController.Setting.NotifyWhenMessageArrived;
     _logger = ObjectContainer.Resolve<ILoggerFactory>().Create(GetType().FullName);
     _sendRTLogger = ObjectContainer.Resolve<ILoggerFactory>().Create("SendRT");
     var messageWriteQueueThreshold = brokerController.Setting.MessageWriteQueueThreshold;
     _bufferQueue = new BufferQueue<StoreContext>("QueueBufferQueue", messageWriteQueueThreshold, OnQueueMessageCompleted, _logger);
 }
Esempio n. 20
0
        public BatchSendMessageRequestHandler(BrokerController brokerController)
        {
            _brokerController            = brokerController;
            _suspendedPullRequestManager = ObjectContainer.Resolve <SuspendedPullRequestManager>();
            _messageStore             = ObjectContainer.Resolve <IMessageStore>();
            _queueStore               = ObjectContainer.Resolve <IQueueStore>();
            _tpsStatisticService      = ObjectContainer.Resolve <ITpsStatisticService>();
            _notifyWhenMessageArrived = _brokerController.Setting.NotifyWhenMessageArrived;
            _logger       = ObjectContainer.Resolve <ILoggerFactory>().Create(GetType().FullName);
            _sendRTLogger = ObjectContainer.Resolve <ILoggerFactory>().Create("BatchSendRT");
            var messageWriteQueueThreshold = brokerController.Setting.BatchMessageWriteQueueThreshold;

            _bufferQueue = new BufferQueue <StoreContext>("QueueBufferQueue", messageWriteQueueThreshold, OnQueueMessageCompleted, _logger);
        }
Esempio n. 21
0
 void ProcessQueue()
 {
     while (End != true)
     {
         if (BufferQueue.Count != 0)
         {
             var buffer = BufferQueue.Dequeue();
             while (ProcessBuffer(ref buffer) > 0)
             {
                 ;
             }
         }
     }
 }
Esempio n. 22
0
 private void SendMessage()
 {
     while (IsWorking)
     {
         SendMREvent.Reset();
         var queue = (BufferQueue.GetMessage());
         while (queue != null && queue.Count > 0)
         {
             var de = queue.Dequeue();
             SendMessage(de.Client, de.Message.ToBytes());
         }
         SendMREvent.WaitOne();
     }
 }
Esempio n. 23
0
        public bool Send(byte[] data)
        {
            if (_sock == null)
            {
                return(false);
            }
            if (data == null)
            {
                return(false);
            }

            BufferQueue.Enqueue(data);

            return(SendComputer());
        }
            /// <summary>
            /// Performs pre-processing using parallelization. Up to <paramref name="maxThreads"/> threads will be used to process data prior to it being requested by (and simultaneous with) the enumerable consumer.
            /// </summary>
            /// <param name="source">source enumerable; preferably something like a list of file that need to be loaded</param>
            /// <param name="processFunction">Transform function from <paramref name="source"/> to return type; should involve heavy processing (if x => x, you may see a performance penalty)</param>
            /// <param name="maxThreads">Max number of <paramref name="source"/> items to process simultaneously</param>
            /// <param name="maxPreprocessed">Max number of items to allow being preprocessed or completed-but-not-consumed at any time; defaults to <paramref name="maxThreads"/></param>
            /// <param name="checkIntervalSeconds">How often to check for completion of the preprocessing</param>
            /// <param name="cancellationToken">Cancellation token</param>
            /// <returns>IEnumerable of items that have been processed via <paramref name="processFunction"/></returns>
            public ParallelPreprocessor(IEnumerable <T> source, Func <T, TResult> processFunction, int maxThreads, int maxPreprocessed = -1, double checkIntervalSeconds = 1,
                                        CancellationToken cancellationToken = default(CancellationToken))
            {
                cancelToken = cancellationToken;
                if (maxPreprocessed < 1)
                {
                    maxPreprocessed = maxThreads;
                }

                preprocessedLimiter = new SemaphoreSlim(maxPreprocessed, maxPreprocessed);

                buffer = new BufferQueue <TResult>(maxPreprocessed + 1);

                Start(source, processFunction, maxThreads, checkIntervalSeconds);
            }
Esempio n. 25
0
        public bool Send(byte[] data)
        {
            BufferQueue.Enqueue(data);

            if (!SendIng)
            {
                if (InitData())
                {
                    SendIng = true;
                    sock.SendAsync(_send);
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 26
0
        public void BufferQueue_Test()
        {
            var r     = 0;
            var queue = new BufferQueue <int>("q1", 2, v =>
            {
                r = v;
            });

            queue.EnqueueMessage(1);
            queue.EnqueueMessage(2);
            queue.EnqueueMessage(3);
            queue.EnqueueMessage(4);
            queue.EnqueueMessage(5);

            Assert.True(r > 0);
        }
Esempio n. 27
0
 private void AllocateBuffers(IEnumerable <BufferQueueSetting> settings)
 {
     foreach (var setting in settings)
     {
         BufferQueue queue;
         if (queues.ContainsKey(setting.ChunkSize))
         {
             queue = queues[setting.ChunkSize];
         }
         else
         {
             queue = new BufferQueue();
             queues.AddOrUpdate(setting.ChunkSize, queue, (i, bufferQueue) => bufferQueue);
         }
         for (int i = 0; i < setting.InitialPoolSize; i++)
         {
             queue.Enqueue(new byte[setting.ChunkSize]);
         }
     }
 }
Esempio n. 28
0
        public void EnqueueBufferQueue(int length, int index = 0)
        {
            if (index + length > BufferSize)
            {
                throw new Exception("超过Buffer长度");
            }

            BufferQueue.Lock();
            try
            {
                for (var i = index; i < length; i++)
                {
                    BufferQueue.Enqueue(Buffer[i], true);
                }
            }
            catch
            {
            }
            BufferQueue.UnLock();
            BufferQueue.EnqueueEvent.Set();
        }
Esempio n. 29
0
        public CompileOutputComponent()
        {
            _control = new RichTextBox
            {
                Dock       = DockStyle.Fill,
                Multiline  = true,
                Font       = new Font(FontFamily.GenericMonospace, 8),
                BackColor  = Color.White,
                ScrollBars = RichTextBoxScrollBars.Both,
                WordWrap   = false,
                ReadOnly   = true
            };

            _buffer = new BufferQueue <Output>();

            Oy.Subscribe <Batch>("Compile:Started", async b =>
            {
                Clear();
                await Oy.Publish("?", this);
            });

            Oy.Subscribe <string>("Compile:Output", async data => Append(Color.Black, data));
            Oy.Subscribe <string>("Compile:Error", async data => Append(Color.Red, data));
            Oy.Subscribe <string>("Compile:Information", async data => Append(Color.DodgerBlue, data));
            Oy.Subscribe <string>("Compile:Success", async data => Append(Color.Green, data));
            Oy.Subscribe <string>("Compile:Debug", async data => Append(Color.Magenta, data));

            Oy.Subscribe <Batch>("Compile:Finished", async b =>
            {
                var msg       = b.Successful ? CompileCompletedSuccessfully : CompileFailed;
                var col       = b.Successful ? Color.Green : Color.Red;
                var flowerbox = new string('*', msg.Length + 4);
                Append(col, $"{flowerbox}\r\n* {msg} *\r\n{flowerbox}\r\n");
            });

            _queue = new Subject <int>();
            _queue.Publish().RefCount()
            .Sample(TimeSpan.FromMilliseconds(1000))
            .Subscribe(_ => _control.InvokeLater(UpdateText));
        }
Esempio n. 30
0
        public static void Init()
        {
            Queue = new BufferQueue <SystemLogEntity>();
            var td = new System.Threading.Thread(() =>
            {
                using (TaskDbContext db = new TaskDbContext())
                {
                    while (true)
                    {
                        Queue.Read((item, index) =>
                        {
                            db.SystemLog.Add(item);
                        });
                        db.SaveChanges();
                        System.Threading.Thread.Sleep(5000);
                    }
                }
            });

            td.IsBackground = true;
            td.Start();
        }
Esempio n. 31
0
        void init(SendType type, int clients)
        {
            _listener  = null;
            _sendType  = type;
            _totalSize = new int[clients];
            //_sh = null;
            _client          = new TcpClient[clients];
            _recvThreads     = new Thread[clients];
            _isEndServer     = true;
            _isEndConnection = new bool[clients];
            _callBackFunc    = null;
            _queue           = new BufferQueue[clients];
            _functions       = new InterfaceFunctions[clients];

            for (int i = 0; i < clients; i++)
            {
                _client[i]          = null;
                _queue[i]           = new BufferQueue();
                _functions[i]       = new InterfaceFunctions(this, _queue[i]);
                _totalSize[i]       = 0;
                _isEndConnection[i] = false;
            }
        }
Esempio n. 32
0
 public RiffAviFileWriter(Stream stream)
 {
     this.stream = stream;
       bufferQueue = new BufferQueue();
 }
Esempio n. 33
0
 private void Clear()
 {
     _buffer = new BufferQueue <Output>();
     _queue.OnNext(0);
 }
Esempio n. 34
0
        public void Load()
        {
            _bufferQueue = new BufferQueue<MessageLogRecord>("MessageBufferQueue", BrokerController.Instance.Setting.MessageWriteQueueThreshold, PersistMessages, _logger);
            _chunkManager = new ChunkManager("MessageChunk", BrokerController.Instance.Setting.MessageChunkConfig, BrokerController.Instance.Setting.IsMessageStoreMemoryMode);
            _chunkWriter = new ChunkWriter(_chunkManager);
            _chunkReader = new ChunkReader(_chunkManager, _chunkWriter);

            _chunkManager.Load(ReadMessage);
        }