## com.bbn.openmap.layer.rpf
Class RpfCacheHandler

    java.lang.Object
      com.bbn.openmap.layer.rpf.RpfCacheHandler

public class RpfCacheHandler
extends java.lang.Object

The RpfCacheHandler handles everything to do with the decompressed subframes, which is what gets put up on the screen. It interfaces with the RpfFrameProvider to get the information about the data. It also is usually handled by the RpfCacheManager.

Nested Class Summary
`static class` `RpfCacheHandler.SubframeCache` The entire subframe cache

Field Summary
`protected RpfCacheHandler.SubframeCache` `cache` The subframe cache.
`protected java.util.Vector` `coverageBoxes` The current description of the TOC entry that currently applies.
`protected boolean` `DEBUG_RPF`
`protected boolean` `DEBUG_RPFDETAIL`
`static int` `DEFAULT_SUBFRAMEBUFFER`
`protected java.awt.Point` `end` The lower right subframe index on screen.
`protected RpfFrameProvider` `frameProvider` The place to look for for image data.
`protected boolean` `goodData` A flag to let the cache manager know that the subframes needed for the map make sense.
`static int` `MAX_DESC_LEN`
`static int` `MAX_NUM_DESC`
`static int` `NOT_CACHED` subframe status constant.
`static int` `NOT_PRESENT` subframe status constant.
`protected int` `scalingHeight` Subframe scaling for map scales that don't match chart scale.
`protected int` `scalingWidth` Subframe scaling for map scales that don't match chart scale.
`protected java.awt.Point` `start` The upper left subframe index on screen.
`static int` `SUBFRAME_CACHE_SIZE`
`protected int` `subframeBuffer` The subframe cache is mapped by a 2D matrix based on the number of subframes that will fit in the RpfCoverageBox area.
`protected int` `subframeCacheSize` The size of the subframe cache.
`protected byte[][]` `subframeIndex` The array of indexes for subframes contained in the RpfTocEntry.
`protected byte[][]` `subframeVersion` The array of version markers for subframes contained in the RpfTocEntry.
`protected RpfViewAttributes` `viewAttributes` Description of how the frames should be constructed and displayed.

Constructor Summary
`RpfCacheHandler(RpfFrameProvider provider, RpfViewAttributes rva)` Constructor for a main cache, with the full size cache.
`RpfCacheHandler(RpfFrameProvider provider, RpfViewAttributes rva, int subframe_cache_size)` Constructor for an auxiliary cache, with a settable cache size.

Method Summary
`void` `clearCache()` Clear the subframes in the cache, marking them as NOT_CACHED.
`protected void` `freeCache(int index)`
`protected RpfSubframe` `getCached(int cbx, int cby)` Get a subframe from the cache if possible, otherwise allocate a new cache entry and decompress it.
`protected RpfSubframe` `getCached(int cbx, int cby, int subframeCount)` Get a subframe from the cache if possible, otherwise allocate a new cache entry and decompress it.
`int` `getCacheSize()` Find out the size of the subframe cache.
`java.util.Vector` `getCoverageBoxes()` Returns the Vector containing RpfCoverageBoxes that was returned from the RpfFrameProvider as a result of the last setCache call.
`RpfFrameProvider` `getFrameProvider()` Return RpfFrameProvider used by the layer.
`boolean` `getGoodData()` Return true if the cache handler knows about good data in the current situation.
`protected int` `getLRU()` Get the index of the least recently used entry from the subframe cache.
`protected RpfSubframe` `getSubframeFromOtherTOC(int x, int y)` Get a subframe from one of the other RpfCoverageBoxes.
`protected RpfSubframe` `getSubframeFromOtherTOC(int x, int y, int subframeCount)` Get a subframe from one of the other RpfCoverageBoxes.
`RpfViewAttributes` `getViewAttributes()` Get the view attributes or the layer.
`protected void` `initCache(boolean newCache)`
`protected boolean` `loadSubframe(RpfSubframe subframe, RpfCoverageBox coverageBox, int x, int y)` Contacts the frame provider to put the subframe image in the RpfSubframe.
`protected void` `referenceCache(int index)` Mark a cache entry as being recently used.
`protected void` `resetSubframeIndex(int vertFrames, int horizFrames)` Resets the indicators in the subframe cache, so that none of the current contents will be used - they'll have to be loaded with data first.
`void` `setCache(float ullat, float ullon, float lrlat, float lrlon, CADRG proj)` Called to prepare the cache for subframes that will fit into the next request.
`void` `setFrameProvider(RpfFrameProvider fp)` Set the RpfFrameProvider for the layer.
`void` `setViewAttributes(RpfViewAttributes rva)` Set the view attributes for the layer.
`void` `updateViewAttributes()` This only needs to be called if the frame provider is not local.

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

Field Detail

