Class SimpleLockStoredList<T>

java.lang.Object
com.j_spaces.kernel.AbstractStoredList<T>
com.j_spaces.kernel.SimpleLockStoredList<T>
All Implemented Interfaces:
IHashEntry<Object,IStoredList<T>>, ICollection<T>, IStoredList<T>, IObjectsList, Iterable<T>
Direct Known Subclasses:
HashedSimpleLockIStoredList

public class SimpleLockStoredList<T> extends AbstractStoredList<T>
Read/Write Lock version of StoredList to be used with JDK 1.5+
  • Field Details

  • Constructor Details

    • SimpleLockStoredList

      public SimpleLockStoredList(boolean Support_Random_Scans)
    • SimpleLockStoredList

      public SimpleLockStoredList(boolean Support_Random_Scans, IReusableResourcePool<ReadWriteLock> locksPool)
      Create new stored list that will use the given ReadWriteLock for synchronization. This allows lock reuse between stored lists
  • Method Details

    • size

      public int size()
      Description copied from interface: ICollection
      Returns the amount of elements in the StoredList.
      Returns:
      size of the StoredList
      See Also:
    • optimizeScanForSingleObject

      public boolean optimizeScanForSingleObject()
      return true if we can save iterator creation and get a single entry
      Returns:
      true if we can optimize
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: ICollection
      Returns true if this list is empty, i.e. has no elements. [Tail] - [Head]
      Returns:
      true if list is empty; false otherwise.
    • getHead

      public IObjectInfo<T> getHead()
      get head of SL
      Returns:
      the head of the list
    • getObjectFromHead

      public T getObjectFromHead()
      get object from head of SL
      Returns:
      the value of the head of the list
    • iterate

      protected boolean iterate(boolean random_scan, StoredListIterator<T> res)
      Specified by:
      iterate in class AbstractStoredList<T>
    • nextPos

      public boolean nextPos(StoredListIterator<T> slh)
      Specified by:
      nextPos in class AbstractStoredList<T>
    • add

      public IObjectInfo<T> add(T subject)
      store an element
      Parameters:
      subject - element to store.
      Returns:
      an information node representing the inserted element; null if StoredList has been invalidated.
    • addUnlocked

      public IObjectInfo<T> addUnlocked(T subject)
      store an element, while the SL is unlocked
      Parameters:
      subject - element to store.
      Returns:
      an information node representing the inserted element; null if StoredList has been invalidated.
    • remove

      public void remove(IObjectInfo<T> oi)
      remove an element described by ObjectInfo
      Parameters:
      oi - an existing element between Tail and Head
    • removeUnlocked

      public void removeUnlocked(IObjectInfo<T> oi)
      remove an element described by ObjectInfo, while the SL is unlocked
      Parameters:
      oi - an existing element between Tail and Head
    • removeByObject

      public boolean removeByObject(T obj)
      given an object scan the list, find it and remove it, returns true if found
      Parameters:
      obj - element to remove
      Returns:
      true if object was removed; false otherwise (if element wasn't found)
    • contains

      public boolean contains(T obj)
      is this object contained in the SL ?
      Parameters:
      obj - the element to search for
      Returns:
      true if element exists in the StoredList; false otherwise.
    • invalidate

      public boolean invalidate()
      Sets an indication that this StoredList is invalid. if isEmpty() returns true, the indication is set; otherwise the indication remains false. Called by PersistentGC when scanning for empty StoredList that can be garbage collected.
      Returns:
      true if StoredList was set to invalid; false otherwise.
    • isInvalid

      protected boolean isInvalid()
      Specified by:
      isInvalid in class AbstractStoredList<T>
      Returns:
      true if the list is invalid
    • getHashCode

      public int getHashCode(int id)
    • getKey

      public Object getKey(int id)
    • getValue

      public IStoredList<T> getValue(int id)
    • isNativeHashEntry

      public boolean isNativeHashEntry()
      Returns:
      true if this is a native hashmap entry