K
- Key associated with entry stored inside of container.V
- Value which may be in open/closed stated and associated with key.public class OClosableLinkedContainer<K,V extends OClosableItem> extends Object
Elements may be added in this container only in open state,as result after addition of some elements other rarely used elements will be closed.
When you want to use elements from container you should acquire them acquire(Object)
.
So element still will be inside of container but in acquired state. As result it will not be
automatically closed when container will try to close rarely used items.
Container uses LRU eviction policy to choose item to be closed.
When you finish to work with element from container you should release (@link release(OClosableEntry)
) element back to container.
Constructor and Description |
---|
OClosableLinkedContainer(int openLimit)
Creates new instance of container and set limit of open files which may be hold by container.
|
Modifier and Type | Method and Description |
---|---|
OClosableEntry<K,V> |
acquire(K key)
Acquires item associated with passed in key in container.
|
void |
add(K key,
V item)
Adds item to the container.
|
void |
clear()
Clears all content.
|
boolean |
close(K key)
Closes item related to passed in key.
|
V |
get(K key)
Returns item without acquiring it.
|
void |
release(OClosableEntry<K,V> entry)
Releases item acquired by call of
acquire(Object) method. |
V |
remove(K key)
Removes item associated with passed in key.
|
OClosableEntry<K,V> |
tryAcquire(K key) |
public OClosableLinkedContainer(int openLimit)
openLimit
- Limit of open files hold by container.public void add(K key, V item) throws InterruptedException
key
- Key associated with given item.item
- Item associated with passed in key.InterruptedException
public V remove(K key)
key
- Key associated with item to remove.public OClosableEntry<K,V> acquire(K key) throws InterruptedException
key
- Key associated with itemnull
if there is no item
associated with given containerInterruptedException
public OClosableEntry<K,V> tryAcquire(K key) throws InterruptedException
InterruptedException
public void release(OClosableEntry<K,V> entry)
acquire(Object)
method. After this call container is
free to close given item if limit of open files exceeded and this item is rarely used.entry
- Entry to releasepublic V get(K key)
key
- Key associated with required item.public void clear()
public boolean close(K key)
key
- Key related to item that has going to be closed.true
if item was closed and false
otherwise.Copyright © 2009–2020 OrientDB. All rights reserved.