### SUBFRAME_CACHE_SIZE

    public static final int SUBFRAME_CACHE_SIZE

See Also:
  Constant Field Values

### MAX_NUM_DESC

    public static final int MAX_NUM_DESC

See Also:
  Constant Field Values

### MAX_DESC_LEN

    public static final int MAX_DESC_LEN

See Also:
  Constant Field Values

### DEFAULT_SUBFRAMEBUFFER

    public static final int DEFAULT_SUBFRAMEBUFFER

See Also:
  Constant Field Values

### NOT_CACHED

    public static final int NOT_CACHED

  subframe status constant.

  See Also:
    Constant Field Values

### NOT_PRESENT

    public static final int NOT_PRESENT

  subframe status constant.

  See Also:
    Constant Field Values

### scalingHeight

    protected int scalingHeight

  Subframe scaling for map scales that don't match chart scale.

### scalingWidth

    protected int scalingWidth

  Subframe scaling for map scales that don't match chart scale.

### cache

    protected RpfCacheHandler.SubframeCache cache

  The subframe cache.

### coverageBoxes

    protected java.util.Vector coverageBoxes

  The current description of the TOC entry that currently applies.

### subframeIndex

    protected byte[][] subframeIndex

  The array of indexes for subframes contained in the RpfTocEntry.

### subframeVersion

    protected byte[][] subframeVersion

  The array of version markers for subframes contained in the RpfTocEntry.

### subframeCacheSize

    protected int subframeCacheSize

  The size of the subframe cache.

### viewAttributes

    protected RpfViewAttributes viewAttributes

  Description of how the frames should be constructed and displayed.

### frameProvider

    protected RpfFrameProvider frameProvider

  The place to look for for image data.

### start

    protected java.awt.Point start

  The upper left subframe index on screen.

### end

    protected java.awt.Point end

  The lower right subframe index on screen.

### goodData

    protected boolean goodData

  A flag to let the cache manager know that the subframes needed for the map make sense.

### subframeBuffer

    protected int subframeBuffer

  The subframe cache is mapped by a 2D matrix based on the number of subframes that will fit in the RpfCoverageBox area. The subframeBuffer is used to put additional subframe entries in the matrix, so that subframes retrieved outside of the RpfCoverageBox area can still be cached. The subframeBuffer refers to the number of subframes added on each side of the matrix.

### DEBUG_RPF

    protected boolean DEBUG_RPF

### DEBUG_RPFDETAIL

    protected boolean DEBUG_RPFDETAIL

Constructor Detail

### RpfCacheHandler

    public RpfCacheHandler(RpfFrameProvider provider,
                           RpfViewAttributes rva)

  Constructor for a main cache, with the full size cache.

### RpfCacheHandler

    public RpfCacheHandler(RpfFrameProvider provider,
                           RpfViewAttributes rva,
                           int subframe_cache_size)

  Constructor for an auxiliary cache, with a settable cache size.

Method Detail

### setViewAttributes

    public void setViewAttributes(RpfViewAttributes rva)

  Set the view attributes for the layer. The frame provider view attributes are updated, and the cache is cleared.

  Parameters:
    `rva` - the RpfViewAttributes used for the layer.

### getViewAttributes

    public RpfViewAttributes getViewAttributes()

  Get the view attributes or the layer.

  Returns:
    RpfViewAttributes.

### setFrameProvider

    public void setFrameProvider(RpfFrameProvider fp)

  Set the RpfFrameProvider for the layer. Clears out the cache, and the frame provider gets the RpfViewAttributes held by the layer.

  Parameters:
    `fp` - the frame provider.

### getFrameProvider

    public RpfFrameProvider getFrameProvider()

  Return RpfFrameProvider used by the layer.

### updateViewAttributes

    public void updateViewAttributes()

  This only needs to be called if the frame provider is not local. In that case, updates to the view attributes object will not be reflected on the server side. This will update the parameters.

### getCoverageBoxes

    public java.util.Vector getCoverageBoxes()

  Returns the Vector containing RpfCoverageBoxes that was returned from the RpfFrameProvider as a result of the last setCache call. These provide rudimentary knowledge about what is being displayed.

  Returns:
    Vector of RpfCoverageBoxes.

### setCache

    public void setCache(float ullat,
                         float ullon,
                         float lrlat,
                         float lrlon,
                         CADRG proj)

  Called to prepare the cache for subframes that will fit into the next request. The subframe entry from the TOC is known and tracked, and if it changes, the frame cache gets tossed and recreated via setScreenSubframes.

  Parameters:
    `ullat` - NW latitude.
    `ullon` - NW longitude.
    `lrlat` - SE latitude.
    `lrlon` - SE longitude
    `proj` - CADRG projection to use for zone decisions.

