/** * Get the next available array, either from the cache or a brand new one */ private byte[] acquire() { return _available.acquire(); }
/** * Call at shutdown/startup to not hold ctx refs * @since 0.9.2 */ public static void clearCache() { if (CACHE) { PacketFactory.context = null; _packetCache.clear(); } }
/** * Put this array back onto the available cache for reuse */ private void releaseIt(byte[] entry) { if (entry == null || entry.length != _entrySize) return; // should be safe without this //Arrays.fill(entry, (byte) 0); _available.release(entry); }
private SimpleByteCache(int maxCachedEntries, int entrySize) { _available = new TryCache<byte[]>(new ByteArrayFactory(entrySize), maxCachedEntries); _entrySize = entrySize; }
/** * Return a read buffer to the pool. * These buffers must be from acquireBuf(), i.e. capacity() == BUF_SIZE. * High-frequency path in thread. */ public static void releaseBuf(ByteBuffer buf) { // double check if (buf.capacity() < BUF_SIZE) { I2PAppContext.getGlobalContext().logManager().getLog(EventPumper.class).error("Bad size " + buf.capacity(), new Exception()); return; } buf.clear(); _bufferCache.release(buf); }
/** * High-frequency path in thread. */ private ByteBuffer acquireBuf() { return _bufferCache.acquire(); }
/** * Clear everything (memory pressure) */ private void clear() { _available.clear(); } }
public synchronized void release() { verifyNotReleased(); _released = true; //_releasedBy = new Exception("released by"); //_acquiredBy = null; // //_dataCache.release(_dataBuf); if (_bandwidthRequest != null) { synchronized(_bandwidthRequest) { if (_bandwidthRequest.getPendingRequested() > 0) _bandwidthRequest.abort(); } _bandwidthRequest = null; } if (!CACHE) return; _packetCache.release(this); }
/** * @param inbound unused */ public static UDPPacket acquire(RouterContext ctx, boolean inbound) { UDPPacket rv; if (CACHE) { PacketFactory.context = ctx; rv = _packetCache.acquire(); rv.init(ctx); } else { rv = new UDPPacket(ctx); } return rv; }
public final void release(ByteArray entry, boolean shouldZero) { if (entry == null || entry.getData() == null) return; if (entry.getData().length != _entrySize) { Log log = I2PAppContext.getGlobalContext().logManager().getLog(ByteCache.class); if (log.shouldLog(Log.WARN)) log.warn("Bad size", new Exception("I did it")); return; } entry.setValid(0); entry.setOffset(0); if (shouldZero) Arrays.fill(entry.getData(), (byte)0x0); super.release(entry); }