org.red5.server.persistence

## Class FilePersistence

- java.lang.Object
- - org.red5.server.persistence.RamPersistence
  - - org.red5.server.persistence.FilePersistence

All Implemented Interfaces:
  IPersistenceStore

    public class FilePersistence
    extends RamPersistence

Simple file-based persistence for objects. Lowers memory usage if used instead of RAM memory storage.

Author:
  The Red5 Project (red5@osflash.org), Joachim Bauch (jojo@struktur.de)

### Field Summary

### Fields inherited from class org.red5.server.persistence.RamPersistence

`objects, PERSISTENCE_NO_NAME, resources`

### Constructor Summary

Constructors
Constructor and Description
`FilePersistence(IScope scope)` Create file persistence object for given scope
`FilePersistence(org.springframework.core.io.support.ResourcePatternResolver resolver)` Create file persistence object from given resource pattern resolver

### Method Summary

Methods
`protected void` `checkRemoveEmptyDirectories(String base)` Remove empty dirs
`protected String` `getObjectPath(String id, String name)` Get object path for given id and name
`boolean` `load(IPersistable object)` 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.
`protected boolean` `saveObject(IPersistable object)` Save persistable object
`void` `setExtension(String extension)` Setter for extension.
`void` `setPath(String path)` Setter for file path.

### Methods inherited from class org.red5.server.persistence.RamPersistence

`getObjectId, getObjectName, getObjectNames, getObjects`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### FilePersistence

    public FilePersistence(org.springframework.core.io.support.ResourcePatternResolver resolver)

Create file persistence object from given resource pattern resolver

Parameters:
  `resolver` - Resource pattern resolver and loader

#### FilePersistence

    public FilePersistence(IScope scope)

Create file persistence object for given scope

Parameters:
  `scope` - Scope

### Method Detail

#### setPath

    public void setPath(String path)

Setter for file path.

Parameters:
  `path` - New path

#### setExtension

    public void setExtension(String extension)

Setter for extension.

Parameters:
  `extension` - New extension.

#### getObjectPath

    protected String getObjectPath(String id,
                       String name)

Get object path for given id and name

Overrides:
  `getObjectPath` in class `RamPersistence`
Parameters:
  `id` - Object ID. The format of the object id is <type>/<path>/<objectName>
  `name` - Object name
Returns:
  Resource path

#### 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`
Overrides:
  `load` in class `RamPersistence`
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 object)

Load state of an already instantiated persistent object.

Specified by:
  `load` in interface `IPersistenceStore`
Overrides:
  `load` in class `RamPersistence`
Parameters:
  `object` - the object to initializ
Returns:
  true if the object was initialized, false otherwise

#### saveObject

    protected boolean saveObject(IPersistable object)

Save persistable object

Parameters:
  `object` - Persistable object
Returns:
  `true` on success, `false` otherwise

#### save

    public boolean save(IPersistable object)

Persist given object.

Specified by:
  `save` in interface `IPersistenceStore`
Overrides:
  `save` in class `RamPersistence`
Parameters:
  `object` - Object to store
Returns:
  `true` on success, `false` otherwise

#### checkRemoveEmptyDirectories

    protected void checkRemoveEmptyDirectories(String base)

Remove empty dirs

Parameters:
  `base` - Base directory

#### remove

    public boolean remove(String name)

Delete the persistent object with the given name.

Specified by:
  `remove` in interface `IPersistenceStore`
Overrides:
  `remove` in class `RamPersistence`
Parameters:
  `name` - the name of the object to delete
Returns:
  `true` if object was persisted and thus can be removed, `false` otherwise

#### remove

    public boolean remove(IPersistable object)

Delete the passed persistent object.

Specified by:
  `remove` in interface `IPersistenceStore`
Overrides:
  `remove` in class `RamPersistence`
Parameters:
  `object` - the object to delete
Returns:
  `true` if object was persisted and thus can be removed, `false` otherwise

#### 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`
Overrides:
  `notifyClose` in class `RamPersistence`