org.red5.server.persistence
Class RamPersistence

java.lang.Object
  extended by org.red5.server.persistence.RamPersistence
All Implemented Interfaces:
IPersistenceStore
Direct Known Subclasses:
FilePersistence

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 ([email protected]), Joachim Bauch ([email protected]), Michael Klishin ([email protected])

Field Summary
protected  ConcurrentMap<String,IPersistable> objects
          Map for persistable objects
protected static String PERSISTENCE_NO_NAME
          This is used in the id for objects that have a name of null
protected  ResourcePatternResolver resources
          Resource pattern resolver.
 
Constructor Summary
RamPersistence(IScope scope)
          Creates RAM persistence object from scope
RamPersistence(ResourcePatternResolver resources)
          Creates RAM persistence object from resource pattern resolvers
 
Method Summary
protected  String getObjectId(IPersistable object)
          Get object id
protected  String getObjectName(String id)
          Get resource name from path
 Set<String> getObjectNames()
          Return iterator over the names of all already loaded objects in the storage.
protected  String getObjectPath(String id, String name)
          Get object path for given id and name
 Collection<IPersistable> getObjects()
          Return iterator over the already loaded objects in the storage.
 boolean load(IPersistable obj)
          Load state of an already instantiated persistent object.
 IPersistable load(String name)
          Load a persistent object with the given name.
 void notifyClose()
          Notify store that it's being closed.
 boolean remove(IPersistable object)
          Delete the passed persistent object.
 boolean remove(String name)
          Delete the persistent object with the given name.
 boolean save(IPersistable object)
          Persist given object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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:
Constant Field Values

objects

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


resources

protected ResourcePatternResolver resources
Resource pattern resolver. Resolves resources from patterns, loads resources.

Constructor Detail

RamPersistence

public RamPersistence(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 Detail

getObjectName

protected String getObjectName(String id)
Get resource name from path

Parameters:
id - Object ID. The format of the object id is //.
Returns:
Resource name

getObjectPath

protected String getObjectPath(String id,
                               String name)
Get object path for given id and name

Parameters:
id - Object ID. The format of the object id is //
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


Copyright © 2006-2012 The Red5 Project