org.infinispan.container
Class FIFODataContainer

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

public class FIFODataContainer
extends Object
implements DataContainer

A container that maintains order of entries based on when they were placed in the container. Iterators obtained from this container maintain this order.

This container offers constant-time operation for all public API methods.

This is implemented using a set of lockable segments, each of which is a hash table, not unlike the JDK's ConcurrentHashMap with the exception that each entry is also linked.

Links are maintained using techniques inspired by H. Sundell and P. Tsigas' 2008 paper, Lock Free Deques and Doubly Linked Lists, M. Michael's 2002 paper, High Performance Dynamic Lock-Free Hash Tables and List-Based Sets, and Java6's ConcurrentSkipListMap.

Since:
4.0
Author:
Manik Surtani

Nested Class Summary
protected  class FIFODataContainer.KeyIterator
           
protected  class FIFODataContainer.KeySet
           
protected  class FIFODataContainer.LinkedIterator
           
protected  class FIFODataContainer.ValueIterator
           
 
Constructor Summary
FIFODataContainer()
           
 
Method Summary
 void clear()
          Removes all entries in the container
 boolean containsKey(Object k)
          Tests whether an entry exists in the container
 InternalCacheEntry get(Object k)
          Retrieves a cached entry
protected  void initLinks()
          Initializes links to an empty container
 Iterator<InternalCacheEntry> iterator()
           
 Set<Object> keySet()
           
protected  void linkAtEnd(org.infinispan.container.FIFODataContainer.LinkedEntry le)
           
 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()
           
protected  void unlink(org.infinispan.container.FIFODataContainer.LinkedEntry le)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FIFODataContainer

public FIFODataContainer()
Method Detail

initLinks

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


unlink

protected final void unlink(org.infinispan.container.FIFODataContainer.LinkedEntry le)

linkAtEnd

protected final void linkAtEnd(org.infinispan.container.FIFODataContainer.LinkedEntry le)

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

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>


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