forked from I2P_Developers/i2p.i2p
move TryCache to core
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
package net.i2p.router.util;
|
package net.i2p.util;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -41,7 +41,7 @@ public class TryCache<T> {
|
|||||||
/**
|
/**
|
||||||
* @return a cached or newly created item from this cache
|
* @return a cached or newly created item from this cache
|
||||||
*/
|
*/
|
||||||
public T tryAcquire() {
|
public T acquire() {
|
||||||
T rv = null;
|
T rv = null;
|
||||||
if (lock.tryLock()) {
|
if (lock.tryLock()) {
|
||||||
try {
|
try {
|
||||||
@ -64,7 +64,7 @@ public class TryCache<T> {
|
|||||||
* the cache has reached capacity or it's lock is held by
|
* the cache has reached capacity or it's lock is held by
|
||||||
* another thread.
|
* another thread.
|
||||||
*/
|
*/
|
||||||
public void tryRelease(T item) {
|
public void release(T item) {
|
||||||
if (lock.tryLock()) {
|
if (lock.tryLock()) {
|
||||||
try {
|
try {
|
||||||
if (items.size() < capacity) {
|
if (items.size() < capacity) {
|
@ -28,7 +28,7 @@ import net.i2p.data.router.RouterIdentity;
|
|||||||
import net.i2p.router.CommSystemFacade.Status;
|
import net.i2p.router.CommSystemFacade.Status;
|
||||||
import net.i2p.router.RouterContext;
|
import net.i2p.router.RouterContext;
|
||||||
import net.i2p.router.transport.FIFOBandwidthLimiter;
|
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.Addresses;
|
||||||
import net.i2p.util.ConcurrentHashSet;
|
import net.i2p.util.ConcurrentHashSet;
|
||||||
import net.i2p.util.I2PThread;
|
import net.i2p.util.I2PThread;
|
||||||
@ -462,7 +462,7 @@ class EventPumper implements Runnable {
|
|||||||
* High-frequency path in thread.
|
* High-frequency path in thread.
|
||||||
*/
|
*/
|
||||||
private ByteBuffer acquireBuf() {
|
private ByteBuffer acquireBuf() {
|
||||||
return _bufferCache.tryAcquire();
|
return _bufferCache.acquire();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -471,7 +471,7 @@ class EventPumper implements Runnable {
|
|||||||
* High-frequency path in thread.
|
* High-frequency path in thread.
|
||||||
*/
|
*/
|
||||||
public static void releaseBuf(ByteBuffer buf) {
|
public static void releaseBuf(ByteBuffer buf) {
|
||||||
_bufferCache.tryRelease(buf);
|
_bufferCache.release(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processAccept(SelectionKey key) {
|
private void processAccept(SelectionKey key) {
|
||||||
|
@ -12,7 +12,7 @@ import net.i2p.data.SessionKey;
|
|||||||
import net.i2p.router.RouterContext;
|
import net.i2p.router.RouterContext;
|
||||||
import net.i2p.router.transport.FIFOBandwidthLimiter;
|
import net.i2p.router.transport.FIFOBandwidthLimiter;
|
||||||
import net.i2p.router.util.CDQEntry;
|
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.Addresses;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
import net.i2p.util.SystemVersion;
|
import net.i2p.util.SystemVersion;
|
||||||
@ -407,7 +407,7 @@ class UDPPacket implements CDQEntry {
|
|||||||
UDPPacket rv = null;
|
UDPPacket rv = null;
|
||||||
if (CACHE) {
|
if (CACHE) {
|
||||||
PacketFactory.context = ctx;
|
PacketFactory.context = ctx;
|
||||||
rv = _packetCache.tryAcquire();
|
rv = _packetCache.acquire();
|
||||||
rv.init(ctx);
|
rv.init(ctx);
|
||||||
}
|
}
|
||||||
if (rv == null)
|
if (rv == null)
|
||||||
@ -439,7 +439,7 @@ class UDPPacket implements CDQEntry {
|
|||||||
}
|
}
|
||||||
if (!CACHE)
|
if (!CACHE)
|
||||||
return;
|
return;
|
||||||
_packetCache.tryRelease(this);
|
_packetCache.release(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user