move TryCache to core

This commit is contained in:
zab2
2018-07-04 16:09:11 +00:00
parent d42a467c00
commit 11e00ba9cb
3 changed files with 9 additions and 9 deletions

View File

@ -1,4 +1,4 @@
package net.i2p.router.util;
package net.i2p.util;
import java.util.ArrayList;
import java.util.List;
@ -41,7 +41,7 @@ public class TryCache<T> {
/**
* @return a cached or newly created item from this cache
*/
public T tryAcquire() {
public T acquire() {
T rv = null;
if (lock.tryLock()) {
try {
@ -64,7 +64,7 @@ public class TryCache<T> {
* the cache has reached capacity or it's lock is held by
* another thread.
*/
public void tryRelease(T item) {
public void release(T item) {
if (lock.tryLock()) {
try {
if (items.size() < capacity) {

View File

@ -28,7 +28,7 @@ import net.i2p.data.router.RouterIdentity;
import net.i2p.router.CommSystemFacade.Status;
import net.i2p.router.RouterContext;
import net.i2p.router.transport.FIFOBandwidthLimiter;
import net.i2p.router.util.TryCache;
import net.i2p.util.TryCache;
import net.i2p.util.Addresses;
import net.i2p.util.ConcurrentHashSet;
import net.i2p.util.I2PThread;
@ -462,7 +462,7 @@ class EventPumper implements Runnable {
* High-frequency path in thread.
*/
private ByteBuffer acquireBuf() {
return _bufferCache.tryAcquire();
return _bufferCache.acquire();
}
/**
@ -471,7 +471,7 @@ class EventPumper implements Runnable {
* High-frequency path in thread.
*/
public static void releaseBuf(ByteBuffer buf) {
_bufferCache.tryRelease(buf);
_bufferCache.release(buf);
}
private void processAccept(SelectionKey key) {

View File

@ -12,7 +12,7 @@ import net.i2p.data.SessionKey;
import net.i2p.router.RouterContext;
import net.i2p.router.transport.FIFOBandwidthLimiter;
import net.i2p.router.util.CDQEntry;
import net.i2p.router.util.TryCache;
import net.i2p.util.TryCache;
import net.i2p.util.Addresses;
import net.i2p.util.Log;
import net.i2p.util.SystemVersion;
@ -407,7 +407,7 @@ class UDPPacket implements CDQEntry {
UDPPacket rv = null;
if (CACHE) {
PacketFactory.context = ctx;
rv = _packetCache.tryAcquire();
rv = _packetCache.acquire();
rv.init(ctx);
}
if (rv == null)
@ -439,7 +439,7 @@ class UDPPacket implements CDQEntry {
}
if (!CACHE)
return;
_packetCache.tryRelease(this);
_packetCache.release(this);
}
/**