Exemplo n.º 1
0
    public void SetMinimapData(Vector2Int baseCoord, IMapDataView targetView, Action <IMapDataView> onResolvedCallback, Action <IMapDataView> onRejectedCallback)
    {
        if (targetView.HasMinimapSceneInfo())
        {
            onResolvedCallback?.Invoke(targetView);
            return;
        }

        targetView.SetBaseCoord(baseCoord);

        var info = MinimapMetadata.GetMetadata().GetSceneInfo(baseCoord.x, baseCoord.y);

        if (info != null)
        {
            targetView.SetMinimapSceneInfo(info);
            onResolvedCallback?.Invoke(targetView);
        }
        else
        {
            PendingData pending = null;
            if (!pendingSceneData.TryGetValue(baseCoord, out pending))
            {
                pending = new PendingData();
                pendingSceneData.Add(baseCoord, pending);
            }

            pending.AddPending(targetView, onResolvedCallback, onRejectedCallback);
        }
    }
Exemplo n.º 2
0
        public void Clear()
        {
            if (mBuffered != null)
            {
                mBuffered.Release();
                mBuffered = null;
            }

            while (mPendingQueue.Count > 0)
            {
                mPendingQueue.Dequeue().Release();
            }
        }
Exemplo n.º 3
0
        public PendingData CheckFlushReady()
        {
            PendingData gram = null;

            if (mPendingQueue.Count == 0 && mBuffered != null)
            {
                gram = mBuffered;

                mPendingQueue.Enqueue(mBuffered);
                mBuffered = null;
            }

            return(gram);
        }
Exemplo n.º 4
0
			public static PendingData Acquire() {
				lock( mPoolStack ) {
					PendingData gram;

					if( mPoolStack.Count > 0 )
						gram = mPoolStack.Pop();
					else
						gram = new PendingData();

					gram.mBuffer = AcquireBuffer();
					gram.mLength = 0;

					return gram;
				}
			}
Exemplo n.º 5
0
        public PendingData Dequeue()
        {
            PendingData gram = null;

            if (mPendingQueue.Count > 0)
            {
                mPendingQueue.Dequeue().Release();

                if (mPendingQueue.Count > 0)
                {
                    gram = mPendingQueue.Peek();
                }
            }

            return(gram);
        }
Exemplo n.º 6
0
            public static PendingData Acquire()
            {
                lock ( mPoolStack ) {
                    PendingData gram;

                    if (mPoolStack.Count > 0)
                    {
                        gram = mPoolStack.Pop();
                    }
                    else
                    {
                        gram = new PendingData();
                    }

                    gram.mBuffer = AcquireBuffer();
                    gram.mLength = 0;

                    return(gram);
                }
            }
Exemplo n.º 7
0
        public PendingData Enqueue(byte[] buffer, int offset, int length)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            else if (!(offset >= 0 && offset < buffer.Length))
            {
                throw new ArgumentOutOfRangeException("offset", offset, "Offset must be greater than or equal to zero and less than the size of the buffer.");
            }
            else if (length < 0 || length > buffer.Length)
            {
                throw new ArgumentOutOfRangeException("length", length, "Length cannot be less than zero or greater than the size of the buffer.");
            }
            else if ((buffer.Length - offset) < length)
            {
                throw new ArgumentException("Offset and length do not point to a valid segment within the buffer.");
            }

            int existingBytes = (mPendingQueue.Count * mCoalesceBufferSize) + (mBuffered == null ? 0 : mBuffered.Length);

            if ((existingBytes + length) > PendingCap)
            {
                throw new CapacityExceededException();
            }

            PendingData gram = null;

            while (length > 0)
            {
                if (mBuffered == null)
                {
                    mBuffered = PendingData.Acquire();
                }

                int bytesWritten = mBuffered.Write(buffer, offset, length);

                offset += bytesWritten;
                length -= bytesWritten;

                if (mBuffered.IsFull)
                {
                    if (mPendingQueue.Count == 0)
                    {
                        gram = mBuffered;
                        System.Diagnostics.Debug.WriteLine("Gram.Enqueue(): _buffered IsFull, will send, _buffered.Length is " + mBuffered.Length);
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("Gram.Enqueue(): _buffered IsFull but _pending.Count is " + mPendingQueue.Count);
                    }

                    mPendingQueue.Enqueue(mBuffered);
                    mBuffered = null;
                }
            }

            if (gram == null)
            {
                System.Diagnostics.Debug.WriteLine("Gram.Enqueue(): no Packet send, still Available: " + mBuffered.Available);
            }

            return(gram);
        }
