public class Store
extends java.lang.Object
implements java.io.Closeable
setRoot(java.io.File)
method.Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
clazz |
protected java.lang.ClassLoader |
clazzLoader |
protected static java.lang.ClassLoader |
defaultClazzLoader |
protected static java.util.Map<java.lang.String,Store> |
instances |
protected java.io.File |
root |
protected static java.io.File |
storeRoot |
Modifier | Constructor and Description |
---|---|
protected |
Store(java.lang.String clazz) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the store.
|
protected static void |
closeQuietly(java.io.InputStream is)
Closes input stream quietly.
|
protected static void |
closeQuietly(java.io.OutputStream os)
Closes output stream quietly.
|
boolean |
delete()
Deletes the data store.
|
<T> T |
getById(java.lang.Class<T> type,
java.lang.String id)
Gets an object in the store.
|
<T> java.util.List<T> |
getByType(java.lang.Class<T> type)
Gets all objects of a given class in the store.
|
protected java.lang.String |
getId(java.io.Serializable obj)
Gets the ID for an object.
|
static Store |
getInstance(Agent agent)
Gets a store instance for an agent.
|
protected <T> T |
load(java.lang.Class<T> type,
java.io.File f)
Loads a stored object from a file.
|
void |
put(java.io.Serializable obj)
Stores an object.
|
boolean |
remove(java.io.Serializable obj)
Removes an object from the store.
|
<T> boolean |
removeById(java.lang.Class<T> type,
java.lang.String id)
Removes an object from the store.
|
<T> boolean |
removeByType(java.lang.Class<T> type)
Removes all objects of a given type from the store.
|
static void |
setClassLoader(java.lang.ClassLoader cl)
Sets class loader to use for loading stored classes.
|
static void |
setRoot(java.io.File folder)
Sets root folder for store data.
|
long |
size()
Gets the size of the data store (in bytes).
|
protected static java.io.File storeRoot
protected static java.lang.ClassLoader defaultClazzLoader
protected static java.util.Map<java.lang.String,Store> instances
protected java.io.File root
protected java.lang.String clazz
protected java.lang.ClassLoader clazzLoader
public static void setRoot(java.io.File folder)
public static void setClassLoader(java.lang.ClassLoader cl)
cl
- class loader to use, or null to use defaultprotected java.lang.String getId(java.io.Serializable obj)
public void put(java.io.Serializable obj)
protected <T> T load(java.lang.Class<T> type, java.io.File f)
public <T> T getById(java.lang.Class<T> type, java.lang.String id)
type
- object classid
- object IDpublic <T> java.util.List<T> getByType(java.lang.Class<T> type)
type
- object classpublic boolean remove(java.io.Serializable obj)
obj
- object to removepublic <T> boolean removeById(java.lang.Class<T> type, java.lang.String id)
type
- object classid
- object ID to removepublic <T> boolean removeByType(java.lang.Class<T> type)
type
- objet classpublic boolean delete()
public long size()
public void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
protected static void closeQuietly(java.io.InputStream is)
protected static void closeQuietly(java.io.OutputStream os)