Class RamPersistence

java.lang.Object
org.red5.server.persistence.RamPersistence
All Implemented Interfaces:
IPersistenceStore

public class RamPersistence extends Object implements IPersistenceStore
Persistence implementation that stores the objects in memory. This serves as default persistence if nothing has been configured.
Author:
The Red5 Project, Joachim Bauch (jojo@struktur.de), Michael Klishin (michael@novemberain.com)
  • Field Details

    • PERSISTENCE_NO_NAME

      protected static final String PERSISTENCE_NO_NAME
      This is used in the id for objects that have a name of
       null
       
      See Also:
    • objects

      protected ConcurrentMap<String,IPersistable> objects
      Map for persistable objects
    • resources

      protected org.springframework.core.io.support.ResourcePatternResolver resources
      Resource pattern resolver. Resolves resources from patterns, loads resources.
  • Constructor Details

    • RamPersistence

      public RamPersistence(org.springframework.core.io.support.ResourcePatternResolver resources)
      Creates RAM persistence object from resource pattern resolvers
      Parameters:
      resources - Resource pattern resolver and loader
    • RamPersistence

      public RamPersistence(IScope scope)
      Creates RAM persistence object from scope
      Parameters:
      scope - Scope
  • Method Details

    • getObjectName

      protected String getObjectName(String id)
      Get resource name from path. The format of the object id is
       type / path / objectName
       
      Parameters:
      id - object id
      Returns:
      resource name
    • getObjectPath

      protected String getObjectPath(String id, String name)
      Get object path for given id and name. The format of the object id is
       type / path / objectName
       
      Parameters:
      id - object id
      name - object name
      Returns:
      resource path
    • getObjectId

      protected String getObjectId(IPersistable object)
      Get object id
      Parameters:
      object - Persistable object whose id is asked for
      Returns:
      Given persistable object id
    • save

      public boolean save(IPersistable object)
      Persist given object.
      Specified by:
      save in interface IPersistenceStore
      Parameters:
      object - Object to store
      Returns:
       true
       
      on success,
       false
       
      otherwise
    • load

      public IPersistable load(String name)
      Load a persistent object with the given name. The object must provide either a constructor that takes an input stream as only parameter or an empty constructor so it can be loaded from the persistence store.
      Specified by:
      load in interface IPersistenceStore
      Parameters:
      name - the name of the object to load
      Returns:
      The loaded object or
       null
       
      if no such object was found
    • load

      public boolean load(IPersistable obj)
      Load state of an already instantiated persistent object.
      Specified by:
      load in interface IPersistenceStore
      Parameters:
      obj - the object to initializ
      Returns:
      true if the object was initialized, false otherwise
    • remove

      public boolean remove(IPersistable object)
      Delete the passed persistent object.
      Specified by:
      remove in interface IPersistenceStore
      Parameters:
      object - the object to delete
      Returns:
       true
       
      if object was persisted and thus can be removed,
       false
       
      otherwise
    • remove

      public boolean remove(String name)
      Delete the persistent object with the given name.
      Specified by:
      remove in interface IPersistenceStore
      Parameters:
      name - the name of the object to delete
      Returns:
       true
       
      if object was persisted and thus can be removed,
       false
       
      otherwise
    • getObjectNames

      public Set<String> getObjectNames()
      Return iterator over the names of all already loaded objects in the storage.
      Specified by:
      getObjectNames in interface IPersistenceStore
      Returns:
      Set of all object names
    • getObjects

      public Collection<IPersistable> getObjects()
      Return iterator over the already loaded objects in the storage.
      Specified by:
      getObjects in interface IPersistenceStore
      Returns:
      Set of all objects
    • notifyClose

      public void notifyClose()
      Notify store that it's being closed. This allows the store to write any pending objects to disk.
      Specified by:
      notifyClose in interface IPersistenceStore