|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectariba.util.core.SelfCleaningPool<T>
public abstract class SelfCleaningPool<T>
Generic resource pooling mechanism, that uses Timer to return allocated storage to be garbage collected when it is no longer needed for current usage patterns. By default resources are released from the pool 10 minutes after they were last acquired or released to the pool. There is no upper bound to the pool size, it will grow to meet simultaneous demand for the resources, and then shrink over time when simultaneous demand is not so high. The resources are remembered through soft references, so the GC can reclaim them at any time if there are no strong references to them, and the code here defends against the resource having been reclaimed this way. This class is completely thread-safe, there is expected to be only one instance of a given pool across all realms on a node, so the pool of resources can be reused without generating garbage by different realms and threads at different times as needed.
Nested Class Summary | |
---|---|
static class |
SelfCleaningPool.PoolFloat<T>
Nested class that wraps up an actual resource instance. |
Constructor Summary | |
---|---|
SelfCleaningPool()
|
Method Summary | |
---|---|
T |
get()
Returns an instance of the resource T. |
EventLoop |
getEventLoop()
Returns EventLoop previously registered by the singleton BaseServer constructor. |
int |
getIdleTimeoutSeconds()
Returns int number of seconds after the time when a given resource was most recently used, at which the resource will be declared idle and reclaimed for garbage collection. |
void |
performCommand(java.lang.String command,
java.lang.Object data)
This method is called when the timer fires. |
static void |
registerEventLoop(EventLoop eventLoop)
This static method is called by the BaseServer constructor to register the one true master event loop for the node with us, so we can create timers, and so our client code in util.core doesn't have to figure out how to get an event loop to pass us. |
void |
release(T item)
Releases a previously allocated instance of the resource item back to the pool. |
void |
setIdleTimeoutSeconds(int seconds)
Sets int number of seconds after the time when a given resource was most recently used, at which the resource will be declared idle and reclaimed for garbage collection. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SelfCleaningPool()
Method Detail |
---|
public T get()
public void release(T item)
public int getIdleTimeoutSeconds()
public void setIdleTimeoutSeconds(int seconds)
public static void registerEventLoop(EventLoop eventLoop)
public EventLoop getEventLoop()
public final void performCommand(java.lang.String command, java.lang.Object data)
performCommand
in interface Target
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |