Overview | Package | Class | Tree | Deprecated | Index | Help
| SolarMetric Kodo JDO 3.4.1 generated on May 30 2006
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## kodo.util
Class CacheMap

    java.lang.Object
      |
      +--kodo.util.CacheMap

All Implemented Interfaces:
  Map

Direct Known Subclasses:
  ClassRefCacheMap

public class CacheMap
extends Object
implements Map

A map that keeps hard references to a fixed number of elements and moves expired references to a soft reference map. Additionally, objects that are pinned are not counted towards the max size of the map. This implementation is thread-safe.

Inner classes inherited from class java.util.Map
`Map.Entry`

Field Summary
`protected com.solarmetric.util.MutableMaxSizeLRUMap` | `_lruMap` The map for non-expired and pinned references.
`protected HashMap` | `_pinnedMap` The set of objects pinned into the cache.
`protected serp.util.ReferenceMap` | `_softMap` The map for expired references.

Constructor Summary
`CacheMap()` Create a new `CacheMap` with an initial maximum unpinned object size of 1000.
`CacheMap(int size)` Create a new `CacheMap` with an initial maximum unpinned object size of `size`.
`CacheMap(int size, float load)` Create a new `CacheMap` with an initial maximum unpinned object size of `size` and a load factor of `load`.
`CacheMap(int size, float load, int max)` Create a new `CacheMap` with an initial size of `size`, load factor of `load`, and maximum unpinned object size of `max`.

