public class PersistentContext extends Context
This class represents a context persistent accross multiple program
executions. It is typically used to hold
persistent references.
How this context is loaded/saved is application specific.
Although, the simplest way is to use Javolution XML serialization
facility. For example:
import javolution.xml.XMLObjectReader;
import javolution.xml.XMLObjectWriter;
public void main(String[]) {
// Loads persistent context (typically at start-up).
XMLObjectReader reader = XMLObjectReader.newInstance(new FileInputStream("C:/persistent.xml"));
PersistentContext.setCurrentPersistentContext(reader.read());
reader.close();
...
...
// Saves persistent context for future execution.
XMLObjectWriter writer = XMLObjectWriter.newInstance(new FileOutputStream("C:/persistent.xml"));
writer.write(PersistentContext.getCurrentPersistentContext());
writer.close();
}
| Modifier and Type | Class and Description |
|---|---|
static class |
PersistentContext.Reference<T>
This class represents a reference over an object which can be kept
persistent accross multiple program executions.
|
| Constructor and Description |
|---|
PersistentContext()
Default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
enterAction()
Throws
UnsupportedOperationException persistent context
are global to all threads (singleton). |
protected void |
exitAction()
Throws
UnsupportedOperationException persistent context
are global to all threads (singleton). |
static PersistentContext |
getCurrentPersistentContext()
Returns the persistent context instance (singleton).
|
java.util.Map<java.lang.String,java.lang.Object> |
getIdToValue()
Returns the ID to value mapping for this persistent context.
|
static void |
setCurrentPersistentContext(PersistentContext ctx)
Sets the persistent instance.
|
enter, enter, exit, exit, getCurrentContext, getOuter, getOwner, setConcurrentContext, toStringpublic static void setCurrentPersistentContext(PersistentContext ctx)
ctx - the persistent instance.public static PersistentContext getCurrentPersistentContext()
public java.util.Map<java.lang.String,java.lang.Object> getIdToValue()
protected void enterAction()
UnsupportedOperationException persistent context
are global to all threads (singleton).enterAction in class Contextprotected void exitAction()
UnsupportedOperationException persistent context
are global to all threads (singleton).exitAction in class ContextCopyright © 2005 - 2007 Javolution.