### resetSubframeIndex

    protected void resetSubframeIndex(int vertFrames,
                                      int horizFrames)

  Resets the indicators in the subframe cache, so that none of the current contents will be used - they'll have to be loaded with data first. The cache mananagement is also set for the current main RpfCoverageBox.

### clearCache

    public void clearCache()

  Clear the subframes in the cache, marking them as NOT_CACHED.

### getGoodData

    public boolean getGoodData()

  Return true if the cache handler knows about good data in the current situation.

### initCache

    protected void initCache(boolean newCache)

### getLRU

    protected int getLRU()

  Get the index of the least recently used entry from the subframe cache.

### freeCache

    protected void freeCache(int index)

### referenceCache

    protected void referenceCache(int index)

  Mark a cache entry as being recently used.

### getCacheSize

    public int getCacheSize()

  Find out the size of the subframe cache. From the start and end indexes, you can figure out the number of subframes the map needs. If that number is bigger than this cache size, you'll need to use the getCached that lets you supply the subframe number that you are requesting, so that the RpfCacheHandler knows when to stop caching subframes during a retrival.. Otherwise, the cache will overwrite data and subframes will not show up on the map.

### getSubframeFromOtherTOC

    protected RpfSubframe getSubframeFromOtherTOC(int x,
                                                  int y)

  Get a subframe from one of the other RpfCoverageBoxes. Keep going through them until there is a subframe returned, or if there's nothing. Use this method when you are sure that the subframe cache is big enough to handle all the subframes on the map.

  Parameters:
    `x` - the x index of subframe in the FIRST RpfCoverageBox space - translation needed.
    `y` - the y index of subframe in the FIRST RpfCoverageBox space - translation needed.

### getSubframeFromOtherTOC

    protected RpfSubframe getSubframeFromOtherTOC(int x,
                                                  int y,
                                                  int subframeCount)

  Get a subframe from one of the other RpfCoverageBoxes. Keep going through them until there is a subframe returned, or if there nothing. If you are not sure that the number of subframes that go on the map is less than or equal to the size of the subframe cache, then use this method to provide a running count of how many subframes you've already called for to use in the current map. If this number gets bigger than the cache size, then the RpfCacheHandler will keep fetching data without storing the extra subframes in the cache. Otherwise, the previous images in the cache would be replaced before they were painted, and they would not appear on the map. If subframeCount is less than subframe size, then the latest retrieved subframe will be stored in the cache.

  Parameters:
    `x` - the x index of subframe in the FIRST RpfCoverageBox space - translation needed.
    `y` - the y index of subframe in the FIRST RpfCoverageBox space - translation needed.
    `subframeCount` - a running count of the number of subframes retrieved so far for the current map. Should be used it there is concern that the number of subframes needed for the map is greater than the size of the subframe.

### getCached

    protected RpfSubframe getCached(int cbx,
                                    int cby)

  Get a subframe from the cache if possible, otherwise allocate a new cache entry and decompress it. Each cache entry has a version number that is incremented whenever it is replaced by a new subframe. This ensures the replacement is detected. Use this method when you are sure that the subframe cache is big enough to handle all the subframes on the map.

  Parameters:
    `cbx` - the x index of subframe in the rcbIndex A.TOC space.
    `cby` - the y index of subframe in the rcbIndex A.TOC space.

### getCached

    protected RpfSubframe getCached(int cbx,
                                    int cby,
                                    int subframeCount)

  Get a subframe from the cache if possible, otherwise allocate a new cache entry and decompress it. Each cache entry has a version number that is incremented whenever it is replaced by a new subframe. This ensures the replacement is detected. If you are not sure that the number of subframes that go on the map is less than or equal to the size of the subframe cache, then use this method to provide a running count of how many subframes you've already called for to use in the current map. If this number gets bigger than the cache size, then the RpfCacheHandler will keep fetching data without storing the extra subframes in the cache. Otherwise, the previous images in the cache would be replaced before they were painted, and they would not appear on the map. If subframeCount is less than subframe size, then the latest retrieved subframe will be stored in the cache.

  Parameters:
    `cbx` - the x index of subframe in the rcbIndex A.TOC space.
    `cby` - the y index of subframe in the rcbIndex A.TOC space.
    `subframeCount` - a running count of the number of subframes retrieved so far for the current map. Should be used if there is concern that the number of subframes needed for the map is greater than the size of the cache.

### loadSubframe

    protected boolean loadSubframe(RpfSubframe subframe,
                                   RpfCoverageBox coverageBox,
                                   int x,
                                   int y)

  Contacts the frame provider to put the subframe image in the RpfSubframe.

  Parameters:
    `subframe` - the RpfSubframe to load the image data into.
    `coverageBox` - that has toc and entry numbers to use.
    `x` - the coveragebox x index for the subframe.
    `y` - the coveragebox y index for the subframe.
  Returns:
    true if successful.

Copyright (C) BBNT Solutions LLC; See http://openmap.bbn.com/ for details