public NewtonsoftReaderWriterFactory(JsonSerializerSettings settings, ObjectPoolProvider pooling) { _serializerPool = pooling.Create(new JsonSerializerObjectPolicy(settings)); _charPool = ArrayPool <char> .Shared; _bytePool = ArrayPool <byte> .Shared; }
public NewtonsoftSerializerFactory(AdvancedSettings settings, ObjectPoolProvider pooling) { _serializerPool = pooling.Create(new JsonSerializerObjectPolicy(settings.JsonSerialization)); _charPool = ArrayPool <char> .Shared; _bytePool = ArrayPool <byte> .Shared; }
/// <summary> /// Called during deserialization to get the <see cref="JsonSerializer"/>. /// </summary> /// <returns>The <see cref="JsonSerializer"/> used during deserialization.</returns> /// <remarks> /// This method works in tandem with <see cref="ReleaseJsonSerializer(JsonSerializer)"/> to /// manage the lifetimes of <see cref="JsonSerializer"/> instances. /// </remarks> protected virtual JsonSerializer CreateJsonSerializer() { if (_jsonSerializerPool == null) { _jsonSerializerPool = _objectPoolProvider.Create <JsonSerializer>(); } return(_jsonSerializerPool.Get()); }
/// <summary> /// Called during deserialization to get the <see cref="JsonSerializer"/>. /// </summary> /// <returns>The <see cref="JsonSerializer"/> used during deserialization.</returns> /// <remarks> /// This method works in tandem with <see cref="ReleaseJsonSerializer(JsonSerializer)"/> to /// manage the lifetimes of <see cref="JsonSerializer"/> instances. /// </remarks> protected virtual JsonSerializer CreateJsonSerializer() { if (_jsonSerializerPool == null) { _jsonSerializerPool = _objectPoolProvider.Create(new JsonSerializerObjectPolicy(SerializerSettings)); } return(_jsonSerializerPool.Get()); }
private JsonSerializer CreateJsonSerializer() { if (_jsonSerializerPool == null) { _jsonSerializerPool = _objectPoolProvider.Create(new BsonSerializerObjectPolicy(_jsonSerializerSettings)); } return(_jsonSerializerPool.Get()); }
/// <summary> /// Creates a new <see cref="HMACSignatureAlgorithm" />. /// </summary> /// <param name="secret">The shared key of the HMAC algorithm.</param> /// <param name="hashAlgorithm">The name of the hash algorithm to use.</param> public HMACSignatureAlgorithm(string secret, HashAlgorithmName hashAlgorithm) { if (secret == null) { throw new ArgumentNullException(nameof(secret)); } HashAlgorithm = hashAlgorithm; Key = Encoding.UTF8.GetBytes(secret); _hasherPool = PoolProvider.Create(new PooledHMACPolicy(() => CreateHMAC(HashAlgorithm, Key))); }
public static void AddHazel(this IServiceCollection services) { services.TryAddSingleton <ObjectPoolProvider>(new DefaultObjectPoolProvider()); services.AddSingleton(serviceProvider => { ObjectPoolProvider provider = serviceProvider.GetRequiredService <ObjectPoolProvider>(); MessageReaderPolicy policy = ActivatorUtilities.CreateInstance <MessageReaderPolicy>(serviceProvider); return(provider.Create(policy)); }); }
/// <summary> /// Creates an <see cref="ObjectPool{T}"/> that pools <see cref="StringBuilder"/> instances. /// </summary> /// <param name="provider">The <see cref="ObjectPoolProvider"/>.</param> /// <param name="initialCapacity">The initial capacity to initialize <see cref="StringBuilder"/> instances with.</param> /// <param name="maximumRetainedCapacity">The maximum value for <see cref="StringBuilder.Capacity"/> that is allowed to be /// retained, when an instance is returned.</param> /// <returns>The <see cref="ObjectPool{T}"/>.</returns> public static ObjectPool <StringBuilder> CreateStringBuilderPool( this ObjectPoolProvider provider, int initialCapacity, int maximumRetainedCapacity) { var policy = new StringBuilderPooledObjectPolicy() { InitialCapacity = initialCapacity, MaximumRetainedCapacity = maximumRetainedCapacity, }; return(provider.Create <StringBuilder>(policy)); }
/// <summary> /// Adds the <see cref="IRequestExecutorResolver"/> and related services /// to the <see cref="IServiceCollection"/>. /// </summary> /// <param name="services">The <see cref="IServiceCollection"/>.</param> /// <returns>The <see cref="IServiceCollection"/>.</returns> public static IServiceCollection AddGraphQLCore(this IServiceCollection services) { if (services is null) { throw new ArgumentNullException(nameof(services)); } services.AddOptions(); services.TryAddSingleton<ObjectPoolProvider, DefaultObjectPoolProvider>(); services.TryAddSingleton<ObjectPool<StringBuilder>>(sp => { ObjectPoolProvider provider = sp.GetRequiredService<ObjectPoolProvider>(); var policy = new StringBuilderPooledObjectPolicy(); return provider.Create(policy); }); // core services services .TryAddRequestExecutorFactoryOptionsMonitor() .TryAddTypeConverter() .TryAddInputFormatter() .TryAddInputParser() .TryAddDefaultCaches() .TryAddDefaultDocumentHashProvider() .TryAddDefaultBatchDispatcher() .TryAddRequestContextAccessor() .TryAddDefaultDataLoaderRegistry() .TryAddIdSerializer() .TryAddDataLoaderParameterExpressionBuilder() .TryAddDataLoaderOptions(); // pools services .TryAddResultPool() .TryAddResolverTaskPool() .TryAddOperationContextPool() .TryAddDataLoaderTaskCachePool(); // global executor services services .TryAddVariableCoercion() .TryAddRequestExecutorResolver(); // parser services.TryAddSingleton(ParserOptions.Default); return services; }
internal static IServiceCollection TryAddOperationContextPool( this IServiceCollection services) { services.TryAddSingleton <ObjectPool <OperationContext> >(sp => { ObjectPoolProvider provider = sp.GetRequiredService <ObjectPoolProvider>(); var policy = new OperationContextPooledObjectPolicy( sp.GetRequiredService <ObjectPool <ResolverTask> >(), sp.GetRequiredService <ResultPool>()); return(provider.Create(policy)); }); return(services); }
public RoutePatternBinderFactory(UrlEncoder encoder, ObjectPoolProvider objectPoolProvider) { if (encoder == null) { throw new ArgumentNullException(nameof(encoder)); } if (objectPoolProvider == null) { throw new ArgumentNullException(nameof(objectPoolProvider)); } _encoder = encoder; _pool = objectPoolProvider.Create(new UriBuilderContextPooledObjectPolicy()); }
public SocketClient Get(string remoteName) { if (!_objectPoolDict.TryGetValue(remoteName, out ObjectPool <SocketClient> objectPool)) { var option = _options.Remotes.Find(v => v.Name == remoteName); if (option == null) { throw new IndexOutOfRangeException(nameof(remoteName)); } if (_objectPoolProvider is DefaultObjectPoolProvider defaultObjectPoolProvider) { int poolSize = option.PoolSize; defaultObjectPoolProvider.MaximumRetained = poolSize; } objectPool = _objectPoolProvider.Create(new SocketClientPooledObjectPolicy(option, _socketClientProvider)); _objectPoolDict.TryAdd(remoteName, objectPool); } return(objectPool.Get()); }
/// <summary> /// Creates an instance of <see cref="DefaultObjectPool{TaskCache}"/>. /// </summary> /// <param name="provider"> /// The Provider to create the <see cref="DefaultObjectPool{TaskCache}"/> instance. /// </param> /// <param name="cacheSize"> /// The size of pooled caches. /// </param> /// <returns> /// Returns the newly created instance of <see cref="DefaultObjectPool{TaskCache}"/>. /// </returns> public static ObjectPool <TaskCache> Create(ObjectPoolProvider provider, int cacheSize = 256) => provider.Create(new TaskCachePooledObjectPolicy(cacheSize));
/// <summary> /// ctor /// </summary> /// <param name="distributedLockManager">parent object</param> /// <param name="poolProvider"> <see cref="LeakTrackingObjectPoolProvider"/> for example or <see cref="DefaultObjectPoolProvider"/> </param> /// <param name="store">the network transport for example grpc or in-memory implementation</param> public DistributedLock(IDistributedLockManager distributedLockManager, ObjectPoolProvider poolProvider, IDistributedLockStore store) { _manager = distributedLockManager; _handlePool = poolProvider.Create(new DistributedLockHandlePooledObjectPolicy(this)); _store = store; }
/// <summary> /// Creates an <see cref="ObjectPool{T}"/> that pools <see cref="StringBuilder"/> instances. /// </summary> /// <param name="provider">The <see cref="ObjectPoolProvider"/>.</param> /// <returns>The <see cref="ObjectPool{T}"/>.</returns> public static ObjectPool <StringBuilder> CreateStringBuilderPool(this ObjectPoolProvider provider) { return(provider.Create <StringBuilder>(new StringBuilderPooledObjectPolicy())); }
public OwinApplication(AppFunc application) { Application = application; EnvironmentPool = PoolProvider.Create <Dictionary <string, object> >(); }
/// <inheritdoc/> public override ObjectPool <T> Create <T>(IPooledObjectPolicy <T> policy) { var inner = _inner.Create <T>(policy); return(new LeakTrackingObjectPool <T>(inner)); }
/// <summary> /// Create instance of <see cref="ObjectPool{T}"/> using <see cref="PoolProvider"/> and <see cref="StringBuilderPolicy"/>. /// </summary> /// <returns></returns> public static ObjectPool <StringBuilder> CreatePool() => PoolProvider.Create(StringBuilderPolicy);
/// <summary> /// Creates a new <see cref="ECDsaSignatureAlgorithm" />. /// </summary> /// <param name="hashAlgorithm">The name of the hash algorithm to use.</param> /// <param name="ecdsa">The Elliptic Curve Digital Signature Algorithm.</param> public ECDsaSignatureAlgorithm(HashAlgorithmName hashAlgorithm, ECDsa ecdsa) { HashAlgorithm = hashAlgorithm; _ecdsa = ecdsa ?? throw new ArgumentNullException(nameof(ecdsa)); _hasherPool = PoolProvider.Create(new PooledHashAlgorithmPolicy(() => HashAlgorithmFactory.Create(HashAlgorithm))); }
/// <summary> /// ctor /// </summary> /// <param name="config"></param> /// <param name="poolProvider"> <see cref="LeakTrackingObjectPoolProvider"/> for example or <see cref="DefaultObjectPoolProvider"/> </param> /// <param name="transport">the network transport for example grpc or in-memory implementation</param> public DistributedLockManager(DistributedLockManagerConfig config, ObjectPoolProvider poolProvider, IDistributedLockStore transport) { _config = config; _transport = transport; _lockPool = poolProvider.Create(new DistributedLockPooledObjectPolicy(this, poolProvider, _transport)); }