org.infinispan.container
Class SpinLockBasedFIFODataContainer

java.lang.Object
  extended by org.infinispan.container.SpinLockBasedFIFODataContainer
All Implemented Interfaces:
Iterable<InternalCacheEntry>, DataContainer
Direct Known Subclasses:
SpinLockBasedLRUDataContainer

@ThreadSafe
public class SpinLockBasedFIFODataContainer
extends Object
implements DataContainer

A data container that exposes an iterator that is ordered based on order of entry into the container, with the oldest entries first.

This data container that maintains a concurrent hashtable of entries, and also maintains linking between the elements for ordered iterators.

This uses concepts from ConcurrentHashMap in that it maintains a table of lockable Segments, each of which is a specialized Hashtable, but HashEntries are also linked to each other such that they can be navigated, like a LinkedHashMap. To ensure thread safety of links between entries, we follow auxillary node ideas expressed in John D. Valois' paper, Lock-Free Linked Lists Using Compare-and-Swap.

The locks maintained on linkable entrues are implemented using SpinLockBasedFIFODataContainer.SpinLocks, and due to the nature of these spin locks, they should only be held for a minimal amount of time.

Since:
4.0
Author:
Manik Surtani, Galder ZamarreƱo

Nested Class Summary
protected static class SpinLockBasedFIFODataContainer.Aux
           
protected  class SpinLockBasedFIFODataContainer.EntryIterator
           
protected  class SpinLockBasedFIFODataContainer.EntrySet
           
protected  class SpinLockBasedFIFODataContainer.ImmutableEntryIterator
           
protected  class SpinLockBasedFIFODataContainer.KeyIterator
           
protected  class SpinLockBasedFIFODataContainer.KeySet
           
protected static class SpinLockBasedFIFODataContainer.LinkedEntry
           
protected  class SpinLockBasedFIFODataContainer.LinkedIterator
           
protected static class SpinLockBasedFIFODataContainer.SpinLock
           
protected  class SpinLockBasedFIFODataContainer.ValueIterator
           
protected  class SpinLockBasedFIFODataContainer.Values
           
 
Constructor Summary
SpinLockBasedFIFODataContainer()
           
 
Method Summary
 void clear()
          Removes all entries in the container
 boolean containsKey(Object k)
          Tests whether an entry exists in the container
 Set<InternalCacheEntry> entrySet()
          Returns a mutable set of immutable cache entries exposed as immutable Map.Entry instances.
 InternalCacheEntry get(Object k)
          Retrieves a cached entry
protected  void initLinks()
          Initializes links to an empty container
 Iterator<InternalCacheEntry> iterator()
           
 Set<Object> keySet()
           
 void purgeExpired()
          Purges entries that have passed their expiry time
 void put(Object k, Object v, long lifespan, long maxIdle)
          Puts an entry in the cache along with a lifespan and a maxIdle time
 InternalCacheEntry remove(Object k)
          Removes an entry from the cache
 int size()
           
 Collection<Object> values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SpinLockBasedFIFODataContainer

public SpinLockBasedFIFODataContainer()
Method Detail

get

public InternalCacheEntry get(Object k)
Description copied from interface: DataContainer
Retrieves a cached entry

Specified by:
get in interface DataContainer
Parameters:
k - key under which entry is stored
Returns:
entry, if it exists and has not expired, or null if not

put

public void put(Object k,
                Object v,
                long lifespan,
                long maxIdle)
Description copied from interface: DataContainer
Puts an entry in the cache along with a lifespan and a maxIdle time

Specified by:
put in interface DataContainer
Parameters:
k - key under which to store entry
v - value to store
lifespan - lifespan in milliseconds. -1 means immortal.
maxIdle - max idle time for which to store entry. -1 means forever.

containsKey

public boolean containsKey(Object k)
Description copied from interface: DataContainer
Tests whether an entry exists in the container

Specified by:
containsKey in interface DataContainer
Parameters:
k - key to test
Returns:
true if entry exists and has not expired; false otherwise

remove

public InternalCacheEntry remove(Object k)
Description copied from interface: DataContainer
Removes an entry from the cache

Specified by:
remove in interface DataContainer
Parameters:
k - key to remove
Returns:
entry removed, or null if it didn't exist or had expired

size

public int size()
Specified by:
size in interface DataContainer
Returns:
count of the number of entries in the container

clear

public void clear()
Description copied from interface: DataContainer
Removes all entries in the container

Specified by:
clear in interface DataContainer

keySet

public Set<Object> keySet()
Specified by:
keySet in interface DataContainer
Returns:
a set of keys contained in the container

entrySet

public Set<InternalCacheEntry> entrySet()
Description copied from interface: DataContainer
Returns a mutable set of immutable cache entries exposed as immutable Map.Entry instances. Clients of this method such as Cache.entrySet() operation implementors are free to convert the set into an immutable set if needed, which is the most common use case. If a client needs to iterate through a mutable set of mutable cache entries, it should iterate the container itself rather than iterating through the return of entrySet().

Specified by:
entrySet in interface DataContainer
Returns:
a set of immutable cache entries

values

public Collection<Object> values()
Specified by:
values in interface DataContainer
Returns:
a set of values contained in the container

purgeExpired

public void purgeExpired()
Description copied from interface: DataContainer
Purges entries that have passed their expiry time

Specified by:
purgeExpired in interface DataContainer

iterator

public Iterator<InternalCacheEntry> iterator()
Specified by:
iterator in interface Iterable<InternalCacheEntry>

initLinks

protected final void initLinks()
Initializes links to an empty container


Google Analytics

Copyright © 2009 JBoss, a division of Red Hat. All Rights Reserved.