/// <summary> /// Construct a new shared-reference that will 'own' the supplied /// <code>value</code>. /// The reference count will be set to 1. /// When the reference count decreases to zero <code>resourceReleaser</code> /// will be used to release the <code>value</code>. /// </summary> /// <param name="value">Non-null value to manage.</param> /// <param name="resourceReleaser"> /// Non-null ResourceReleaser for the value. /// </param> public SharedReference(T value, IResourceReleaser <T> resourceReleaser) { _value = Preconditions.CheckNotNull(value); _resourceReleaser = Preconditions.CheckNotNull(resourceReleaser); _refCount = 1; AddLiveReference(value); }
public void Initialize() { _bitmap = new SoftwareBitmap(BitmapPixelFormat.Rgba8, 1, 1); IResourceReleaser <SoftwareBitmap> resourceReleaser = SimpleBitmapReleaser.Instance; _closeableStaticBitmap = new CloseableStaticBitmap( _bitmap, resourceReleaser, ImmutableQualityInfo.FULL_QUALITY, 0); }
/// <summary> /// Instantiates the <see cref="FlexByteArrayPool"/>. /// </summary> /// <param name="memoryTrimmableRegistry"> /// A class to be notified of system memory events. /// </param> /// <param name="args">The pool params.</param> public FlexByteArrayPool( IMemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams args) { Preconditions.CheckArgument(args.MaxNumThreads > 0); _delegatePool = new SoftRefByteArrayPool( memoryTrimmableRegistry, args, NoOpPoolStatsTracker.Instance); _resourceReleaser = new ResourceReleaserImpl <byte[]>(value => Release(value)); }
/// <summary> /// Constructs a CloseableReference (wrapping a SharedReference) of T with /// provided IResourceReleaser{T}. If t is null, this will just return null. /// </summary> public static CloseableReference <T> of(T t, IResourceReleaser <T> resourceReleaser) { if (t == null) { return(null); } else { return(new CloseableReference <T>(t, resourceReleaser)); } }
/// <summary> /// Instantiates the <see cref="PooledByteArrayBufferedInputStream"/>. /// </summary> public PooledByteArrayBufferedInputStream( Stream inputStream, byte[] byteArray, IResourceReleaser <byte[]> resourceReleaser) { _inputStream = Preconditions.CheckNotNull(inputStream); _byteArray = Preconditions.CheckNotNull(byteArray); _resourceReleaser = Preconditions.CheckNotNull(resourceReleaser); _bufferedSize = 0; _bufferOffset = 0; _closed = false; }
/// <summary> /// Creates a new instance of a CloseableStaticBitmap. /// </summary> public CloseableStaticBitmap( SoftwareBitmap bitmap, IResourceReleaser <SoftwareBitmap> resourceReleaser, IQualityInfo qualityInfo, int rotationAngle) { _bitmap = Preconditions.CheckNotNull(bitmap); _bitmapReference = CloseableReference <SoftwareBitmap> .of( _bitmap, Preconditions.CheckNotNull(resourceReleaser)); _qualityInfo = qualityInfo; _rotationAngle = rotationAngle; }
public void Initialize() { _bitmap = new SoftwareBitmap(BitmapPixelFormat.Rgba8, 50, 50); _releaseCallCount = 0; _resourceReleaser = new ResourceReleaserImpl <SoftwareBitmap>( b => { b.Dispose(); ++_releaseCallCount; }); _closeableStaticBitmap = new CloseableStaticBitmap( _bitmap, _resourceReleaser, ImmutableQualityInfo.FULL_QUALITY, 0); }
/// <summary> /// Registrazione di una classe che, implementando /// l'interfaccia "IResourceReleaser", definisce /// la logica relativa al rilascio delle risorse /// </summary> /// <param name="releaser"></param> public static void Register(IResourceReleaser releaser) { if (!IsRegistered(releaser.GetType())) { ArrayList list = GetListReleaser(); if (list == null) { list = new ArrayList(); HttpContext.Current.Session.Add(SESSION_KEY, list); } list.Add(releaser); } }
/// <summary> /// Releases the resource specified by the given key. /// </summary> /// <typeparam name="TKey">The type of the key.</typeparam> /// <param name="key">The key.</param> /// <exception cref="System.NotSupportedException">The type of the key and/or resource is not supported by this manager.</exception> /// <exception cref="System.ArgumentNullException"><paramref name="key" /> is null.</exception> public void Release <TKey>(TKey key) { if (key == null) { throw new ArgumentNullException(nameof(key)); } IResourceReleaser <TKey> rm = this as IResourceReleaser <TKey>; if (rm == null) { throw new NotSupportedException(Strings.ResourceManager_TypesNotSupported); } rm.Release(key); }
public void Initialize() { _resourceReleaser = new ResourceReleaserImpl <int>(_ => { }); _dataSubscriber = new MockDataSubscriber <IList <CloseableReference <int> > >(); _settableDataSource1 = SettableDataSource <int> .Create <int>(); _settableDataSource2 = SettableDataSource <int> .Create <int>(); _listDataSource = ListDataSource <int> .Create(_settableDataSource1, _settableDataSource2); _ref1 = CloseableReference <int> .of(1, _resourceReleaser); _ref2 = CloseableReference <int> .of(2, _resourceReleaser); _runtimeException = new Exception(); _listDataSource.Subscribe(_dataSubscriber, CallerThreadExecutor.Instance); }
/// <summary> /// Instantiates the <see cref="BitmapCounter"/>. /// </summary> public BitmapCounter(int maxCount, int maxSize) { Preconditions.CheckArgument(maxCount > 0); Preconditions.CheckArgument(maxSize > 0); _maxCount = maxCount; _maxSize = maxSize; _unpooledBitmapsReleaser = new ResourceReleaserImpl <SoftwareBitmap>(value => { try { Decrease(value); } finally { value.Dispose(); } }); }
public void Initialize() { _releaseCallCount = 0; _releaseValues = new List <int>(); _releaser = new ResourceReleaserImpl <int>( v => { ++_releaseCallCount; _releaseValues.Add(v); }); _onExclusivityChangedCallCount = 0; _isExclusive = null; _entryStateObserver = new EntryStateObserverImpl <string>( (v, b) => { ++_onExclusivityChangedCallCount; _isExclusive = b; }); _cacheTrimStrategy = new CacheTrimStrategyImpl(v => _trimRatio); _valueDescriptor = new ValueDescriptorImpl <int>(v => v); _params = new MemoryCacheParams( CACHE_MAX_SIZE, CACHE_MAX_COUNT, CACHE_EVICTION_QUEUE_MAX_SIZE, CACHE_EVICTION_QUEUE_MAX_COUNT, CACHE_ENTRY_MAX_SIZE); _paramsSupplier = new MockSupplier <MemoryCacheParams>(_params); _platformBitmapFactory = new MockPlatformBitmapFactory(); _bitmap = new SoftwareBitmap(BitmapPixelFormat.Rgba8, 50, 50); _bitmapReference = CloseableReference <SoftwareBitmap> .of( _bitmap, BITMAP_RESOURCE_RELEASER); _cache = new CountingMemoryCache <string, int>( _valueDescriptor, _cacheTrimStrategy, _paramsSupplier, _platformBitmapFactory, true); }
/// <summary> /// Rilascio di una risorsa registrata /// </summary> /// <param name="releaserType"></param> public static void Release(Type releaserType) { ArrayList list = GetListReleaser(); if (list != null) { IResourceReleaser itemToRemove = null; foreach (IResourceReleaser item in list) { if (item.GetType().Equals(releaserType)) { item.ReleaseResources(); itemToRemove = item; break; } } list.Remove(itemToRemove); } }
public ResourceLease(T resource, IResourceReleaser <T> releaser) { Resource = resource; _releaser = releaser; }
private CloseableReference(T t, IResourceReleaser <T> resourceReleaser) { // Ref-count pre-set to 1 _sharedReference = new SharedReference <T>(t, resourceReleaser); }
public void Initialize() { // Initializes the mock RequestListener ProducerListenerImpl producerListener = new ProducerListenerImpl( (_, __) => { }, (_, __, ___) => { }, (_, __, ___) => { }, (_, __, ___, ____) => { }, (_, __, ___) => { }, (_) => { return(false); }); _requestListener = new RequestListenerImpl( producerListener, (imageRequest, callerContext, requestId, isPrefetch) => { _onRequestStartInvocation = true; _internalImageRequest = imageRequest; _internalCallerContext = callerContext; _internalRequestId = requestId; _internalIsPrefetch = isPrefetch; }, (imageRequest, requestId, isPrefetch) => { _onRequestSuccessInvocation = true; _internalImageRequest = imageRequest; _internalRequestId = requestId; _internalIsPrefetch = isPrefetch; }, (imageRequest, requestId, exception, isPrefetch) => { _onRequestFailureInvocation = true; _internalImageRequest = imageRequest; _internalRequestId = requestId; _internalException = exception; _internalIsPrefetch = isPrefetch; }, (requestId) => { _onRequestCancellationInvocation = true; _internalRequestId = requestId; }); _resourceReleaser = new ResourceReleaserImpl <object>(_ => { }); _resultRef1 = CloseableReference <object> .of(new object(), _resourceReleaser); _resultRef2 = CloseableReference <object> .of(new object(), _resourceReleaser); _resultRef3 = CloseableReference <object> .of(new object(), _resourceReleaser); _dataSubscriber1 = new MockDataSubscriber <CloseableReference <object> >(); _dataSubscriber2 = new MockDataSubscriber <CloseableReference <object> >(); _internalIsPrefetch = true; _settableProducerContext = new SettableProducerContext( IMAGE_REQUEST, REQUEST_ID, producerListener, CALLER_CONTEXT, RequestLevel.FULL_FETCH, IS_PREFETCH, true, Priority.HIGH); _producer = new ProducerImpl <CloseableReference <object> >( (consumer, _) => { _internalConsumer = consumer; }); _dataSource = CloseableProducerToDataSourceAdapter <object> .Create( _producer, _settableProducerContext, _requestListener); Assert.IsTrue(_onRequestStartInvocation); Assert.AreSame(_internalImageRequest, IMAGE_REQUEST); Assert.AreSame(_internalCallerContext, CALLER_CONTEXT); Assert.AreSame(_internalRequestId, REQUEST_ID); Assert.IsFalse(_internalIsPrefetch); Assert.IsNotNull(_internalConsumer); _onRequestStartInvocation = false; _dataSource.Subscribe(_dataSubscriber1, CallerThreadExecutor.Instance); }