public class SerializedDataManager extends DataManager implements java.io.Serializable
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.Modifier and Type | Field and Description |
---|---|
protected static java.util.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 java.lang.String |
dataPath
The path to the data store
|
protected static boolean |
debug
DESCRIPTION
|
protected java.util.Hashtable |
locks
DESCRIPTION
|
protected long |
nextLockKey
A unique id for locking purposes
|
protected long |
num_records
DESCRIPTION
|
protected java.util.Hashtable |
objectCache
DESCRIPTION
|
protected boolean |
useCache
DESCRIPTION
|
protected boolean |
useFileLocks
DESCRIPTION
|
Constructor and Description |
---|
SerializedDataManager()
Constructor for the SerializedDataManager object, restores a serialized SerializedDataManager.
|
SerializedDataManager(java.lang.String dataPath,
boolean useCache)
Constructs a new SerializedDataManager that reads and writes data to the given
dataPath directory.
|
Modifier and Type | Method and Description |
---|---|
protected java.lang.String |
decodeFileName(java.lang.String name)
Decodes a String that was encoded using the method
encodeFileName(String
name) . |
boolean |
delete(java.lang.String oid)
Deletes an existing data object iff the object is not locked by another user.
|
boolean |
delete(java.lang.String oid,
java.lang.String lockKey)
Deletes an existing data object, assuming the caller had requested and recieved the
necessary lock.
|
protected java.lang.String |
encodeFileName(java.lang.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.
|
java.util.List |
get(java.util.List oids)
Retrieves a
List of data objects. |
java.lang.Object |
get(java.lang.String oid)
Retrieves a single data object.
|
java.util.List |
getCopy(java.util.List oids)
Retrieves a
List of copied data objects, suitable for modifying. |
java.lang.Object |
getCopy(java.lang.String oid)
Retrieves a copy of a single data object, sutable for modifying.
|
java.lang.String[] |
getIDs()
Retrieves a
String [] of all IDs that exist in this
SerializedDataManager. |
java.lang.String[] |
getIDsSorted()
Retrieves a
String [] of all IDs that exists in this
SerializedDataManager sorted lexagraphically. |
long |
getLastModifiedDate(java.lang.String oid)
Returns the time that the object denoted by this oid was last modified.
|
protected boolean |
getLock(java.lang.String objectPath)
Gets an internal read/write lock for a given object in the this
SerializedDataManager.
|
protected java.lang.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(java.lang.String oid)
Determine whether a given object is locked by another user.
|
boolean |
isValidLock(java.lang.String oid,
java.lang.String lockKey)
Determine whether a given object is locked with the given key.
|
java.lang.String |
lock(java.lang.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(java.lang.String oid)
Determines whether an object with the given oid exists in the DataManager.
|
protected void |
prtln(java.lang.String s)
Print a line to standard output.
|
java.lang.Object |
put(java.lang.String oid,
java.lang.Object obj)
Adds a new object of data.
|
protected void |
releaseLock(java.lang.String objectPath)
Release the read/write lock.
|
java.lang.Object |
remove(java.lang.String oid)
Removes an existing data object iff the object is not locked by another user.
|
java.lang.Object |
remove(java.lang.String oid,
java.lang.String lockKey)
Removes an existing data object, assuming the caller had requested and recieved the
necessary lock for the object.
|
protected java.lang.Object |
restoreSerializedObject(java.lang.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(java.lang.String path,
java.lang.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(java.lang.String oid,
java.lang.String lockKey)
Remove the lock on a data object, if it exists.
|
java.lang.Object |
update(java.lang.String oid,
java.lang.Object obj)
Updates a new object of data iff the object is not locked by another user.
|
java.lang.Object |
update(java.lang.String oid,
java.lang.Object obj,
java.lang.String lockKey)
Updates a new object of data, assuming the caller had requested and recieved the
necessary lock.
|
protected java.lang.String dataPath
protected static boolean debug
protected java.util.Hashtable locks
protected java.util.Hashtable objectCache
protected long num_records
protected final boolean useFileLocks
protected boolean useCache
protected static java.util.Hashtable codes
protected long nextLockKey
public SerializedDataManager(java.lang.String dataPath, boolean useCache) throws java.lang.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.java.lang.Exception
- If error.public SerializedDataManager()
public java.lang.Object get(java.lang.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 identifierObject
of dataOIDDoesNotExistException
- If no object exists for the given uid.getCopy(String)
public java.lang.Object getCopy(java.lang.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 java.util.List get(java.util.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 identifiersList
of corresponding data objectsOIDDoesNotExistException
- If no object exists for the given uid.getCopy(List)
public java.util.List getCopy(java.util.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 java.lang.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 java.lang.String[] getIDsSorted()
String []
of all IDs that exists in this
SerializedDataManager sorted lexagraphically.String []
of the IDs in this
SerializedDataManagerpublic long getNumRecords()
public java.lang.Object put(java.lang.String oid, java.lang.Object obj) throws OIDAlreadyExistsException, ObjectNotSupportedException
put
in class DataManager
oid
- The unique identifier that references the new
data objectobj
- The new data objectOIDAlreadyExistsException
- If an object with given oid already exists in
the data store.ObjectNotSupportedException
- If the object type is not suppored.protected boolean getLock(java.lang.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(java.lang.String objectPath)
objectPath
- The absolute path to the data object being stored.public java.lang.Object remove(java.lang.String oid, java.lang.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
objectOIDDoesNotExistException
- If no object exists for the given uid.InvalidLockException
- If the lock provided for the object is not
valid.public java.lang.Object remove(java.lang.String oid) throws OIDDoesNotExistException, LockNotAvailableException
remove
in class DataManager
oid
- The unique identifier that references the data
object to be removedOIDDoesNotExistException
- If no object exists for the given uid.LockNotAvailableException
- If another user currently has a lock on this
object.public boolean delete(java.lang.String oid, java.lang.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
objectOIDDoesNotExistException
- If no object exists for the given uid.InvalidLockException
- If the lock provided for the object is not
valid.public boolean delete(java.lang.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 deletedOIDDoesNotExistException
- If no object exists for the given uid.LockNotAvailableException
- If another user currently has a lock on this
object.public java.lang.Object update(java.lang.String oid, java.lang.Object obj, java.lang.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 objectOIDDoesNotExistException
- 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 java.lang.Object update(java.lang.String oid, java.lang.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 objectOIDDoesNotExistException
- 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 java.lang.String lock(java.lang.String oid) throws OIDDoesNotExistException, LockNotAvailableException
lock
in class DataManager
oid
- The unique identifier that references the data
object to be lockedOIDDoesNotExistException
- If no object exists for the given uid.LockNotAvailableException
- If another user currently has a lock on this
object.public long getLastModifiedDate(java.lang.String oid) throws OIDDoesNotExistException
oid
- The unique identifier that references the data
objectOIDDoesNotExistException
- If no object exists for the given uid.public boolean oidExists(java.lang.String oid)
oidExists
in class DataManager
oid
- The unique identifier that references the data objectpublic boolean isLocked(java.lang.String oid)
isLocked
in class DataManager
oid
- The unique identifier that references the data objectpublic boolean isValidLock(java.lang.String oid, java.lang.String lockKey)
isValidLock
in class DataManager
oid
- The unique identifier that references the data objectlockKey
- The lock keypublic boolean unlock(java.lang.String oid, java.lang.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
objectOIDDoesNotExistException
- If no object exists for the given uid.InvalidLockException
- If the lock provided for the object is not
valid.protected void serailizeObject(java.lang.String path, java.lang.Object obj) throws java.io.IOException, java.io.InvalidClassException, java.io.NotSerializableException
path
- DESCRIPTIONobj
- DESCRIPTIONjava.io.IOException
- DESCRIPTIONjava.io.InvalidClassException
- DESCRIPTIONjava.io.NotSerializableException
- DESCRIPTIONprotected java.lang.Object restoreSerializedObject(java.lang.String oid, boolean fromCache) throws java.io.IOException, java.lang.ClassNotFoundException
oid
- DESCRIPTIONfromCache
- DESCRIPTIONjava.io.IOException
- DESCRIPTIONjava.lang.ClassNotFoundException
- DESCRIPTIONprotected java.lang.String encodeFileName(java.lang.String name)
name
- The String to encode.protected java.lang.String decodeFileName(java.lang.String name)
encodeFileName(String
name)
.name
- The string to decods.protected int getNumFiles()
protected java.lang.String getNextLockKey()
public static void setDebug(boolean isDebugOutput)
isDebugOutput
- The new debug valueprotected void prtln(java.lang.String s)
s
- DESCRIPTION