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!

  • Field Details

    • MAX_DUMP_FACES

      static final int MAX_DUMP_FACES
      Memory clean up, i.e. dumping the file into disk and de-referencing it, is very fast. Faster real objects removal by JVM. Therefore, the checkMemAndDump() method removes almost MAX_DUMP_FACES at once.
      See Also:
    • MIN_FREE_MEMORY

      static final double MIN_FREE_MEMORY
      Keep at least this portion of the Java heap memory free
      See Also:
  • Method Details

    • create

      static HumanFaceMemoryManager create()
      Creates a new instance of the factory.
      Returns:
      a new instance of the factory.
    • setStrategy

      void setStrategy(HumanFaceMemoryManager.Strategy strategy)
      Changes the dumping strategy
      Parameters:
      strategy - Dumping strategy. Must not be null
      Throws:
      IllegalArgumentException - if the strategy is missing
    • getStrategy

      Returns current dumping strategy.
      Returns:
      current dumping strategy
    • setReuseDumpFile

      void setReuseDumpFile(boolean use)
      If set to true, 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 to false, then every dump of the face to the disk overwrites the file.
      Parameters:
      use - If true, then this optimization is turned on.
    • loadFace

      String loadFace(File file)
      Loads new face. If the face is already loaded, then the ID of existing instance is returned. To access the human face instance, use getFace(String).
      Parameters:
      file - OBJ file with human face.
      Returns:
      ID of the human face or null
    • isLoaded

      boolean isLoaded(File faceFile)
      Checks whether the given face is loaded in the factory
      Parameters:
      faceFile - OBJ file with human face.
      Returns:
      true if the face exists in the factory, false otherwise.
    • addFace

      String addFace(HumanFace face)
      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

      HumanFace getFace(String faceId)
      Returns a human face. Recovers the face from the disk if necessary.
      Parameters:
      faceId - ID of the face
      Returns:
      Human face or null
    • removeFace

      boolean removeFace(String faceId)
      Removes the face from either memory or swap space. To re-initiate the face, use loadFace(java.io.File) again.
      Parameters:
      faceId - Face ID
      Returns:
      true if the face existed and was removed.