Package com.j_spaces.kernel.list
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
- Since:
- 7.1
- Version:
- 1.0
- Author:
- Yechiel Fefer
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstore an elementaddUnlocked(T subject) Store an element in the list, while the SL is unlocked .booleanis this object contained in the SL ?protected voidvoidDump list content, used for Debug.establishListScan(boolean randomScan) establish a scan position.establishListScan(boolean randomScan, boolean alternatingThread) establish a scan position.voidfreeSLHolder(IStoredListIterator<T> slh) this method is called by outside scan that want to quit the scan and return the slholder to the factoryintgetHashCode(int id) getHead()Goes over all the segments and finds the "first" element.getKey(int id) protected intget the number of segments in this SLReturns the value of the first element in the list (fifo)protected StoredListChainSegment<T>getSegment(int seg) getValue(int id) protected intprotected voidbooleanSets an indication that this StoredList is invalid.booleanisEmpty()Returns true if the list is emptybooleanis the list an iterator or basic list ?booleanis it an actual multi object container.booleanvoidmonitor()next(IStoredListIterator<T> slh) get the next element in scan orderbooleanreturn true if we can save iterator creation and get a single entryvoidremove(IObjectInfo<T> poi) remove an element described by ObjectInfobooleanremoveByObject(T obj) given an object scan the list, find it and remove it, returns true if foundvoidremoveUnlocked(IObjectInfo<T> poi) Remove an element described by ObjectInfo, while the SL is unlocked.intsize()Returns the amount of elements in the StoredList.protected boolean
-
Constructor Details
-
ConcurrentStoredList
public ConcurrentStoredList(boolean segmented, boolean supportFifoPerSegment)
-
-
Method Details
-
size
public int size()Description copied from interface:ICollectionReturns the amount of elements in the StoredList.- Specified by:
sizein interfaceICollection<T>- Returns:
- size of the StoredList
- See Also:
-
isEmpty
public boolean isEmpty()Returns true if the list is empty- Specified by:
isEmptyin interfaceICollection<T>- Returns:
trueif list is empty;falseotherwise.
-
add
store an element- Specified by:
addin interfaceICollection<T>- Parameters:
subject- element to store.- Returns:
- an information node representing the inserted element;
nullif StoredList has been invalidated.
-
add
-
addUnlocked
Description copied from interface:IStoredListStore an element in the list, while the SL is unlocked . New elements are inserted at the tail.- Specified by:
addUnlockedin interfaceIStoredList<T>- Parameters:
subject- element to store.- Returns:
- an information node representing the inserted element;
nullif StoredList has been invalidated.
-
remove
remove an element described by ObjectInfo- Specified by:
removein interfaceIStoredList<T>- Parameters:
poi- an existing element between Tail and Head
-
removeUnlocked
Description copied from interface:IStoredListRemove an element described by ObjectInfo, while the SL is unlocked. [Tail] - .. - [beforeOi] - [oi] - [afterOi] - .. - [Head]- Specified by:
removeUnlockedin interfaceIStoredList<T>- Parameters:
poi- an existing element between Tail and Head
-
contains
is this object contained in the SL ?- Specified by:
containsin interfaceICollection<T>- Parameters:
obj- the element to search for- Returns:
trueif element exists in the StoredList;falseotherwise.
-
removeByObject
given an object scan the list, find it and remove it, returns true if found- Specified by:
removeByObjectin interfaceICollection<T>- Parameters:
obj- element to remove- Returns:
trueif object was removed;falseotherwise (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:
invalidatein interfaceIStoredList<T>- Returns:
trueif StoredList was set to invalid;falseotherwise.
-
supportsInvalidation
protected boolean supportsInvalidation() -
getNumSegments
protected int getNumSegments()get the number of segments in this SL -
getSegment
-
incremenetAndGetSize
protected int incremenetAndGetSize() -
incrementSize
protected void incrementSize() -
decrementSize
protected void decrementSize() -
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:
getHeadin interfaceIStoredList<T>- Returns:
- the head of the list
-
getObjectFromHead
Description copied from interface:IStoredListReturns the value of the first element in the list (fifo)- Specified by:
getObjectFromHeadin interfaceIStoredList<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:
optimizeScanForSingleObjectin interfaceIStoredList<T>- Returns:
- true if we can optimize
-
establishListScan
establish a scan position. we select a random segment to start from- Specified by:
establishListScanin interfaceICollection<T>- Parameters:
randomScan-trueenable random scan;falsestart from head.- Returns:
- a Holder for this scan. This Resource should be released if scan ended prematurely.
-
establishListScan
establish a scan position. we select a random segment to start from- Specified by:
establishListScanin interfaceICollection<T>- Parameters:
randomScan-trueenable random scan;falsestart from head.alternatingThread-truethe 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:
nextin interfaceICollection<T>- Parameters:
slh- Holder representing a pivot position.- Returns:
- the next pivot position in this scan;
nullif reached end of scan.
-
isMultiObjectCollection
public boolean isMultiObjectCollection()Description copied from interface:ICollectionis it an actual multi object container.- Specified by:
isMultiObjectCollectionin interfaceICollection<T>- Returns:
trueif its an actual list;falseotherwise
-
isIterator
public boolean isIterator()Description copied from interface:IObjectsListis the list an iterator or basic list ?- Specified by:
isIteratorin interfaceIObjectsList
-
dump
Description copied from interface:IStoredListDump list content, used for Debug.- Specified by:
dumpin interfaceIStoredList<T>- Parameters:
logger- logger to usemsg- message to add in log
-
freeSLHolder
this method is called by outside scan that want to quit the scan and return the slholder to the factory- Specified by:
freeSLHolderin interfaceIStoredList<T>- Parameters:
slh- Holder resource to return to pool; can benull.
-
monitor
public void monitor() -
getHashCode
public int getHashCode(int id) - Specified by:
getHashCodein interfaceIHashEntry<Object,IStoredList<T>>
-
getKey
- Specified by:
getKeyin interfaceIHashEntry<Object,IStoredList<T>>
-
getValue
- Specified by:
getValuein interfaceIHashEntry<Object,IStoredList<T>>
-
isNativeHashEntry
public boolean isNativeHashEntry()- Specified by:
isNativeHashEntryin interfaceIHashEntry<Object,IStoredList<T>> - Returns:
trueif this is a native hashmap entry
-