Exemplo n.º 8
0
		public void Clear() {
			if( mBuffered != null ) {
				mBuffered.Release();
				mBuffered = null;
			}

			while( mPendingQueue.Count > 0 )
				mPendingQueue.Dequeue().Release();

		}
Exemplo n.º 9
0
		public PendingData Enqueue( byte[] buffer, int offset, int length ) {
			if( buffer == null ) {
				throw new ArgumentNullException( "buffer" );
			} else if( !( offset >= 0 && offset < buffer.Length ) ) {
				throw new ArgumentOutOfRangeException( "offset", offset, "Offset must be greater than or equal to zero and less than the size of the buffer." );
			} else if( length < 0 || length > buffer.Length ) {
				throw new ArgumentOutOfRangeException( "length", length, "Length cannot be less than zero or greater than the size of the buffer." );
			} else if( ( buffer.Length - offset ) < length ) {
				throw new ArgumentException( "Offset and length do not point to a valid segment within the buffer." );
			}

			int existingBytes = ( mPendingQueue.Count * mCoalesceBufferSize ) + ( mBuffered == null ? 0 : mBuffered.Length );
			if( ( existingBytes + length ) > PendingCap )
				throw new CapacityExceededException();

			PendingData gram = null;
			while( length > 0 ) {
				if( mBuffered == null )
					mBuffered = PendingData.Acquire();

				int bytesWritten = mBuffered.Write( buffer, offset, length );

				offset += bytesWritten;
				length -= bytesWritten;

				if( mBuffered.IsFull ) {
					if( mPendingQueue.Count == 0 ) {
						gram = mBuffered;
						System.Diagnostics.Debug.WriteLine( "Gram.Enqueue(): _buffered IsFull, will send, _buffered.Length is " + mBuffered.Length );
					} else {
						System.Diagnostics.Debug.WriteLine( "Gram.Enqueue(): _buffered IsFull but _pending.Count is " + mPendingQueue.Count );
					}

					mPendingQueue.Enqueue( mBuffered );
					mBuffered = null;
				}
			}

			if( gram == null )
				System.Diagnostics.Debug.WriteLine( "Gram.Enqueue(): no Packet send, still Available: " + mBuffered.Available );

			return gram;
		}
Exemplo n.º 10
0
		public PendingData CheckFlushReady() {
			PendingData gram = null;
			if( mPendingQueue.Count == 0 && mBuffered != null ) {
				gram = mBuffered;

				mPendingQueue.Enqueue( mBuffered );
				mBuffered = null;
			}

			return gram;
		}
        private async Task GetPendingCounterData(Counter counter)
        {
            this.UpdateCounterWithLatestTimestamps(counter);

            DateTimeOffset lastPending = DateTimeOffset.MinValue;
            PendingData    pendingData = counter.DataSet.GetNextPendingData(lastPending);

            if (pendingData == null)
            {
                return;
            }

            do
            {
                if (this.disposed)
                {
                    return;
                }

                lastPending = pendingData.StartTime;

                // TODO: Move below method to DateTimeOffset too.
                using (var aggregator =
                           PersistedDataProtocol.CreateAggregatorForSampleType((MetricSystem.PersistedDataType)counter.DataSet.PersistedDataType,
                                                                               counter.Name,
                                                                               counter.DataSet.DimensionSet,
                                                                               pendingData.Sources,
                                                                               new DateTime(
                                                                                   pendingData.StartTime.DateTime.Ticks,
                                                                                   DateTimeKind.Utc),
                                                                               new DateTime(pendingData.EndTime.DateTime.Ticks,
                                                                                            DateTimeKind.Utc),
                                                                               this.dataManager.MemoryStreamManager))
                {
                    var timeout = TimeoutTiers[ServerCountTiers.Length - 1];
                    for (var i = 0; i < ServerCountTiers.Length; ++i)
                    {
                        if (pendingData.Sources.Count <= ServerCountTiers[i])
                        {
                            timeout = TimeoutTiers[i];
                            break;
                        }
                    }
                    aggregator.MaxFanout = MaxFanout;
                    aggregator.Timeout   = timeout;

                    Events.Write.BeginRetrieveCounterData(counter.Name, pendingData.StartTime, pendingData.EndTime,
                                                          timeout, pendingData.Sources);
                    var success = await aggregator.Run();

                    if (success)
                    {
                        counter.DataSet.UpdateFromAggregator(aggregator, pendingData.StartTime, pendingData.EndTime);
                    }

                    Events.Write.EndRetrieveCounterData(counter.Name, success);
                }

                this.UpdateCounterWithLatestTimestamps(counter);
            } while ((pendingData = counter.DataSet.GetNextPendingData(lastPending)) != null);

            lock (this.activeWorkers)
            {
                this.activeWorkers.Remove(counter.Name);
            }
        }