|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object dsto.dfc.util.Scheduler.Task dsto.dfc.databeans.io.DataObjectPersister2
public class DataObjectPersister2
A task that saves a data object at periodic intervals when it has
been modified. This mostly replaces the original
DataObjectPersister
class, which is only really useful if
you want to use java.util.Timer.
NOTE: This task differs from the original
DataObjectPersister
in that it uses the DFC
Scheduler
's ability to re-schedule and thus
avoids being in the task queue unless a change actually needs to be
saved. This allows the persister to be automatically GC'd with the
target object, or shut down cleanly when the scheduler is, removing
the need to explictly dispose () this object.
Nested Class Summary | |
---|---|
protected class |
DataObjectPersister2.CleanupTask
Cleans up old backups according to the following rules Preserve a trail of backups, daily backups for 1 week weekly backups of 1 month and monthly backups for 1 year. |
Field Summary | |
---|---|
protected boolean |
backup
|
protected static int |
BACKUP_DAILY
|
protected static int |
BACKUP_MONTHLY
|
static String |
BACKUP_REGEX
|
protected static int |
BACKUP_WEEKLY
|
protected File |
file
|
protected long |
firstUnsavedChange
|
boolean |
forceSaveOnExit
Set to true to force the persister to save on exit (dispose ()) rather than rely on the modified flag. |
protected long |
lastBackedUp
|
protected long |
maxBackupInterval
|
protected long |
maxSaveInterval
|
protected boolean |
modified
|
protected IDataObject |
object
|
protected long |
saveInterval
|
protected Scheduler |
scheduler
|
protected XmlOutput |
xmlOutput
|
Fields inherited from class dsto.dfc.util.Scheduler.Task |
---|
runAt |
Constructor Summary | |
---|---|
DataObjectPersister2(Scheduler scheduler,
IDataObject object,
File file)
|
|
DataObjectPersister2(Scheduler scheduler,
IDataObject object,
File file,
boolean backup)
|
|
DataObjectPersister2(Scheduler scheduler,
IDataObject object,
File file,
long saveInterval,
long maxSaveInterval,
long maxBackupInterval,
boolean backup)
|
|
DataObjectPersister2(Scheduler scheduler,
IDataObject object,
String filename)
|
Method Summary | |
---|---|
void |
dispose()
Called when the task is in the scheduling queue (but not currently running) and the scheduler is being shut down. |
protected String |
getBackupFilename(File f)
|
protected String |
getBackupFileRegex(File f)
|
protected File[] |
getBackups()
Returns an array of back up files for the persistance file sorted by last modified in desceding order, ie the most recent backup file is at index 0; |
int |
getMaxSaveInterval()
|
int |
getSaveInterval()
|
XmlOutput |
getXmlOutput()
|
void |
propertyValueChanged(PropertyEvent e)
|
void |
run()
|
void |
setMaxSaveInterval(int maxSaveInterval)
Set the maximum the persister will allow a modified object to remain unsaved. |
void |
setModified(boolean value)
|
void |
setSaveInterval(int saveInterval)
Set the interval that must pass without modifications before a modified object is saved. |
Methods inherited from class dsto.dfc.util.Scheduler.Task |
---|
scheduled |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String BACKUP_REGEX
protected static final int BACKUP_DAILY
protected static final int BACKUP_WEEKLY
protected static final int BACKUP_MONTHLY
public boolean forceSaveOnExit
protected Scheduler scheduler
protected IDataObject object
protected File file
protected XmlOutput xmlOutput
protected boolean modified
protected long firstUnsavedChange
protected long lastBackedUp
protected long saveInterval
protected long maxSaveInterval
protected long maxBackupInterval
protected boolean backup
Constructor Detail |
---|
public DataObjectPersister2(Scheduler scheduler, IDataObject object, String filename)
public DataObjectPersister2(Scheduler scheduler, IDataObject object, File file)
public DataObjectPersister2(Scheduler scheduler, IDataObject object, File file, boolean backup)
public DataObjectPersister2(Scheduler scheduler, IDataObject object, File file, long saveInterval, long maxSaveInterval, long maxBackupInterval, boolean backup)
Method Detail |
---|
public void dispose()
Scheduler.Task
The default implementation calls run () if the task is scheduled to be run now, does nothing if not. Subclasses may override as needed.
dispose
in class Scheduler.Task
public XmlOutput getXmlOutput()
public int getMaxSaveInterval()
public void setMaxSaveInterval(int maxSaveInterval)
maxSaveInterval
- interval in seconds.public int getSaveInterval()
public void setSaveInterval(int saveInterval)
saveInterval
- The interval in seconds.public void run()
run
in interface Runnable
run
in class Scheduler.Task
public void setModified(boolean value)
public void propertyValueChanged(PropertyEvent e)
propertyValueChanged
in interface PropertyListener
protected String getBackupFilename(File f)
protected File[] getBackups()
protected String getBackupFileRegex(File f)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |