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.

public class OClosableLinkedContainer<K,V extends OClosableItem> extends Object
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 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

      public void add(K key, V item) throws InterruptedException
      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

      public V remove(K key)
      Removes item associated with passed in key.
      Parameters:
      key - Key associated with item to remove.
      Returns:
      Removed item.
    • acquire

      public OClosableEntry<K,V> acquire(K key) throws InterruptedException
      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 null if there is no item associated with given container
      Throws:
      InterruptedException
    • tryAcquire

      public OClosableEntry<K,V> tryAcquire(K key) throws InterruptedException
      Throws:
      InterruptedException
    • release

      public void release(OClosableEntry<K,V> entry)
      Releases item acquired by call of 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.
      Parameters:
      entry - Entry to release
    • get

      public V get(K key)
      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

      public boolean close(K key)
      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:
      true if item was closed and false otherwise.