public T get(int length) { T resource = getCachedBuffer(); if (resource == null || getResourceCapacity(resource) < length) { resource = createResource(length); tryCacheResource(resource); } else if (shouldExpunge(length, resource)) { _usedTooSmallBuffer = 0; resource = createResource(length); tryCacheResource(resource); } else { prepareResource(resource, length); } return resource; }
public void notifyUsedSize(int usedSize) { T resource = getCachedBuffer(); if (resource == null) return; if (shouldExpunge(usedSize, resource)) _cachedResource = null; }
public void set(T resource) { if (getResourceCapacity(resource) > _maxCachedBufferLength) return; tryCacheResource(resource); _usedTooSmallBuffer = 0; }
public T get() { T resource = getCachedBuffer(); if (resource == null) { resource = createResource(_defaultResourceLength); tryCacheResource(resource); } else { prepareResource(resource); } return resource; }
public long getLength() { T cachedBuffer = getCachedBuffer(); if (cachedBuffer == null) return 0; return getResourceCapacity(cachedBuffer); }
@Override public ContextClassResolverCompressedMarshObjectConvertor allocate( final IMemoryAwareResourcePool resourcePool) { return new ContextClassResolverCompressedMarshObjectConvertor(9, SmartLengthBasedCache.toCacheCallback(resourcePool)); } }
private boolean shouldExpunge(int length, T resource) { return length < ((double) getResourceCapacity(resource) * _expungeRatio) && _usedTooSmallBuffer++ >= _expungeCount; }
@Override public CompressedMarshObjectConvertor allocate( IMemoryAwareResourcePool resourcePool) { return new CompressedMarshObjectConvertor(9, SmartLengthBasedCache.toCacheCallback(resourcePool)); } }
protected void tryCacheResource(T resource) { int resourceCapacity = getResourceCapacity(resource); if (resourceCapacity > _maxCachedBufferLength) return; if (_callback != null && !_callback.mayCache(resourceCapacity)) return; _cachedResource = new SoftReference<T>(resource); }
@Override public MarshObjectConvertor allocate( final IMemoryAwareResourcePool resourcePool) { return new MarshObjectConvertor(SmartLengthBasedCache.toCacheCallback(resourcePool)); } }
@Override public MarshObjectConvertor allocate( IMemoryAwareResourcePool resourcePool) { return new ContextClassResolverMarshObjectConvertor(SmartLengthBasedCache.toCacheCallback(resourcePool)); } }