Class HumanFaceMemoryManagerImpl
java.lang.Object
cz.fidentis.analyst.data.face.impl.HumanFaceMemoryManagerImpl
- All Implemented Interfaces:
HumanFaceMemoryManager
A flyweight factory that creates and caches human faces. Faces are
stored in the memory until there is enough space in the Java heap. Then they
are cached on disk automatically. The dumping strategy can be switched at run-time.
Currently, listeners registered to HumanFace
are neither dumped nor recovered!
-
Nested Class Summary
Nested classes/interfaces inherited from interface cz.fidentis.analyst.data.face.HumanFaceMemoryManager
HumanFaceMemoryManager.Strategy
-
Field Summary
Fields inherited from interface cz.fidentis.analyst.data.face.HumanFaceMemoryManager
MAX_DUMP_FACES, MIN_FREE_MEMORY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionDirectly adds an existing face instance into the factory.protected File
dumpToFile
(HumanFace face) protected static String
formatSize
(long v) Returns a human face.Returns current dumping strategy.protected int
Checks and releases the heap, if necessary.boolean
Checks whether the given face is loaded in the factoryLoads new face.protected long
https://stackoverflow.com/questions/12807797/java-get-available-memoryboolean
removeFace
(String faceId) Removes the face from either memory or swap space.protected static HumanFace
restoreFromFile
(File dumpFile) void
setReuseDumpFile
(boolean use) If set totrue
, then the dump file of a face is created only once and then reused for every recovery (it is never overwritten).void
setStrategy
(HumanFaceMemoryManager.Strategy strategy) Changes the dumping strategytoString()
protected boolean
updateAccessTime
(String faceId) Updates last access time of the face allocated in the memory.
-
Constructor Details
-
HumanFaceMemoryManagerImpl
public HumanFaceMemoryManagerImpl()Constructor.
-
-
Method Details
-
setStrategy
Description copied from interface:HumanFaceMemoryManager
Changes the dumping strategy- Specified by:
setStrategy
in interfaceHumanFaceMemoryManager
- Parameters:
strategy
- Dumping strategy. Must not benull
-
getStrategy
Description copied from interface:HumanFaceMemoryManager
Returns current dumping strategy.- Specified by:
getStrategy
in interfaceHumanFaceMemoryManager
- Returns:
- current dumping strategy
-
setReuseDumpFile
public void setReuseDumpFile(boolean use) Description copied from interface:HumanFaceMemoryManager
If set totrue
, then the dump file of a face is created only once and then reused for every recovery (it is never overwritten). It accelerates the dumping face, but can be used only if the state of faces never changes between the first dump a consequent recoveries. If set tofalse
, then every dump of the face to the disk overwrites the file.- Specified by:
setReuseDumpFile
in interfaceHumanFaceMemoryManager
- Parameters:
use
- Iftrue
, then this optimization is turned on.
-
loadFace
Description copied from interface:HumanFaceMemoryManager
Loads new face. If the face is already loaded, then the ID of existing instance is returned. To access the human face instance, useHumanFaceMemoryManager.getFace(String)
.- Specified by:
loadFace
in interfaceHumanFaceMemoryManager
- Parameters:
file
- OBJ file with human face.- Returns:
- ID of the human face or
null
-
isLoaded
Description copied from interface:HumanFaceMemoryManager
Checks whether the given face is loaded in the factory- Specified by:
isLoaded
in interfaceHumanFaceMemoryManager
- Parameters:
faceFile
- OBJ file with human face.- Returns:
true
if the face exists in the factory,false
otherwise.
-
addFace
Description copied from interface:HumanFaceMemoryManager
Directly adds an existing face instance into the factory. If a face with the same ID already exists, then it is replaced.- Specified by:
addFace
in interfaceHumanFaceMemoryManager
- Parameters:
face
- Human face- Returns:
- ID of the human face or
null
-
getFace
Description copied from interface:HumanFaceMemoryManager
Returns a human face. Recovers the face from the disk if necessary.- Specified by:
getFace
in interfaceHumanFaceMemoryManager
- Parameters:
faceId
- ID of the face- Returns:
- Human face or
null
-
removeFace
Description copied from interface:HumanFaceMemoryManager
Removes the face from either memory or swap space. To re-initiate the face, useHumanFaceMemoryManager.loadFace(java.io.File)
again.- Specified by:
removeFace
in interfaceHumanFaceMemoryManager
- Parameters:
faceId
- Face ID- Returns:
- true if the face existed and was removed.
-
toString
-
updateAccessTime
Updates last access time of the face allocated in the memory. Returnsfalse
if the face is not in the memory.- Parameters:
faceId
- Face to be updated- Returns:
false
if the face is not in the memory.
-
checkMemAndDump
Checks and releases the heap, if necessary.- Returns:
- true if some existing face has been dumped to free the memory.
- Throws:
IOException
- on I/O error
-
formatSize
-
presumableFreeMemory
protected long presumableFreeMemory()https://stackoverflow.com/questions/12807797/java-get-available-memory- Returns:
-
dumpToFile
- Throws:
IOException
-
restoreFromFile
- Throws:
IOException
-