Class OClosableLinkedContainer<K,V extends OClosableItem>
java.lang.Object
com.orientechnologies.common.collection.closabledictionary.OClosableLinkedContainer<K,V>
- Type Parameters:
K- Key associated with entry stored inside of container.V- Value which may be in open/closed stated and associated with key.
Container for the elements which may be in open/closed state. But only limited amount of elements
are hold by given container may be in open state.
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 Summary
ConstructorsConstructorDescriptionOClosableLinkedContainer(int openLimit) Creates new instance of container and set limit of open files which may be hold by container. -
Method Summary
Modifier and TypeMethodDescriptionAcquires item associated with passed in key in container.voidAdds item to the container.voidclear()Clears all content.booleanCloses item related to passed in key.Returns item without acquiring it.voidrelease(OClosableEntry<K, V> entry) Releases item acquired by call ofacquire(Object)method.Removes item associated with passed in key.tryAcquire(K key)
-
Constructor Details
-
OClosableLinkedContainer
public OClosableLinkedContainer(int openLimit) Creates new instance of container and set limit of open files which may be hold by container.- Parameters:
openLimit- Limit of open files hold by container.
-
-
Method Details
-
add
Adds item to the container. Item should be in open state.- Parameters:
key- Key associated with given item.item- Item associated with passed in key.- Throws:
InterruptedException
-
remove
Removes item associated with passed in key.- Parameters:
key- Key associated with item to remove.- Returns:
- Removed item.
-
acquire
Acquires item associated with passed in key in container. It is guarantied that item will not be closed if limit of open items will be exceeded and container will close rarely used items.- Parameters:
key- Key associated with item- Returns:
- Acquired item if key exists into container or
nullif there is no item associated with given container - Throws:
InterruptedException
-
tryAcquire
- Throws:
InterruptedException
-
release
Releases item acquired by call ofacquire(Object)method. After this call container is free to close given item if limit of open files exceeded and this item is rarely used.- Parameters:
entry- Entry to release
-
get
Returns item without acquiring it. State of item is not guarantied in such case.- Parameters:
key- Key associated with required item.- Returns:
- Item associated with given key.
-
clear
public void clear()Clears all content. -
close
Closes item related to passed in key. Item will be closed if it exists and is not acquired.- Parameters:
key- Key related to item that has going to be closed.- Returns:
trueif item was closed andfalseotherwise.
-