Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.myfaces.shared_orchestra.util
Class BiLevelCacheMap

    java.lang.Object
      org.apache.myfaces.shared_orchestra.util.BiLevelCacheMap

All Implemented Interfaces:
  java.util.Map

    public abstract class BiLevelCacheMap

extends java.lang.Object
implements java.util.Map

A bi-level cache based on HashMap for caching objects with minimal sychronization overhead. The limitation is that `remove()` is very expensive.

Access to L1 map is not sychronized, to L2 map is synchronized. New values are first stored in L2. Once there have been more that a specified mumber of misses on L1, L1 and L2 maps are merged and the new map assigned to L1 and L2 cleared.

IMPORTANT:entrySet(), keySet(), and values() return unmodifiable snapshot collections.

Version:
  $Revision: 472630 $ $Date: 2006-11-08 21:40:03 +0100 (Mi, 08 Nov 2006) $
Author:
  Anton Koinov (latest modification by $Author: grantsmith $)

Nested Class Summary

Nested classes/interfaces inherited from interface java.util.Map
`java.util.Map.Entry<K,V>`

Field Summary
`protected java.util.Map` | `_cacheL1` To preinitialize `_cacheL1` with default values use an initialization block

Constructor Summary
`BiLevelCacheMap(int mergeThreshold)`

Method Summary
`void` | `clear()`
`boolean` | `containsKey(java.lang.Object key)`
`boolean` | `containsValue(java.lang.Object value)`
`java.util.Set` | `entrySet()`
`java.lang.Object` | `get(java.lang.Object key)`
`boolean` | `isEmpty()`
`java.util.Set` | `keySet()`
`protected abstract java.lang.Object` | `newInstance(java.lang.Object key)` Subclasses must implement to have automatic creation of new instances or alternatively can use `put`to add new items to the cache. Implementing this method is prefered to guarantee that there will be only one instance per key ever created.``
`java.lang.Object` | `put(java.lang.Object key, java.lang.Object value)` If key is already in cacheL1, the new value will show with a delay, since merge L2->L1 may not happen immediately.
`void` | `putAll(java.util.Map map)`
`java.lang.Object` | `remove(java.lang.Object key)` This operation is very expensive.
`int` | `size()`
`java.util.Collection` | `values()`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Methods inherited from interface java.util.Map
`equals, hashCode`

Field Detail

### _cacheL1

    protected java.util.Map _cacheL1

  To preinitialize `_cacheL1` with default values use an initialization block

Constructor Detail

### BiLevelCacheMap

    public BiLevelCacheMap(int mergeThreshold)

Method Detail

### isEmpty

    public boolean isEmpty()

  Specified by:
    `isEmpty` in interface `java.util.Map`

### clear

    public void clear()

  Specified by:
    `clear` in interface `java.util.Map`

### containsKey

    public boolean containsKey(java.lang.Object key)

  Specified by:
    `containsKey` in interface `java.util.Map`

### containsValue

    public boolean containsValue(java.lang.Object value)

  Specified by:
    `containsValue` in interface `java.util.Map`

### entrySet

    public java.util.Set entrySet()

  Specified by:
    `entrySet` in interface `java.util.Map`

### get

    public java.lang.Object get(java.lang.Object key)

  Specified by:
    `get` in interface `java.util.Map`

### keySet

    public java.util.Set keySet()

  Specified by:
    `keySet` in interface `java.util.Map`

### put

    public java.lang.Object put(java.lang.Object key,
                                java.lang.Object value)

  If key is already in cacheL1, the new value will show with a delay, since merge L2->L1 may not happen immediately. To force the merge sooner, call `size()`.

  ``
  Specified by:
    `put` in interface `java.util.Map`

### putAll

    public void putAll(java.util.Map map)

  Specified by:
    `putAll` in interface `java.util.Map`

### remove

    public java.lang.Object remove(java.lang.Object key)

  This operation is very expensive. A full copy of the Map is created

  Specified by:
    `remove` in interface `java.util.Map`

### size

    public int size()

  Specified by:
    `size` in interface `java.util.Map`

### values

    public java.util.Collection values()

  Specified by:
    `values` in interface `java.util.Map`

### newInstance

    protected abstract java.lang.Object newInstance(java.lang.Object key)

  Subclasses must implement to have automatic creation of new instances or alternatively can use `put`to add new items to the cache.
  Implementing this method is prefered to guarantee that there will be only one instance per key ever created. Calling put() to add items in a multi- threaded situation will require external synchronization to prevent two instances for the same key, which defeats the purpose of this cache (put() is useful when initialization is done during startup and items are not added during execution or when (temporarily) having possibly two or more instances of the same key is not of concern).

  ``
  Parameters:
    `key` - lookup key
  Returns:
    new instace for the requested key

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2009 The Apache Software Foundation. All Rights Reserved.