Package cz.fidentis.analyst.data.face
Interface HumanFaceMemoryManager
- All Known Implementing Classes:
HumanFaceMemoryManagerImpl
public interface 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 ClassesModifier and TypeInterfaceDescriptionstatic enum
Dumping strategies. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Memory clean up, i.e. dumping the file into disk and de-referencing it, is very fast.static final double
Keep at least this portion of the Java heap memory free -
Method Summary
Modifier and TypeMethodDescriptionDirectly adds an existing face instance into the factory.void
Removes all faces from memory and swap spacestatic HumanFaceMemoryManager
create()
Creates a new instance of the factory.Returns a human face.Returns current dumping strategy.boolean
Checks whether the given face is loaded in the factoryLoads new face.boolean
removeFace
(Long faceId) Removes the face from either memory or swap space.void
setStrategy
(HumanFaceMemoryManager.Strategy strategy) Changes the dumping strategy
-
Field Details
-
MAX_DUMP_FACES
static final int MAX_DUMP_FACESMemory clean up, i.e. dumping the file into disk and de-referencing it, is very fast. Faster real objects removal by JVM. Therefore, thecheckMemAndDump()
method removes almostMAX_DUMP_FACES
at once.- See Also:
-
MIN_FREE_MEMORY
static final double MIN_FREE_MEMORYKeep at least this portion of the Java heap memory free- See Also:
-
-
Method Details
-
create
Creates a new instance of the factory.- Returns:
- a new instance of the factory.
-
setStrategy
Changes the dumping strategy- Parameters:
strategy
- Dumping strategy. Must not benull
- Throws:
IllegalArgumentException
- if the strategy is missing
-
getStrategy
HumanFaceMemoryManager.Strategy getStrategy()Returns current dumping strategy.- Returns:
- current dumping strategy
-
loadFace
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)
- Parameters:
file
- OBJ file with human face.- Returns:
- ID of the human face or
null
-
isLoaded
Checks whether the given face is loaded in the factory- Parameters:
faceId
- OBJ file with human face.- Returns:
true
if the face exists in the factory,false
otherwise.
-
addFace
Directly adds an existing face instance into the factory. If a face with the same ID already exists, then it is replaced.- Parameters:
face
- Human face- Returns:
- ID of the human face or
null
-
getFace
Returns a human face. Recovers the face from the disk if necessary.- Parameters:
faceId
- ID of the face- Returns:
- Human face or
null
-
removeFace
Removes the face from either memory or swap space. To re-initiate the face, useloadFace(Long, java.io.File)
again.- Parameters:
faceId
- Face ID- Returns:
- true if the face existed and was removed.
-
clearFaces
void clearFaces()Removes all faces from memory and swap space
-