|
DLESE Tools v1.2 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.dlese.dpc.datamgr.DataManager org.dlese.dpc.datamgr.SerializedDataManager
A Hashtable-like interface for reading and writing persistent Java objects from and to
disc. Objects are stored in serialized form on disc - any object that implements
Serializable
can be stored in this DataManager for persistent
retrieval. The objects can also be held in a RAM cache to provide faster retrieval.
Serialized objects are stored in a directory specified at the time of construction.
Objects stored in a SerializedDataManager can be of mixed type. This class is safe to
use with multiple process and/or JVMs that access the same dataPath concurrently.
Field Summary | |
---|---|
protected static Hashtable |
codes
Converts a string that contains escaped hex encoding of the form %HEX back to plain text.Provides the inverse operation of the method encodeFileName() |
protected String |
dataPath
The path to the data store |
protected static boolean |
debug
DESCRIPTION |
protected Hashtable |
locks
DESCRIPTION |
protected long |
nextLockKey
A unique id for locking purposes |
protected long |
num_records
DESCRIPTION |
protected Hashtable |
objectCache
DESCRIPTION |
protected boolean |
useCache
DESCRIPTION |
protected boolean |
useFileLocks
DESCRIPTION |
Constructor Summary | |
---|---|
SerializedDataManager()
Constructor for the SerializedDataManager object, restores a serialized SerializedDataManager. |
|
SerializedDataManager(String dataPath,
boolean useCache)
Constructs a new SerializedDataManager that reads and writes data to the given dataPath directory. |
Method Summary | |
---|---|
protected String |
decodeFileName(String name)
Decodes a String that was encoded using the method encodeFileName(String
name) . |
boolean |
delete(String oid)
Deletes an existing data object iff the object is not locked by another user. |
boolean |
delete(String oid,
String lockKey)
Deletes an existing data object, assuming the caller had requested and recieved the necessary lock. |
protected String |
encodeFileName(String name)
Encodes a String so that it is suitable for use as a file name by encoding all non letter or digit chars such as "/" and ":" into escaped hex values of the form _HEX. |
List |
get(List oids)
Retrieves a List of data objects. |
Object |
get(String oid)
Retrieves a single data object. |
List |
getCopy(List oids)
Retrieves a List of copied data objects, suitable for modifying. |
Object |
getCopy(String oid)
Retrieves a copy of a single data object, sutable for modifying. |
String[] |
getIDs()
Retrieves a String [] of all IDs that exist in this
SerializedDataManager. |
String[] |
getIDsSorted()
Retrieves a String [] of all IDs that exists in this
SerializedDataManager sorted lexagraphically. |
long |
getLastModifiedDate(String oid)
Returns the time that the object denoted by this oid was last modified. |
protected boolean |
getLock(String objectPath)
Gets an internal read/write lock for a given object in the this SerializedDataManager. |
protected String |
getNextLockKey()
Gets the nextLockKey attribute of the SerializedDataManager object |
protected int |
getNumFiles()
Return the number of files in this DataManager as reported by the file system. |
long |
getNumRecords()
Get the number of records in this SerializedDataManager. |
boolean |
isLocked(String oid)
Determine whether a given object is locked by another user. |
boolean |
isValidLock(String oid,
String lockKey)
Determine whether a given object is locked with the given key. |
String |
lock(String oid)
Get a user-requested lock for a data object, preventing it from being written by other threads that are using this SerializedDataManager. |
boolean |
oidExists(String oid)
Determines whether an object with the given oid exists in the DataManager. |
protected void |
prtln(String s)
Print a line to standard output. |
Object |
put(String oid,
Object obj)
Adds a new object of data. |
protected void |
releaseLock(String objectPath)
Release the read/write lock. |
Object |
remove(String oid)
Removes an existing data object iff the object is not locked by another user. |
Object |
remove(String oid,
String lockKey)
Removes an existing data object, assuming the caller had requested and recieved the necessary lock for the object. |
protected Object |
restoreSerializedObject(String oid,
boolean fromCache)
Restores a Serialized object from the given file path, pulling if from a RAM cache if caching indicated at construction time. |
protected void |
serailizeObject(String path,
Object obj)
Serializes an object to the given file path, placing it in a RAM cache if caching indicated at construction time. |
static void |
setDebug(boolean isDebugOutput)
Sets the debug attribute of the SerializedDataManager class |
boolean |
unlock(String oid,
String lockKey)
Remove the lock on a data object, if it exists. |
Object |
update(String oid,
Object obj)
Updates a new object of data iff the object is not locked by another user. |
Object |
update(String oid,
Object obj,
String lockKey)
Updates a new object of data, assuming the caller had requested and recieved the necessary lock. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected String dataPath
protected static boolean debug
protected Hashtable locks
protected Hashtable objectCache
protected long num_records
protected final boolean useFileLocks
protected boolean useCache
protected static Hashtable codes
protected long nextLockKey
Constructor Detail |
public SerializedDataManager(String dataPath, boolean useCache) throws Exception
get(String)
and get(List)
methods are not safe to modify. Specifically, any changes made
to the objects will be reflected in subsequent calls to those methods. To get a copy
of the data items that are safe to modify the caller should use the getCopy(String)
or getCopy(List)
methods instead. If caching is not turned
on, the effect of the get methods are the same as the getCopy methods.This class is safe to use with multiple process and/or JVMs that access the same dataPath.
dataPath
- The directory where the serialzed objects are stored.useCache
- Indicates whether to cache the objects in RAM memory for faster
retrievel.
Exception
- If error.public SerializedDataManager()
Method Detail |
public Object get(String oid) throws OIDDoesNotExistException
get(List)
method. To
get a copy of a data item that is safe to modify use the getCopy(String)
method instead. If caching is not enabled, the effect of this method is the same as
getCopy(String)
.
get
in class DataManager
oid
- The data identifier
Object
of data
OIDDoesNotExistException
- If no object exists for the given uid.getCopy(String)
public Object getCopy(String oid) throws OIDDoesNotExistException
oid
- The data identifier.
Object
of data that is
in this SerializedDataManager.
OIDDoesNotExistException
- If no object exists for the given uid.get(String)
public List get(List oids) throws OIDDoesNotExistException
List
of data objects. Note that if caching is turned on in
this SerializedDataManager, the objects that are returned are not safe to modify.
Specifically, if caching is enabled, any changes made to the objects will be
reflected in subsequent calls to this method and the get(String)
method. To
get a copy of a data items that are safe to modify use the getCopy(List)
method instead. If caching is not ebabled, the effect of this method is the same as
getCopy(List)
.
get
in class DataManager
oids
- List
of data identifiers
List
of corresponding data objects
OIDDoesNotExistException
- If no object exists for the given uid.getCopy(List)
public List getCopy(List oids) throws OIDDoesNotExistException
List
of copied data objects, suitable for modifying. The
objects that are returned are safe for modifying without affecting the data that is
in this SerializedDataManager.
oids
- List
of data identifiers.
List
of corresponding data objects
copies.
OIDDoesNotExistException
- If no object exists for the given uid.get(List)
public String[] getIDs()
String []
of all IDs that exist in this
SerializedDataManager. Results are not guaranteed to be in lexagraphical order,
however the order is guaranteed to be in the same order from one invocation to the
next.
String []
of the IDs in this SerializedDataManagerpublic String[] getIDsSorted()
String []
of all IDs that exists in this
SerializedDataManager sorted lexagraphically.
String []
of the IDs in this
SerializedDataManagerpublic long getNumRecords()
public Object put(String oid, Object obj) throws OIDAlreadyExistsException, ObjectNotSupportedException
put
in class DataManager
oid
- The unique identifier that references the new
data objectobj
- The new data object
OIDAlreadyExistsException
- If an object with given oid already exists in
the data store.
ObjectNotSupportedException
- If the object type is not suppored.protected boolean getLock(String objectPath)
releaseLock(String
objectPath)
, provide reliable locking method for use across multiple processes or
JVMs that may access the SDM data concurrently.
objectPath
- The absolute path to the data object being stored.
protected void releaseLock(String objectPath)
objectPath
- The absolute path to the data object being stored.public Object remove(String oid, String lockKey) throws OIDDoesNotExistException, InvalidLockException
remove
in class DataManager
oid
- The unique identifier that references the data
object to be removedlockKey
- The key corresponding to the lock on this data
object
OIDDoesNotExistException
- If no object exists for the given uid.
InvalidLockException
- If the lock provided for the object is not
valid.public Object remove(String oid) throws OIDDoesNotExistException, LockNotAvailableException
remove
in class DataManager
oid
- The unique identifier that references the data
object to be removed
OIDDoesNotExistException
- If no object exists for the given uid.
LockNotAvailableException
- If another user currently has a lock on this
object.public boolean delete(String oid, String lockKey) throws OIDDoesNotExistException, InvalidLockException
remove()
except no object is returned and
thus is more efficient if an object is not required.
delete
in class DataManager
oid
- The unique identifier that references the data
object to be deletedlockKey
- The key corresponding to the lock on this data
object
OIDDoesNotExistException
- If no object exists for the given uid.
InvalidLockException
- If the lock provided for the object is not
valid.public boolean delete(String oid) throws OIDDoesNotExistException, LockNotAvailableException
remove()
except no object is returned and thus is more efficient. After successful completion
the object is deleted from the DataManager.
delete
in class DataManager
oid
- The unique identifier that references the data
object to be deleted
OIDDoesNotExistException
- If no object exists for the given uid.
LockNotAvailableException
- If another user currently has a lock on this
object.public Object update(String oid, Object obj, String lockKey) throws OIDDoesNotExistException, ObjectNotSupportedException, InvalidLockException
update
in class DataManager
oid
- The unique identifier that references the
data object to be updatedobj
- The new updated data objectlockKey
- The key corresponding to the lock on this
data object
OIDDoesNotExistException
- If no object exists for the given uid.
ObjectNotSupportedException
- If the object type is not suppored.
InvalidLockException
- If the lock provided for the object is not
valid.public Object update(String oid, Object obj) throws OIDDoesNotExistException, ObjectNotSupportedException, LockNotAvailableException
update
in class DataManager
oid
- The unique identifier that references the
data object to be updatedobj
- The new updated data object
OIDDoesNotExistException
- If no object exists for the given uid.
ObjectNotSupportedException
- If the object type is not suppored.
LockNotAvailableException
- If another user currently has a lock on this
object.public String lock(String oid) throws OIDDoesNotExistException, LockNotAvailableException
lock
in class DataManager
oid
- The unique identifier that references the data
object to be locked
OIDDoesNotExistException
- If no object exists for the given uid.
LockNotAvailableException
- If another user currently has a lock on this
object.public long getLastModifiedDate(String oid) throws OIDDoesNotExistException
oid
- The unique identifier that references the data
object
OIDDoesNotExistException
- If no object exists for the given uid.public boolean oidExists(String oid)
oidExists
in class DataManager
oid
- The unique identifier that references the data object
public boolean isLocked(String oid)
isLocked
in class DataManager
oid
- The unique identifier that references the data object
public boolean isValidLock(String oid, String lockKey)
isValidLock
in class DataManager
oid
- The unique identifier that references the data objectlockKey
- The lock key
public boolean unlock(String oid, String lockKey) throws OIDDoesNotExistException, InvalidLockException
unlock
in class DataManager
oid
- The unique identifier that references the locked
data objectlockKey
- The key corresponding to the lock on this data
object
OIDDoesNotExistException
- If no object exists for the given uid.
InvalidLockException
- If the lock provided for the object is not
valid.protected void serailizeObject(String path, Object obj) throws IOException, InvalidClassException, NotSerializableException
path
- DESCRIPTIONobj
- DESCRIPTION
IOException
- DESCRIPTION
InvalidClassException
- DESCRIPTION
NotSerializableException
- DESCRIPTIONprotected Object restoreSerializedObject(String oid, boolean fromCache) throws IOException, ClassNotFoundException
oid
- DESCRIPTIONfromCache
- DESCRIPTION
IOException
- DESCRIPTION
ClassNotFoundException
- DESCRIPTIONprotected String encodeFileName(String name)
name
- The String to encode.
protected String decodeFileName(String name)
encodeFileName(String
name)
.
name
- The string to decods.
protected int getNumFiles()
protected String getNextLockKey()
public static void setDebug(boolean isDebugOutput)
isDebugOutput
- The new debug valueprotected void prtln(String s)
s
- DESCRIPTION
|
DLESE Tools v1.2 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |