cz.hdf.cdnavigator
Class Cache

java.lang.Object
  extended by cz.hdf.cdnavigator.Cache

public class Cache
extends java.lang.Object

Cache files in another thread. You can easy put files into cache without waiting cacheFile() or wait for finishing cacheFileDirectly(). Right CD medium must be mounted in mount dir.

Author:
hunter

Nested Class Summary
private  class Cache.Cacher
          Cache/copy files into cache directory.
private  class Cache.Updater
          Go through cache directory and update timeFileSizes structure.
 
Field Summary
private  java.io.File cacheDir
          cache directory
private  Cache.Cacher cacher
          thread to copy files
private  java.util.ArrayList<CacheFileRecord> filesToCache
          new files to copy in cache
private  java.util.logging.Logger logger
          Logger.
private  boolean run
          cacher will run until this is true
private  long size
          cache size, size of all files in bytes
private  java.util.SortedMap<java.lang.Long,java.lang.Long> timeFileSizes
          files already in cache. key = time, value = size of all files with this time
private  Cache.Updater updater
          thread to update cache structure
 
Constructor Summary
Cache()
          Initialize cache and sorted list of cache files.
 
Method Summary
static java.lang.String buildCacheFolderName(java.lang.String _hashcode)
          Build/Create folder name for caching CDs.
 void cacheFile(CDData _cd, java.lang.String _relFile)
          Add file to cache. if file already exists - his time is updated, else copy file to cache.
 void cacheFileDirectly(CDData _cd, java.lang.String _relFile)
          Add file to cache. if file already exists - his time is updated, else copy file to cache.
 void changeCacheDir(java.lang.String _newDirectory)
          call when user set new cache directory.
 void clearDirectory(java.io.File _file, java.lang.Long _timeToDelete, boolean _deleteRoot)
          DOCUMENT ME!
 void stop()
          stop cacher.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

timeFileSizes

private java.util.SortedMap<java.lang.Long,java.lang.Long> timeFileSizes
files already in cache. key = time, value = size of all files with this time


filesToCache

private java.util.ArrayList<CacheFileRecord> filesToCache
new files to copy in cache


cacher

private Cache.Cacher cacher
thread to copy files


updater

private Cache.Updater updater
thread to update cache structure


cacheDir

private java.io.File cacheDir
cache directory


run

private boolean run
cacher will run until this is true


size

private long size
cache size, size of all files in bytes


logger

private java.util.logging.Logger logger
Logger. Hierarchy is set to name of this class.

Constructor Detail

Cache

public Cache()
Initialize cache and sorted list of cache files.

Method Detail

cacheFile

public void cacheFile(CDData _cd,
                      java.lang.String _relFile)
Add file to cache. if file already exists - his time is updated, else copy file to cache. This will be processed in another thread without waiting.

Parameters:
_cd - CD data of file to cache
_relFile - file to cache

cacheFileDirectly

public void cacheFileDirectly(CDData _cd,
                              java.lang.String _relFile)
Add file to cache. if file already exists - his time is updated, else copy file to cache. This will be processed immediately. Operation will wait after cache finished.

Parameters:
_cd - CD of file to cache
_relFile - file to cache

changeCacheDir

public void changeCacheDir(java.lang.String _newDirectory)
call when user set new cache directory. Updates cache structure.

Parameters:
_newDirectory - new cache directory

clearDirectory

public void clearDirectory(java.io.File _file,
                           java.lang.Long _timeToDelete,
                           boolean _deleteRoot)
DOCUMENT ME!

Parameters:
_file -
_timeToDelete -
_deleteRoot - delete root empty folder?

stop

public void stop()
stop cacher.


buildCacheFolderName

public static java.lang.String buildCacheFolderName(java.lang.String _hashcode)
Build/Create folder name for caching CDs.

Parameters:
_hashcode -
Returns:


CDnavigator JavaDoc, HDF company www.hdf.cz