예제 #1
0
        protected override object OnDeserialize(Stream stream, Type itemType)
        {
            var ser = _pool.New();
            var obj = ser.Deserialize(stream, itemType);

            _pool.Store(ser);
            return(obj);
        }
예제 #2
0
        public MultiArray <byte> Compress(MultiArray <byte> source)
        {
            var msDes = _recMemStream.New();

            using (var msOrg = source.AsReadOnlyStream())
                Compress(msOrg, msDes);
            var value = msDes.GetMultiArray();

            msDes.Reset();
            _recMemStream.Store(msDes);
            return(value);
        }
예제 #3
0
        public void Serialize(object item, Type itemType, Stream stream)
        {
            if (Compressor is null)
            {
                OnSerialize(stream, item, itemType);
                return;
            }
            var ms = _recMemStream.New();

            OnSerialize(ms, item, itemType);
            ms.Position = 0;
            Compressor.Compress(ms, stream);
            ms.Reset();
            _recMemStream.Store(ms);
        }
예제 #4
0
        protected override void OnSerialize(Stream stream, object item, Type itemType)
        {
            var ser = SerPool.New();

            ser.Serialize(stream, item, itemType);
            SerPool.Store(ser);
        }
예제 #5
0
        public Task WriteAsync(TraceItem item)
        {
            if (_isDirty || _cItems == null)
            {
                if (_items == null)
                {
                    return(Task.CompletedTask);
                }
                lock (_locker)
                {
                    _cItems = new List <ITraceStorage>(_items);
                }
            }
            var tsks = _procTaskPool.New();

            for (var i = 0; i < _cItems.Count; i++)
            {
                tsks.Add(InternalWriteAsync(_cItems[i], item));
            }
            var resTask = Task.WhenAll(tsks).ContinueWith(_ =>
            {
                tsks.Clear();
                _procTaskPool.Store(tsks);
            });

            return(resTask);
        }
예제 #6
0
        protected override object OnDeserialize(Stream stream, Type itemType)
        {
            var des   = DeserPool.New();
            var value = des.Deserialize(stream);

            DeserPool.Store(des);
            return(value);
        }
예제 #7
0
        public async Task <StatusCollection> GetAll()
        {
            var statusHttpServices = DiscoveryService.GetLocalRegisteredServices("STATUS.HTTP").DistinctBy(srv => srv.ApplicationName);
            var collection         = new StatusCollection();
            var getTasks           = new List <(Task <string> Data, string IpAddress, string Port, WebClient Client)>();

            foreach (var srv in statusHttpServices)
            {
                if (!(srv.Data.GetValue() is Dictionary <string, object> data))
                {
                    continue;
                }
                if (!data.TryGetValue("Port", out var port))
                {
                    continue;
                }
                var client     = WebClients.New();
                var clientTask = client.DownloadStringTaskAsync($"http://{srv.Addresses[0]}:{port}/xml");
                getTasks.Add((clientTask, srv.Addresses[0].ToString(), port.ToString(), client));
            }
            await Task.WhenAll(getTasks.Select(i => i.Data)).ConfigureAwait(false);

            foreach (var item in getTasks)
            {
                var statusCollection = item.Data.Result.DeserializeFromXml <StatusItemCollection>();
                collection.Statuses.Add(new StatusCollectionItem {
                    Data = statusCollection, IpAddress = item.IpAddress, Port = item.Port
                });
                WebClients.Store(item.Client);
            }
            collection.Statuses.Sort((x, y) =>
            {
                var cmp = string.Compare(x.Data.EnvironmentName, y.Data.EnvironmentName, StringComparison.Ordinal);
                if (cmp == 0)
                {
                    cmp = string.Compare(x.Data.MachineName, y.Data.MachineName, StringComparison.Ordinal);
                }
                if (cmp == 0)
                {
                    cmp = string.Compare(x.Data.ApplicationName, y.Data.ApplicationName, StringComparison.Ordinal);
                }
                return(cmp);
            });
            return(collection);
        }
예제 #8
0
        public async Task <RPCResponseMessage> InvokeMethodAsync(RPCRequestMessage messageRq)
        {
            if (!_shouldBeConnected)
            {
                await ConnectAsync().ConfigureAwait(false);
            }
            if (_connectionCancellationToken.IsCancellationRequested)
            {
                return(null);
            }
            var handler = _messageHandlerPool.New();

            while (!_messageResponsesHandlers.TryAdd(messageRq.MessageId, handler))
            {
                await Task.Yield();
            }
            if (_currentIndex > ResetIndex)
            {
                _currentIndex = -1;
            }
            bool sent;

            do
            {
                var client = _clients[Interlocked.Increment(ref _currentIndex) % _socketsPerClient];
                sent = await client.SendRpcMessageAsync(messageRq).ConfigureAwait(false);
            } while (!sent);
            await handler.Event.WaitAsync(InvokeMethodTimeout, _connectionCancellationToken).ConfigureAwait(false);

            if (handler.Event.IsSet)
            {
                var msg = handler.Message;
                _messageHandlerPool.Store(handler);
                return(msg);
            }
            _messageHandlerPool.Store(handler);
            _connectionCancellationToken.ThrowIfCancellationRequested();
            throw new TimeoutException($"Timeout of {InvokeMethodTimeout / 1000} seconds has been reached waiting the response from the server with Id={messageRq.MessageId}.");
        }
예제 #9
0
        public bool TryRemove(string key, out StorageItemMeta removedMeta)
        {
            if (_storageWorker.Status != WorkerStatus.Started && _storageWorker.Status != WorkerStatus.Stopped)
            {
                Core.Log.Warning("The storage is disposing, modifying the collection is forbidden.");
                removedMeta = null;
                return(false);
            }

            if (_pendingItems.TryRemove(key, out _))
            {
                Interlocked.Decrement(ref _pendingItemsCount);
            }

            _globalMetas.TryRemove(key, out _);
            if (!_metas.TryRemove(key, out var meta))
            {
                removedMeta = null;
                return(false);
            }

            Interlocked.Decrement(ref _metasCount);
            meta.Dispose();

            if (_storageWorker.Count >= _storage.SlowDownWriteThreshold)
            {
                Core.Log.Warning("The storage working has reached his maximum capacity, slowing down the collection modification.");
                TaskHelper.SleepUntil(() => _storageWorker.Count < _storage.SlowDownWriteThreshold).WaitAsync();
            }

            var fstoItem = FileStoragePool.New();

            fstoItem.Meta = meta;
            fstoItem.Type = FileStorageMetaLog.TransactionType.Remove;
            _storageWorker.Enqueue(fstoItem);
            removedMeta = meta;
            return(true);
        }
예제 #10
0
        public async Task WriteAsync(TraceItem item)
        {
            var cItems = _cItems;
            var tsks   = _procTaskPool.New();

            for (var i = 0; i < cItems.Length; i++)
            {
                tsks.Add(InternalWriteAsync(_cItems[i], item));
            }
            await Task.WhenAll(tsks).ConfigureAwait(false);

            tsks.Clear();
            _procTaskPool.Store(tsks);
        }