Package com.j_spaces.kernel.list
Class ExternallyLockedStoredList<T>
java.lang.Object
com.j_spaces.kernel.list.ExternallyLockedStoredList<T>
- All Implemented Interfaces:
IHashEntry<Object,,IStoredList<T>> ICollection<T>,IOrderedList<T>,IStoredList<T>,IObjectsList
public class ExternallyLockedStoredList<T>
extends Object
implements IStoredList<T>, IOrderedList<T>
no Lock version of StoredList locks should be external to this class scanning after establishing
a starting position should be left lock free
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classstatic class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstore an elementaddUnlocked(T subject) store an element, while the SL is unlockedbooleanis this object contained in the SL ?voidDump list content, used for Debug.establishListOrderedScan(IObjectInfo<T> OrderedScanPivot, boolean ascending) establish a scan position in one direction ascending (twrds head) or descending (towards tail).establishListScan(boolean random_scan) establish a scan position.protected ExternallyLockedStoredList.StoredListIterator<T>establishOrderedPos(ExternallyLockedStoredList.ObjectInfo<T> OrderedScanPivot, boolean ascending, ExternallyLockedStoredList.StoredListIterator<T> res) protected ExternallyLockedStoredList.StoredListIterator<T>establishPos(boolean random_scan, ExternallyLockedStoredList.StoredListIterator<T> res) 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()get head of SLgetKey(int id) getLargerInOrder(IObjectInfo<T> ref) in an ordered SL, get the element larger than refget object from head of SLgetSmallerInOrder(IObjectInfo<T> ref) in an ordered SL, get the element smaller than refgetValue(int id) booleanSets an indication that this StoredList is invalid.booleanisEmpty()Returns true if this list is empty, i.e.protected booleanbooleanis the list an iterator or basic list ?booleanis it an actual multi object container.booleannext(IStoredListIterator<T> slh) get the next element in scan orderprotected IStoredListIterator<T>booleanreturn true if we can save iterator creation and get a single entryvoidremove(IObjectInfo<T> oi) 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> oi) remove an element described by ObjectInfo, while the SL is unlockedintsize()Returns the amount of elements in the StoredList.storeBeforeCeiling(IObjectInfo<T> theCeiling, T subject) given an ObjectInfo of an existing element, store a new element right "before" this one.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.j_spaces.kernel.ICollection
establishListScan
-
Constructor Details
-
ExternallyLockedStoredList
public ExternallyLockedStoredList(boolean Support_Random_Scans)
-
-
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:
-
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
-
isEmpty
public boolean isEmpty()Description copied from interface:ICollectionReturns true if this list is empty, i.e. has no elements. [Tail] - [Head]- Specified by:
isEmptyin interfaceICollection<T>- Returns:
trueif list is empty;falseotherwise.
-
getHead
get head of SL- Specified by:
getHeadin interfaceIStoredList<T>- Returns:
- the head of the list
-
getObjectFromHead
get object from head of SL- Specified by:
getObjectFromHeadin interfaceIStoredList<T>- Returns:
- the value of the head of the list
-
establishPos
protected ExternallyLockedStoredList.StoredListIterator<T> establishPos(boolean random_scan, ExternallyLockedStoredList.StoredListIterator<T> res) -
establishOrderedPos
protected ExternallyLockedStoredList.StoredListIterator<T> establishOrderedPos(ExternallyLockedStoredList.ObjectInfo<T> OrderedScanPivot, boolean ascending, ExternallyLockedStoredList.StoredListIterator<T> res) -
nextPos
-
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.
-
addUnlocked
store an element, while the SL is unlocked- Specified by:
addUnlockedin interfaceIStoredList<T>- Parameters:
subject- element to store.- Returns:
- an information node representing the inserted element;
nullif StoredList has been invalidated.
-
storeBeforeCeiling
given an ObjectInfo of an existing element, store a new element right "before" this one. Method used in OrderedIndex object when the MasterList reflects the order of elements- head is the largest, tail the smallest- Specified by:
storeBeforeCeilingin interfaceIOrderedList<T>- Parameters:
theCeiling- a ceiling to the new element (towards the head); when null, the ceiling will be the Head.subject- a new element, to be inserted before the ceiling (towards the tail)- Returns:
- an information node representing the inserted element.
Note: not relevant for random scans
-
getLargerInOrder
in an ordered SL, get the element larger than ref- Specified by:
getLargerInOrderin interfaceIOrderedList<T>- Parameters:
ref- a reference to an OI (element in the )- Returns:
- the next largest element to ref (towards head)
-
getSmallerInOrder
in an ordered SL, get the element smaller than ref- Specified by:
getSmallerInOrderin interfaceIOrderedList<T>- Parameters:
ref- a reference to an OI (element in the )- Returns:
- the next smallest to ref (towards tail)
-
remove
remove an element described by ObjectInfo- Specified by:
removein interfaceIStoredList<T>- Parameters:
oi- an existing element between Tail and Head
-
removeUnlocked
remove an element described by ObjectInfo, while the SL is unlocked- Specified by:
removeUnlockedin interfaceIStoredList<T>- Parameters:
oi- an existing element between Tail and Head
-
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)
-
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.
-
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.
-
isInvalid
protected boolean isInvalid()- Returns:
- true if the list is invalid
-
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
-
establishListScan
establish a scan position. if random scanning supported we select a random position- Specified by:
establishListScanin interfaceICollection<T>- Parameters:
random_scan-trueenable random scan;falsestart from head.- Returns:
- a Holder for this scan. This Resource should be released if scan ended prematurely.
-
establishListOrderedScan
public IStoredListIterator<T> establishListOrderedScan(IObjectInfo<T> OrderedScanPivot, boolean ascending) establish a scan position in one direction ascending (twrds head) or descending (towards tail). if random scanning supported starting at a predefined pos this API is used by the OrderedIndex masterList to establish an index scan- Specified by:
establishListOrderedScanin interfaceIOrderedList<T>- Parameters:
OrderedScanPivot- a pivot from which to start this scan. if null, pivot is Head (if ascending is true); Tail otherwiseascending- iftruescan from pivot towards head; iffalsescan from pivot towards tail.- Returns:
- returns a Holder of 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.
-
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.
-
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
-
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
-