Top Fields Constructors Methods
com.jogamp.common.util.cache

public Class TempFileCache

extends Object
Class Inheritance
Imports
java.io.File, .FileOutputStream, .FilenameFilter, .IOException, java.nio.channels.FileChannel, .FileLock, com.jogamp.common.util.IOUtil, .InterruptSource, jogamp.common.Debug

Field Summary

Modifier and TypeField and Description
private static final boolean
private File
private boolean
private static boolean
private static final File
private static final String
private static File
pack-priv static final String
private static String

Constructor Summary

AccessConstructor and Description
public
TempFileCache()

Create the individualTmpDir.

Method Summary

Modifier and TypeMethod and Description
private void
createTmpDir()

Create the temp directory in tmpRootDir.

private static void
deleteOldTempDirs()

Called by the Reaper thread to delete old temp directories Only one of these threads will run per JVM invocation.

public void
destroy()

Delete the individualTmpDir recursively and remove it's reference.

public File
getBaseDir()

Base temp directory used by TempFileCache.

public File
getRootDir()

Root temp directory for this JVM instance.

public File
getTempDir()

Temporary directory for individual files (eg.

public static boolean

Returns:

true is static initialization was successful
initSingleton
()

Documented way to kick off static initialization

private static void
initTmpRoot()

This method is called by the static initializer to create / initialize the temp root directory that will hold the temp directories for this instance of the JVM.

public boolean

Returns:

true is static and object initialization was successful
isValid
()

private static void
removeAll(final File path)

Remove the specified file or directory.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEBUGback to summary
private static final boolean DEBUG
individualTmpDirback to summary
private File individualTmpDir
initErrorback to summary
private boolean initError
staticInitErrorback to summary
private static boolean staticInitError
tmpBaseDirback to summary
private static final File tmpBaseDir
tmpDirPrefixback to summary
private static final String tmpDirPrefix
tmpRootDirback to summary
private static File tmpRootDir
tmpRootPropNameback to summary
pack-priv static final String tmpRootPropName
tmpRootPropValueback to summary
private static String tmpRootPropValue

Constructor Detail

TempFileCacheback to summary
public TempFileCache()

Create the individualTmpDir.

Method Detail

createTmpDirback to summary
private void createTmpDir() throws IOException

Create the temp directory in tmpRootDir. To do this, we create a temp file with a ".tmp" extension, and then create a directory of the same name but without the ".tmp". The temp file, directory, and all files in the directory will be reaped the next time this is started. We avoid deleteOnExit, because it doesn't work reliably.

deleteOldTempDirsback to summary
private static void deleteOldTempDirs()

Called by the Reaper thread to delete old temp directories Only one of these threads will run per JVM invocation.

destroyback to summary
public void destroy()

Delete the individualTmpDir recursively and remove it's reference.

getBaseDirback to summary
public File getBaseDir()

Base temp directory used by TempFileCache.

Lifecycle: For one user's JVMs, ClassLoader and time.

This is set to:
  ${java.io.tmpdir}/tmpDirPrefix
getRootDirback to summary
public File getRootDir()

Root temp directory for this JVM instance. Used to store individual directories.

Lifecycle: For one user's concurrently running JVMs and ClassLoader

  tmpBaseDir/tmpRootPropValue

Use Case: Per ClassLoader files, eg. native libraries.

Old temp directories are cleaned up the next time a JVM is launched that uses TempFileCache.

getTempDirback to summary
public File getTempDir()

Temporary directory for individual files (eg. native libraries of one ClassLoader instance). The directory name is:

Lifecycle: Within each JVM .. use case dependent, ie. per ClassLoader

  tmpRootDir/jlnMMMMM
where jlnMMMMM is the unique filename created by File.createTempFile() without the ".tmp" extension.
initSingletonback to summary
public static boolean initSingleton()

Documented way to kick off static initialization

Returns:boolean

true is static initialization was successful

initTmpRootback to summary
private static void initTmpRoot() throws IOException

This method is called by the static initializer to create / initialize the temp root directory that will hold the temp directories for this instance of the JVM. This is done as follows: 1. Synchronize on a global lock. Note that for this purpose we will use System.out in the absence of a true global lock facility. We are careful not to hold this lock too long. The global lock is claimed in the static initializer block, calling this method! 2. Check for the existence of the "jnlp.jogamp.tmp.cache.root" system property. a. If set, then some other thread in a different ClassLoader has already created the tmpRootDir, so we just need to use it. The remaining steps are skipped. However, we check the existence of the tmpRootDir and if non existent, we assume a new launch and continue. b. If not set, then we are the first thread in this JVM to run, and we need to create the the tmpRootDir. 3. Create the tmpRootDir, along with the appropriate locks. Note that we perform the operations in the following order, prior to creating tmpRootDir itself, to work around the fact that the file creation and file lock steps are not atomic, and we need to ensure that a newly-created tmpRootDir isn't reaped by a concurrently running JVM. create jlnNNNN.tmp using File.createTempFile() lock jlnNNNN.tmp create jlnNNNN.lck while holding the lock on the .tmp file lock jlnNNNN.lck Since the Reaper thread will enumerate the list of *.lck files before starting, we can guarantee that if there exists a *.lck file for an active process, then the corresponding *.tmp file is locked by that active process. This guarantee lets us avoid reaping an active process' files. 4. Set the "jnlp.jogamp.tmp.cache.root" system property. 5. Add a shutdown hook to cleanup jlnNNNN.lck and jlnNNNN.tmp. We don't actually expect that this shutdown hook will ever be called, but the act of doing this, ensures that the locks never get garbage-collected, which is necessary for correct behavior when the first ClassLoader is later unloaded, while subsequent Applets are still running. 6. Start the Reaper thread to cleanup old installations.

isValidback to summary
public boolean isValid()
Returns:boolean

true is static and object initialization was successful

removeAllback to summary
private static void removeAll(final File path)

Remove the specified file or directory. If "path" is a directory, then recursively remove all entries, then remove the directory itself.