Top Description Inners Fields Constructors Methods
net.sf.ehcache

public final Class DiskStorePathManager

extends Object
Class Inheritance
Imports
java.io.File, .IOException, .RandomAccessFile, java.nio.channels.FileChannel, .FileLock, .OverlappingFileLockException, java.util.HashSet, .Set, net.sf.ehcache.config.DiskStoreConfiguration, org.slf4j.Logger, .LoggerFactory

Manager class to handle disk store path. CacheManager has a reference to this manager.
Author
hhuynh

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
DiskStorePathManager.DiskstoreNotExclusiveException

Exception class thrown when a diskstore path collides with an existing one

private static class
DiskStorePathManager.DiskStorePath

Resolved path and lock details

Field Summary

Modifier and TypeField and Description
private static final String
AUTO_DISK_PATH_DIRECTORY_PREFIX

If the CacheManager needs to resolve a conflict with the disk path, it will create a subdirectory in the given disk path with this prefix followed by a number.

private final boolean
private static final int
private static final char
private static final Set<Character>
private final File
private static final String
private static final Logger
private volatile DiskStorePathManager.DiskStorePath

Constructor Summary

AccessConstructor and Description
public
DiskStorePathManager(String
diskstore path on disk
initialPath
)

Create a diskstore path manager with provided initial path.

public
DiskStorePathManager()

Create a diskstore path manager using the default path.

Method Summary

Modifier and TypeMethod and Description
private static void
public File

Returns:

a file object
getFile
(String
the cache name
cacheName
,
String
a file suffix
suffix
)

Get a file object for the given cache-name and suffix

public File

Returns:

a file object
getFile
(String
the file name
name
)

Get a file object for the given name

public boolean

Returns:

true if path is auto created
isAutoCreated
()

Was this path auto-created (ie.

public boolean

Returns:

true if path is the default
isDefault
()

Was this path sourced from the default value.

public synchronized void
releaseLock()

release the lock file used for collision detection should be called when cache manager shutdowns

public boolean

Returns:

true if the file existed and the path was successfully locked
resolveAndLockIfExists
(String
file to check for
file
)

Resolve and lock this disk store path if the resultant path contains the supplied file.

private void
resolveAndLockIfNeeded(boolean allowAutoCreate)

private static String

Returns:

sanitized version of name
safeName
(String name)

sanitize a name for valid file or directory name

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

AUTO_DISK_PATH_DIRECTORY_PREFIXback to summary
private static final String AUTO_DISK_PATH_DIRECTORY_PREFIX

If the CacheManager needs to resolve a conflict with the disk path, it will create a subdirectory in the given disk path with this prefix followed by a number. The presence of this name is used to determined whether it makes sense for a persistent DiskStore to be loaded. Loading persistent DiskStores will only have useful semantics where the diskStore path has not changed.

defaultPathback to summary
private final boolean defaultPath
DELback to summary
private static final int DEL
ESCAPEback to summary
private static final char ESCAPE
ILLEGALSback to summary
private static final Set<Character> ILLEGALS
initialPathback to summary
private final File initialPath
LOCK_FILE_NAMEback to summary
private static final String LOCK_FILE_NAME
LOGback to summary
private static final Logger LOG
pathback to summary
private volatile DiskStorePathManager.DiskStorePath path

Constructor Detail

DiskStorePathManagerback to summary
public DiskStorePathManager(String initialPath)

Create a diskstore path manager with provided initial path.

Parameters
initialPath:String

diskstore path on disk

DiskStorePathManagerback to summary
public DiskStorePathManager()

Create a diskstore path manager using the default path.

Method Detail

deleteFileback to summary
private static void deleteFile(File f)
getFileback to summary
public File getFile(String cacheName, String suffix)

Get a file object for the given cache-name and suffix

Parameters
cacheName:String

the cache name

suffix:String

a file suffix

Returns:File

a file object

getFileback to summary
public File getFile(String name)

Get a file object for the given name

Parameters
name:String

the file name

Returns:File

a file object

isAutoCreatedback to summary
public boolean isAutoCreated()

Was this path auto-created (ie. the result of a collision)

Returns:boolean

true if path is auto created

isDefaultback to summary
public boolean isDefault()

Was this path sourced from the default value.

Returns:boolean

true if path is the default

releaseLockback to summary
public synchronized void releaseLock()

release the lock file used for collision detection should be called when cache manager shutdowns

resolveAndLockIfExistsback to summary
public boolean resolveAndLockIfExists(String file)

Resolve and lock this disk store path if the resultant path contains the supplied file.

Parameters
file:String

file to check for

Returns:boolean

true if the file existed and the path was successfully locked

resolveAndLockIfNeededback to summary
private void resolveAndLockIfNeeded(boolean allowAutoCreate) throws DiskstoreNotExclusiveException
safeNameback to summary
private static String safeName(String name)

sanitize a name for valid file or directory name

Returns:String

sanitized version of name

net.sf.ehcache back to summary

private Class DiskStorePathManager.DiskstoreNotExclusiveException

extends Exception
Class Inheritance

Exception class thrown when a diskstore path collides with an existing one

Constructor Summary

AccessConstructor and Description
public
DiskstoreNotExclusiveException()

Constructor for the DiskstoreNotExclusiveException object.

public
DiskstoreNotExclusiveException(String
the exception detail message
message
)

Constructor for the DiskstoreNotExclusiveException object.

Constructor Detail

DiskstoreNotExclusiveExceptionback to summary
public DiskstoreNotExclusiveException()

Constructor for the DiskstoreNotExclusiveException object.

DiskstoreNotExclusiveExceptionback to summary
public DiskstoreNotExclusiveException(String message)

Constructor for the DiskstoreNotExclusiveException object.

Parameters
message:String

the exception detail message

net.sf.ehcache back to summary

private Class DiskStorePathManager.DiskStorePath

extends Object
Class Inheritance

Resolved path and lock details

Field Summary

Modifier and TypeField and Description
private final boolean
private final boolean
private final FileLock
private final File
private final File

Constructor Summary

AccessConstructor and Description
pack-priv
DiskStorePath(File path, boolean autoCreated, boolean defaultPath)

Method Summary

Modifier and TypeMethod and Description
pack-priv File
pack-priv File
pack-priv boolean
pack-priv boolean
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
pack-priv void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

autoCreatedback to summary
private final boolean autoCreated
defaultPathback to summary
private final boolean defaultPath
directoryLockback to summary
private final FileLock directoryLock
diskStorePathback to summary
private final File diskStorePath
lockFileback to summary
private final File lockFile

Constructor Detail

DiskStorePathback to summary
pack-priv DiskStorePath(File path, boolean autoCreated, boolean defaultPath) throws DiskstoreNotExclusiveException

Method Detail

getDiskStorePathback to summary
pack-priv File getDiskStorePath()
getLockFileback to summary
pack-priv File getLockFile()
isAutoCreatedback to summary
pack-priv boolean isAutoCreated()
isDefaultback to summary
pack-priv boolean isDefault()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
unlockback to summary
pack-priv void unlock()