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.void
Removes all faces from memory and swap spaceprotected 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
(Long faceId) Removes the face from either memory or swap space.protected static HumanFace
restoreFromFile
(File dumpFile) void
setStrategy
(HumanFaceMemoryManager.Strategy strategy) Changes the dumping strategytoString()
protected boolean
updateAccessTime
(Long 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
-
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, useinvalid reference
#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:
faceId
- 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(Long, 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
-
clearFaces
public void clearFaces()Description copied from interface:HumanFaceMemoryManager
Removes all faces from memory and swap space- Specified by:
clearFaces
in interfaceHumanFaceMemoryManager
-