Class ConcurrentStoredList<T>

java.lang.Object
com.j_spaces.kernel.list.ConcurrentStoredList<T>
All Implemented Interfaces:
IHashEntry<Object,IStoredList<T>>, ICollection<T>, IStoredList<T>, IObjectsList
Direct Known Subclasses:
ConcurrentSegmentedStoredList, ConcurrentSegmentedStoredListHashmapEntry

public class ConcurrentStoredList<T> extends Object implements IStoredList<T>
Since:
7.1
Version:
1.0
Author:
Yechiel Fefer
  • Constructor Details

    • ConcurrentStoredList

      public ConcurrentStoredList(boolean segmented, boolean supportFifoPerSegment)
  • Method Details

    • size

      public int size()
      Description copied from interface: ICollection
      Returns the amount of elements in the StoredList.
      Specified by:
      size in interface ICollection<T>
      Returns:
      size of the StoredList
      See Also:
    • isEmpty

      public boolean isEmpty()
      Returns true if the list is empty
      Specified by:
      isEmpty in interface ICollection<T>
      Returns:
      true if list is empty; false otherwise.
    • add

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

      public IObjectInfo<T> add(T subject, Object segmentHint)
    • addUnlocked

      public IObjectInfo<T> addUnlocked(T subject)
      Description copied from interface: IStoredList
      Store an element in the list, while the SL is unlocked . New elements are inserted at the tail.
      Specified by:
      addUnlocked in interface IStoredList<T>
      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> poi)
      remove an element described by ObjectInfo
      Specified by:
      remove in interface IStoredList<T>
      Parameters:
      poi - an existing element between Tail and Head
    • removeUnlocked

      public void removeUnlocked(IObjectInfo<T> poi)
      Description copied from interface: IStoredList
      Remove an element described by ObjectInfo, while the SL is unlocked. [Tail] - .. - [beforeOi] - [oi] - [afterOi] - .. - [Head]
      Specified by:
      removeUnlocked in interface IStoredList<T>
      Parameters:
      poi - an existing element between Tail and Head
    • contains

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

      public boolean removeByObject(T obj)
      given an object scan the list, find it and remove it, returns true if found
      Specified by:
      removeByObject in interface ICollection<T>
      Parameters:
      obj - element to remove
      Returns:
      true if object was removed; false otherwise (if element wasn't found)
    • 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.
      Specified by:
      invalidate in interface IStoredList<T>
      Returns:
      true if StoredList was set to invalid; false otherwise.
    • supportsInvalidation

      protected boolean supportsInvalidation()
    • getNumSegments

      protected int getNumSegments()
      get the number of segments in this SL
    • getSegment

      protected StoredListChainSegment<T> getSegment(int seg)
    • incremenetAndGetSize

      protected int incremenetAndGetSize()
    • incrementSize

      protected void incrementSize()
    • decrementSize

      protected void decrementSize()
    • getHead

      public IObjectInfo<T> getHead()
      Goes over all the segments and finds the "first" element. NOTE- if num of segments > 1 just get according to segments order
      Specified by:
      getHead in interface IStoredList<T>
      Returns:
      the head of the list
    • getObjectFromHead

      public T getObjectFromHead()
      Description copied from interface: IStoredList
      Returns the value of the first element in the list (fifo)
      Specified by:
      getObjectFromHead in interface IStoredList<T>
      Returns:
      the value of the head of the list
    • optimizeScanForSingleObject

      public boolean optimizeScanForSingleObject()
      return true if we can save iterator creation and get a single entry
      Specified by:
      optimizeScanForSingleObject in interface IStoredList<T>
      Returns:
      true if we can optimize
    • establishListScan

      public IStoredListIterator<T> establishListScan(boolean randomScan)
      establish a scan position. we select a random segment to start from
      Specified by:
      establishListScan in interface ICollection<T>
      Parameters:
      randomScan - true enable random scan; false start from head.
      Returns:
      a Holder for this scan. This Resource should be released if scan ended prematurely.
    • establishListScan

      public IStoredListIterator<T> establishListScan(boolean randomScan, boolean alternatingThread)
      establish a scan position. we select a random segment to start from
      Specified by:
      establishListScan in interface ICollection<T>
      Parameters:
      randomScan - true enable random scan; false start from head.
      alternatingThread - true the result iter many be used by a not-same thread
      Returns:
      a Holder for this scan. This Resource should be released if scan ended prematurely.
    • next

      get the next element in scan order
      Specified by:
      next in interface ICollection<T>
      Parameters:
      slh - Holder representing a pivot position.
      Returns:
      the next pivot position in this scan; null if reached end of scan.
    • isMultiObjectCollection

      public boolean isMultiObjectCollection()
      Description copied from interface: ICollection
      is it an actual multi object container.
      Specified by:
      isMultiObjectCollection in interface ICollection<T>
      Returns:
      true if its an actual list; false otherwise
    • isIterator

      public boolean isIterator()
      Description copied from interface: IObjectsList
      is the list an iterator or basic list ?
      Specified by:
      isIterator in interface IObjectsList
    • dump

      public void dump(org.slf4j.Logger logger, String msg)
      Description copied from interface: IStoredList
      Dump list content, used for Debug.
      Specified by:
      dump in interface IStoredList<T>
      Parameters:
      logger - logger to use
      msg - message to add in log
    • freeSLHolder

      public void freeSLHolder(IStoredListIterator<T> slh)
      this method is called by outside scan that want to quit the scan and return the slholder to the factory
      Specified by:
      freeSLHolder in interface IStoredList<T>
      Parameters:
      slh - Holder resource to return to pool; can be null.
    • monitor

      public void monitor()
    • getHashCode

      public int getHashCode(int id)
      Specified by:
      getHashCode in interface IHashEntry<Object,IStoredList<T>>
    • getKey

      public Object getKey(int id)
      Specified by:
      getKey in interface IHashEntry<Object,IStoredList<T>>
    • getValue

      public IStoredList<T> getValue(int id)
      Specified by:
      getValue in interface IHashEntry<Object,IStoredList<T>>
    • isNativeHashEntry

      public boolean isNativeHashEntry()
      Specified by:
      isNativeHashEntry in interface IHashEntry<Object,IStoredList<T>>
      Returns:
      true if this is a native hashmap entry