protected override object OnDeserialize(Stream stream, Type itemType) { var ser = _pool.New(); var obj = ser.Deserialize(stream, itemType); _pool.Store(ser); return(obj); }
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); }
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); }
protected override void OnSerialize(Stream stream, object item, Type itemType) { var ser = SerPool.New(); ser.Serialize(stream, item, itemType); SerPool.Store(ser); }
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); }
protected override object OnDeserialize(Stream stream, Type itemType) { var des = DeserPool.New(); var value = des.Deserialize(stream); DeserPool.Store(des); return(value); }
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); }
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}."); }
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); }
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); }