Method Summary
`void` | `clear()` Removes pinned objects as well as unpinned ones.
`boolean` | `containsKey(Object key)`
`boolean` | `containsValue(Object val)`
`protected void` | `entryHardRefAdded(Object key, Object value)`
`protected void` | `entryRemoved(Object key, Object value)`
`Set` | `entrySet()`
`protected void` | `entryWeakRefAdded(Object key, Object value)`
`Object` | `get(Object key)`
`int` | `getCacheSize()` Returns the maximum number of unpinned objects to keep hard references to.
`Set` | `getPinnedKeys()` Returns the keys to the objects currently pinned into memory.
`int` | `getSoftReferenceSize()` Returns the maximum number of unpinned objects to keep soft references to.
`Collection` | `getStatistics()`
`boolean` | `isEmpty()`
`protected void` | `keyRemoved(Object key, boolean expired)` Invoked when a key-value pair is evicted from this data structure.
`Set` | `keySet()`
`boolean` | `pin(Object key)` Locks the key-value pair identified by `key` into the map.
`Object` | `put(Object key, Object value)`
`void` | `putAll(Map map)`
`Object` | `remove(Object key)` If `key` is pinned into the cache, the pin is cleared and the object is removed.
`void` | `setCacheSize(int size)` Sets the maximum number of unpinned objects to keep hard references to.
`void` | `setSoftReferenceSize(int size)` Sets the maximum number of unpinned objects to keep soft references to.
`int` | `size()`
`boolean` | `unpin(Object key)` Removes the key-value pair identified by `key` from the set of pinned objects.
`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

### _softMap

    protected final serp.util.ReferenceMap _softMap

  The map for expired references.

### _lruMap

    protected final com.solarmetric.util.MutableMaxSizeLRUMap _lruMap

  The map for non-expired and pinned references.

### _pinnedMap

    protected HashMap _pinnedMap

  The set of objects pinned into the cache.

Constructor Detail

### CacheMap

    public CacheMap()

  Create a new `CacheMap` with an initial maximum unpinned object size of 1000.

### CacheMap

    public CacheMap(int size)

  Create a new `CacheMap` with an initial maximum unpinned object size of `size`.

### CacheMap

    public CacheMap(int size,
                    float load)

  Create a new `CacheMap` with an initial maximum unpinned object size of `size` and a load factor of `load`.

### CacheMap

    public CacheMap(int size,
                    float load,
                    int max)

  Create a new `CacheMap` with an initial size of `size`, load factor of `load`, and maximum unpinned object size of `max`.

Method Detail

### setCacheSize

    public void setCacheSize(int size)

  Sets the maximum number of unpinned objects to keep hard references to. If the map contains more unpinned objects than `size`, then this method will result in the cache flushing old values. If this is `-1`, the cache will never be flushed.

### getCacheSize

    public int getCacheSize()

  Returns the maximum number of unpinned objects to keep hard references to.

### setSoftReferenceSize

    public void setSoftReferenceSize(int size)

  Sets the maximum number of unpinned objects to keep soft references to. If the map contains more soft references than `size`, then this method will result in the cache flushing some of the soft references. If this is `-1`, the cache will store a limitless number of soft references. Defaults to `-1`.

### getSoftReferenceSize

    public int getSoftReferenceSize()

  Returns the maximum number of unpinned objects to keep soft references to.

### getPinnedKeys

    public Set getPinnedKeys()

  Returns the keys to the objects currently pinned into memory.

### pin

    public boolean pin(Object key)

  Locks the key-value pair identified by `key` into the map. Objects pinned into the map are not counted towards the maximum size of the map, and are never removed except by explicit calls to `remove(java.lang.Object)` or `clear()`.

  If a key that is not currently in the cache is pinned, it will not be considered pinned once that key is used in the cache.

  Returns:
    `true` if `key`'s value was pinned into the cache; `false` if the key is not in the cache.

### unpin

    public boolean unpin(Object key)

  Removes the key-value pair identified by `key` from the set of pinned objects. This key becomes a candidate for removal from the LRU map if the map exceeds the maximum size.
  Returns:
    `true` if `key`'s value was unpinned from the cache; `false` if the key is not in the cache.

### keyRemoved

    protected void keyRemoved(Object key,
                              boolean expired)

  Invoked when a key-value pair is evicted from this data structure. This is invoked with `expired` set to `true` when an object is dropped because of space requirements or through garbage collection of soft references. It is invoked with `expired` set to `false` when an object is explicitly removed via the `remove(java.lang.Object)` or `clear()` methods.

  This may be invoked more than once for a given key.

  Since:
    2.5.0

### get

    public Object get(Object key)

  Specified by:
    `get` in interface `Map`

### put

    public Object put(Object key,
                      Object value)

  Specified by:
    `put` in interface `Map`

### putAll

    public void putAll(Map map)

  Specified by:
    `putAll` in interface `Map`

### remove

    public Object remove(Object key)

  If `key` is pinned into the cache, the pin is cleared and the object is removed.
  Specified by:
    `remove` in interface `Map`

### clear

    public void clear()

  Removes pinned objects as well as unpinned ones.
  Specified by:
    `clear` in interface `Map`

### size

    public int size()

  Specified by:
    `size` in interface `Map`

### isEmpty

    public boolean isEmpty()

  Specified by:
    `isEmpty` in interface `Map`

### containsKey

    public boolean containsKey(Object key)

  Specified by:
    `containsKey` in interface `Map`

### containsValue

    public boolean containsValue(Object val)

  Specified by:
    `containsValue` in interface `Map`

### keySet

    public Set keySet()

  Specified by:
    `keySet` in interface `Map`

### values

    public Collection values()

  Specified by:
    `values` in interface `Map`

### entrySet

    public Set entrySet()

  Specified by:
    `entrySet` in interface `Map`

### entryRemoved

    protected void entryRemoved(Object key,
                                Object value)

### entryWeakRefAdded

    protected void entryWeakRefAdded(Object key,
                                     Object value)

### entryHardRefAdded

    protected void entryHardRefAdded(Object key,
                                     Object value)

### getStatistics

    public Collection getStatistics()

Overview | Package | Class | Tree | Deprecated | Index | Help
| SolarMetric Kodo JDO 3.4.1 generated on May 30 2006
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright 2001,2002 SolarMetric, Inc. All Rights Reserved.