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
    • loadFace

      Long loadFace(Long id, 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
      invalid reference
      #getFace(String)
      .
      Parameters:
      file - OBJ file with human face.
      Returns:
      ID of the human face or null
    • isLoaded

      boolean isLoaded(Long faceId)
      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

      Long 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(Long 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(Long faceId)
      Removes the face from either memory or swap space. To re-initiate the face, use loadFace(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