public class Memoizer extends ReaderWrapper
ReaderWrapper
implementation which caches the state of the
delegate (including and other ReaderWrapper
instances)
after setId has been called.Modifier and Type | Class and Description |
---|---|
static interface |
Memoizer.Deser |
static class |
Memoizer.KryoDeser |
private static class |
Memoizer.RandomAccessDeser
Helper implementation that can be used to implement
Memoizer.Deser
classes for libraries working solely with byte arrays. |
Modifier and Type | Field and Description |
---|---|
static long |
DEFAULT_MINIMUM_ELAPSED
Default value for
minimumElapsed if none is provided in the
constructor. |
private File |
directory
Directory where all memo files should be created.
|
private boolean |
doInPlaceCaching
If True, then all memo files will be created in the same directory as the
original file.
|
private boolean |
loadedFromMemo
Whether the
ReaderWrapper.reader instance currently active was loaded from
the memo file during setId(String) . |
private static org.slf4j.Logger |
LOGGER |
private File |
memoFile |
private long |
minimumElapsed
Minimum number of milliseconds which must elapse during the call to
setId(java.lang.String) before a memo file will be created. |
private Location |
realFile |
private MetadataStore |
replacementMetadataStore
MetadataStore created internally. |
private boolean |
savedToMemo
Whether the
ReaderWrapper.reader instance was saved to a memo file on
setId(String) . |
protected Memoizer.Deser |
ser |
private OMEXMLService |
service |
private boolean |
skipLoad |
private boolean |
skipSave |
private File |
tempFile |
private MetadataStore |
userMetadataStore
MetadataStore set by the caller. |
static Integer |
VERSION
Defines the file format.
|
private boolean |
versionChecking
Whether to invalidate the memo file based upon mismatched major/minor
version numbers.
|
reader
CAN_GROUP, CANNOT_GROUP, MUST_GROUP
Constructor and Description |
---|
Memoizer()
Constructs a memoizer around a new
ImageReader creating memo
files under the same directory as the original file only if the call to
setId(java.lang.String) takes longer than 100L in
milliseconds. |
Memoizer(IFormatReader r)
Constructs a memoizer around the given
IFormatReader creating
memo files under the same directory as the original file only if the
call to setId(java.lang.String) takes longer than
100L in milliseconds. |
Memoizer(IFormatReader r,
long minimumElapsed)
Constructs a memoizer around the given
IFormatReader creating
memo files under the same directory as the original file only if the
call to setId(java.lang.String) takes longer than minimumElapsed
in milliseconds. |
Memoizer(IFormatReader r,
long minimumElapsed,
File directory)
Constructs a memoizer around the given
IFormatReader creating
memo files under the directory argument including the full
path of the original file only if the call to setId(java.lang.String) takes
longer than minimumElapsed in milliseconds. |
Memoizer(long minimumElapsed)
Constructs a memoizer around a new
ImageReader creating memo
files under the same directory as the original file only if the call to
setId(java.lang.String) takes longer than minimumElapsed in
milliseconds. |
Memoizer(long minimumElapsed,
File directory)
Constructs a memoizer around a new
ImageReader creating memo
files under the directory argument including the full
path of the original file only if the call to setId(java.lang.String) takes
longer than minimumElapsed in milliseconds. |
Modifier and Type | Method and Description |
---|---|
protected void |
cleanup() |
void |
close() |
void |
close(boolean fileOnly)
Closes the currently open file.
|
protected boolean |
deleteQuietly(File file)
Attempts to delete an existing file, logging at
warn if the deletion returns false or at error
if an exception is thrown.
|
protected Memoizer.Deser |
getDeser()
Returns a configured
Kryo instance. |
File |
getMemoFile(String id)
Constructs a
File object from id string. |
MetadataStore |
getMetadataStore()
Retrieves the current metadata store for this reader.
|
protected OMEXMLService |
getService() |
protected IFormatReader |
handleMetadataStore(IFormatReader memo)
Return the
IFormatReader instance that is passed in or null if
it has been invalidated, which will include the instance being closed. |
boolean |
isLoadedFromMemo()
Returns whether the
ReaderWrapper.reader instance currently active was loaded
from the memo file during setId(String) . |
boolean |
isSavedToMemo()
Returns whether the
ReaderWrapper.reader instance currently active was saved
to the memo file during setId(String) . |
boolean |
isVersionChecking()
Returns whether or not version checking is done based upon major/minor
version numbers.
|
private static void |
load(String id,
File tmp,
boolean delete) |
IFormatReader |
loadMemo()
Load a memo file if possible, returning a null if not.
|
static void |
main(String[] args) |
boolean |
saveMemo() |
void |
setId(String id)
Sets the current file name.
|
void |
setMetadataStore(MetadataStore store)
Sets the default metadata store for this reader.
|
void |
setVersionChecking(boolean version)
Set whether version checking is done based upon major/minor version
numbers.
|
protected org.perf4j.slf4j.Slf4JStopWatch |
stopWatch() |
boolean |
versionMismatch()
Returns true if the version of the memo file as returned by
Memoizer.Deser.loadReleaseVersion() and Memoizer.Deser.loadRevision()
do not match the current version as specified by FormatTools.VERSION
and FormatTools.VCS_REVISION , respectively. |
coreIndexToSeries, duplicate, fileGroupOption, get16BitLookupTable, get8BitLookupTable, getAdvancedSeriesUsedFiles, getAdvancedUsedFiles, getBitsPerPixel, getCoreIndex, getCoreMetadataList, getCurrentFile, getDatasetStructureDescription, getDimensionOrder, getDomains, getEffectiveSizeC, getFormat, getGlobalMetadata, getImageCount, getIndex, getIndex, getMetadataOptions, getMetadataStoreRoot, getMetadataValue, getModuloC, getModuloT, getModuloZ, getNativeDataType, getOptimalTileHeight, getOptimalTileWidth, getPixelType, getPossibleDomains, getReader, getRequiredDirectories, getResolution, getResolutionCount, getRGBChannelCount, getSeries, getSeriesCount, getSeriesMetadata, getSeriesMetadataValue, getSeriesUsedFiles, getSeriesUsedFiles, getSizeC, getSizeT, getSizeX, getSizeY, getSizeZ, getSuffixes, getSupportedMetadataLevels, getThumbSizeX, getThumbSizeY, getUnderlyingReaders, getUsedFiles, getUsedFiles, getZCTCoords, getZCTModuloCoords, hasCompanionFiles, hasFlattenedResolutions, isFalseColor, isGroupFiles, isIndexed, isInterleaved, isInterleaved, isLittleEndian, isMetadataComplete, isMetadataFiltered, isNormalized, isOrderCertain, isOriginalMetadataPopulated, isRGB, isSingleFile, isThisType, isThisType, isThisType, isThisType, isThumbnailSeries, openBytes, openBytes, openBytes, openBytes, openPlane, openThumbBytes, reopenFile, seriesToCoreIndex, setCoreIndex, setFlattenedResolutions, setGroupFiles, setMetadataFiltered, setMetadataOptions, setNormalized, setOriginalMetadataPopulated, setResolution, setSeries, unwrap, unwrap, unwrap
public static final Integer VERSION
public static final long DEFAULT_MINIMUM_ELAPSED
minimumElapsed
if none is provided in the
constructor.private static final org.slf4j.Logger LOGGER
private final long minimumElapsed
setId(java.lang.String)
before a memo file will be created.private final File directory
private boolean doInPlaceCaching
protected transient Memoizer.Deser ser
private transient OMEXMLService service
private Location realFile
private File memoFile
private File tempFile
private boolean skipLoad
private boolean skipSave
private boolean versionChecking
private boolean loadedFromMemo
ReaderWrapper.reader
instance currently active was loaded from
the memo file during setId(String)
.private boolean savedToMemo
ReaderWrapper.reader
instance was saved to a memo file on
setId(String)
.private MetadataStore userMetadataStore
MetadataStore
set by the caller. This value will be held locally
and not set on the ReaderWrapper.reader
delegate until the execution
of setId(String)
. If no value has been set by the caller, then
no special actions are taken during setId(String)
. If a value
is set, however, we must be careful with attempting to serialize ithandleMetadataStore(IFormatReader)
private MetadataStore replacementMetadataStore
MetadataStore
created internally.handleMetadataStore(IFormatReader)
public Memoizer()
ImageReader
creating memo
files under the same directory as the original file only if the call to
setId(java.lang.String)
takes longer than 100L in
milliseconds.public Memoizer(long minimumElapsed)
ImageReader
creating memo
files under the same directory as the original file only if the call to
setId(java.lang.String)
takes longer than minimumElapsed
in
milliseconds.minimumElapsed
- a long specifying the number of milliseconds which
must elapse during the call to setId(java.lang.String)
before a memo file
will be created.public Memoizer(long minimumElapsed, File directory)
ImageReader
creating memo
files under the directory
argument including the full
path of the original file only if the call to setId(java.lang.String)
takes
longer than minimumElapsed
in milliseconds.minimumElapsed
- a long specifying the number of milliseconds which
must elapse during the call to setId(java.lang.String)
before a memo file
will be created.directory
- a File
specifying the directory where all memo
files should be created. If null
, disable
memoization.public Memoizer(IFormatReader r)
IFormatReader
creating
memo files under the same directory as the original file only if the
call to setId(java.lang.String)
takes longer than
100L in milliseconds.r
- an IFormatReader
instancepublic Memoizer(IFormatReader r, long minimumElapsed)
IFormatReader
creating
memo files under the same directory as the original file only if the
call to setId(java.lang.String)
takes longer than minimumElapsed
in milliseconds.r
- an IFormatReader
instanceminimumElapsed
- a long specifying the number of milliseconds which
must elapse during the call to setId(java.lang.String)
before a memo file
will be created.public Memoizer(IFormatReader r, long minimumElapsed, File directory)
IFormatReader
creating
memo files under the directory
argument including the full
path of the original file only if the call to setId(java.lang.String)
takes
longer than minimumElapsed
in milliseconds.r
- an IFormatReader
instanceminimumElapsed
- a long specifying the number of milliseconds which
must elapse during the call to setId(java.lang.String)
before a memo file
will be created.directory
- a File
specifying the directory where all memo
files should be created. If null
, disable
memoization.public boolean isLoadedFromMemo()
ReaderWrapper.reader
instance currently active was loaded
from the memo file during setId(String)
.public boolean isSavedToMemo()
ReaderWrapper.reader
instance currently active was saved
to the memo file during setId(String)
.public boolean isVersionChecking()
public boolean versionMismatch() throws IOException
Memoizer.Deser.loadReleaseVersion()
and Memoizer.Deser.loadRevision()
do not match the current version as specified by FormatTools.VERSION
and FormatTools.VCS_REVISION
, respectively.IOException
public void setVersionChecking(boolean version)
protected void cleanup()
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class ReaderWrapper
IOException
public void close(boolean fileOnly) throws IOException
IFormatReader
Closeable.close()
.close
in interface IFormatReader
close
in class ReaderWrapper
IOException
public void setId(String id) throws FormatException, IOException
IFormatHandler
setId
in interface IFormatHandler
setId
in class ReaderWrapper
FormatException
IOException
public void setMetadataStore(MetadataStore store)
IFormatReader
setMetadataStore
in interface IFormatReader
setMetadataStore
in class ReaderWrapper
store
- a metadata store implementation.public MetadataStore getMetadataStore()
IFormatReader
null
metadata store.getMetadataStore
in interface IFormatReader
getMetadataStore
in class ReaderWrapper
protected boolean deleteQuietly(File file)
File.delete()
or false
if an exception is thrown.protected Memoizer.Deser getDeser()
Kryo
instance. This method can be modified
by consumers. The returned instance is not thread-safe.Kryo
instance.protected OMEXMLService getService() throws MissingLibraryException
MissingLibraryException
protected org.perf4j.slf4j.Slf4JStopWatch stopWatch()
public File getMemoFile(String id)
File
object from id
string. This method
can be modified by consumers, but then existing memo files will not be
found.id
- the path passed to setId(java.lang.String)
File
object pointing at the location of the memo filepublic IFormatReader loadMemo() throws IOException, FormatException
IOException
FormatException
public boolean saveMemo()
protected IFormatReader handleMetadataStore(IFormatReader memo) throws MissingLibraryException
IFormatReader
instance that is passed in or null if
it has been invalidated, which will include the instance being closed.
MetadataStore
implementation is passed in when no memo file exists, then a replacement
MetadataStore
will be created and set on the ReaderWrapper.reader
delegate before calling ReaderWrapper.setId(String)
. This stack
will then be serialized, before any values are copied into
userMetadataStore
.
MetadataStore
implementation is set before calling setId(String)
then ...
MissingLibraryException
Copyright © 2015 Open Microscopy Environment