|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectdsto.dfc.swing.persistence.PersistenceManager
public class PersistenceManager
A lightweight persistent object manager. Maintains a set of
persistent objects, loading, unloading and saving modified objects
as required. Each managed object is accessed via a logical key:
clients may register new persistent objects (registerObject(String, Object)
), lookup existing
objects (findObject(java.lang.String)
) and mark objects modified (objectModified(java.lang.String)
). Objects that fire StateChangeEvent
's
are automatically marked changed by the manager. The manager ensures modifed
objects are periodically saved and that unreferenced objects are unloaded in
response to memory demand using the Java weak reference system.
Field Summary | |
---|---|
protected dsto.dfc.swing.persistence.PersistenceManager.Housekeeper |
housekeeper
|
protected CountedSet |
modifiedObjects
|
protected HashMap |
objects
Maps object key to PersistentRef instance. |
protected ReferenceQueue |
refQueue
|
protected String |
storageDir
The default storage directory for objects. |
Constructor Summary | |
---|---|
PersistenceManager(String storageDir)
Creates a new PersistenceManager instance. |
Method Summary | |
---|---|
Object |
findObject(String key)
Lookup a previously registered persistent object. |
Object |
findObject(String key,
ISerializer serializer)
Lookup a previously registered persistent object. |
Object |
findObject(String key,
String dir)
Lookup a previously registered persistent object. |
Object |
findObject(String key,
String dir,
ISerializer serializer)
Lookup a previously registered persistent object. |
Object |
getModifyLock()
Get the object that is locked by the manager when modifying state. |
boolean |
isModified(String key)
|
String[] |
listObjects()
Retrieve the list of all available persistent objects. |
String[] |
listObjects(Selector selector)
Retrieve the list of all available persistent objects matching a given selector. |
String[] |
listObjects(String dir)
Retrieve the list of all available persistent objects. |
String[] |
listObjects(String dir,
Selector selector)
Retrieve the list of all available persistent objects matching a given selector. |
void |
objectAccessed(Object object)
Manually signal that a persistent object has been accessed. |
void |
objectModified(Object object)
Mark an object as modified. |
void |
objectModified(String key)
Mark an object as modified. |
String |
pathForKey(String key)
The default path used to store serialized data for a given key. |
String |
pathForKey(String dir,
String key)
The path used to store serialized data for a given key dir storage directory. |
void |
registerObject(String key,
Object object)
Register a new persistent object using the default Java serialization format. |
void |
registerObject(String key,
Object object,
ISerializer serializer)
Register a new persistent object. |
void |
registerObject(String key,
String dir,
Object object)
Register a new persistent object. |
void |
registerObject(String key,
String dir,
Object object,
ISerializer serializer)
Register a new persistent object. |
void |
saveModified()
Save all modified objects. |
void |
saveModified(boolean forceSaveAll)
Save modified objects. |
void |
shutdown()
Perform a controlled shutdown of the manager. |
protected void |
unlockStaleObjects()
Unlock any unmodified objects that have not been accessed for 30 seconds, freeing them for GC. |
void |
unregisterObject(String key)
Deprecated. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected String storageDir
protected HashMap objects
protected final CountedSet modifiedObjects
protected final ReferenceQueue refQueue
protected final dsto.dfc.swing.persistence.PersistenceManager.Housekeeper housekeeper
Constructor Detail |
---|
public PersistenceManager(String storageDir)
PersistenceManager
instance.
storageDir
- The base directory for persistent storage.
Serialized objects are saved here using filenames derived from
their logical keys.Method Detail |
---|
public Object getModifyLock()
Object
valuepublic String pathForKey(String key)
pathForKey(String, String)
public String pathForKey(String dir, String key)
dir
- The storage directory.key
- The key.
public void registerObject(String key, Object object) throws IllegalArgumentException
IllegalArgumentException
- if key is already in use.registerObject(String, Object, ISerializer)
public void registerObject(String key, String dir, Object object)
key
- The logical key for the object. This is used for
subsequent access (eg see (findObject(java.lang.String)
).dir
- The base directory for the saved object.object
- The object to be managed. Note, this object is not
automatically considered to be modified, and will not be serialized
until a call to objectModified() is made or the object fires a change
event.
IllegalArgumentException
- if key is already in use.registerObject(String,Object)
,
objectModified(String)
public void registerObject(String key, Object object, ISerializer serializer) throws IllegalArgumentException
key
- The logical key for the object. This is used for
subsequent access (eg see (findObject(java.lang.String)
).object
- The object to be managed. Note, this object is not
automatically considered to be modified, and will not be serialized
until a call to objectModified() is made or the object fires a change
event.serializer
- The serializer for the object.
IllegalArgumentException
- if key is already in use.registerObject(String,Object)
,
objectModified(String)
public void registerObject(String key, String dir, Object object, ISerializer serializer) throws IllegalArgumentException
key
- The logical key for the object. This is used for
subsequent access (eg see (findObject(java.lang.String)
).dir
- The base directory for the saved object.object
- The object to be managed. Note, this object is not
automatically considered to be modified, and will not be serialized
until a call to objectModified() is made or the object fires a change
event.serializer
- The serializer for the object.
IllegalArgumentException
- if key is already in use.registerObject(String,Object)
,
objectModified(String)
public Object findObject(String key) throws IOException
getModifyLock()
.
key
- The key for the object
IOException
- If an error occurred reading a previously
saved store.registerObject(String, Object, ISerializer)
public Object findObject(String key, ISerializer serializer) throws IOException
getModifyLock()
.
key
- The key for the objectserializer
- The serializer to use if the object needs to be loaded.
IOException
- If an error occurred reading a previously
saved store.registerObject(String,Object,ISerializer)
public Object findObject(String key, String dir) throws IOException
getModifyLock()
.
key
- The key for the object.dir
- The directory to look for the object.
IOException
- If an error occurred reading a previously
saved store.registerObject(String,Object,ISerializer)
public Object findObject(String key, String dir, ISerializer serializer) throws IOException
getModifyLock()
.
key
- The key for the objectdir
- The directory to look for the object.serializer
- The serializer to use if the object needs to be loaded.
IOException
- If an error occurred reading a previously
saved store.registerObject(String,Object,ISerializer)
public String[] listObjects()
listObjects(Selector)
public String[] listObjects(String dir)
dir
- The directory to search for saved objects.
listObjects(Selector)
public String[] listObjects(Selector selector)
selector
- A selector instance that is used to select object keys.
public String[] listObjects(String dir, Selector selector)
dir
- The directory to search for saved objects.selector
- A selector instance that is used to select object keys.
public void unregisterObject(String key)
public void objectModified(String key)
key
- The key for the object.objectModified(Object)
public void objectModified(Object object)
object
- The object.objectModified(String)
public void objectAccessed(Object object)
public boolean isModified(String key)
public void saveModified()
public void saveModified(boolean forceSaveAll)
forceSaveAll
- Force save of all modified objects. If not true,
only objects not recently modified (last 10 secs) or not saved for 2 mins
are saved.protected void unlockStaleObjects()
public void shutdown()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |