org.keridwen.core.data.storage.manager
Class DefaultDataStorage

java.lang.Object
  extended by org.keridwen.core.data.storage.manager.DefaultDataStorage
All Implemented Interfaces:
DataStorage, UniqueIdGenerator<DataPacketId>

public class DefaultDataStorage
extends Object
implements DataStorage, UniqueIdGenerator<DataPacketId>

This is the default implementation of the DataStorage.


Constructor Summary
DefaultDataStorage()
          Default constructor.
DefaultDataStorage(boolean isStoredInMemory)
          Constructor with data storage localization.
 
Method Summary
 boolean addDataPacketListener(DataPacketId packetId, DataPacketListener listener)
          Add a listener on a data packet with given Id
 boolean addDataStorageListener(DataStorageListener listener)
          Adds a listener on this data storage.
protected  void fireDataManagerEvent(DataStorageEvent event)
          fire an event to the Data manager listeners
 DataPacketId generateUniqueId(Object... parameters)
          ids generation Method.
 Set<DataPacketId> getDataListSafe(Class<?> objectClass)
          Gets the list of ids for the objects of the given type.
 Set<DataPacketId> getDataListUnsafe(Class<?> objectClass)
          Gets the list of ids for the objects of the given type.
<ObjectType extends Serializable>
ObjectType
getDataSafe(DataPacketId packetId)
          Gets the data object corresponding to the given unique id.
<ObjectType extends Serializable>
ObjectType
getDataSafe(String objectName)
          Gets the data object corresponding to the given name.
<ObjectType>
ObjectType
getDataUnsafe(DataPacketId packetId)
          Gets the unsafe data associated with the given unique id.
<ObjectType>
ObjectType
getDataUnsafe(String objectName)
          Gets the data object corresponding to the given name.
 boolean getLogPacketInformation()
           
 int getNbData()
          Get the total number of stored data (safe+unsafe).
 String getPacketInformation(DataPacketId packetId)
          Gets the information of the packet with the given id.
 Boolean isReadLocked(DataPacketId packetId)
          Checks if the data packet with the given id is read locked.
 Boolean isWriteLocked(DataPacketId packetId)
          Checks if the data packet with the given id is write locked.
 boolean removeDataPacketListener(DataPacketId packetId, DataPacketListener listener)
          remove a listener from a data packet with given Id
 boolean removeDataStorageListener(DataStorageListener listener)
          Removes a listener from this data storage.
 boolean setDataSafe(Serializable serializableObject, DataPacketId packetId)
          Sets the object with the given unique id in the data storage.
 DataPacketId setDataSafe(String name, Serializable serializableObject)
          Sets the given object as safe data.
<ObjectType>
DataPacketId
setDataUnsafe(String name, ObjectType object)
          Sets the given object as unsafe data.
 void setFileDataStorage()
          Set the data storage in files.
 void setLogPacketInformation(boolean logPacketInformations)
           
 void setLogPacketInformation(DataPacketId id, String log)
           
 void setMemoryDataStorage()
          Sets the data storage in memory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultDataStorage

public DefaultDataStorage()
Default constructor.


DefaultDataStorage

public DefaultDataStorage(boolean isStoredInMemory)
Constructor with data storage localization.

Parameters:
isStoredInMemory - true if the storage is performed in memory
Method Detail

getNbData

public final int getNbData()
Description copied from interface: DataStorage
Get the total number of stored data (safe+unsafe).

Specified by:
getNbData in interface DataStorage
Returns:
the total number of stored data

generateUniqueId

public final DataPacketId generateUniqueId(Object... parameters)
Description copied from interface: UniqueIdGenerator
ids generation Method.

Specified by:
generateUniqueId in interface UniqueIdGenerator<DataPacketId>
Parameters:
parameters - list of parameters
Returns:
a newly created unique id

setMemoryDataStorage

public final void setMemoryDataStorage()
Sets the data storage in memory.


setFileDataStorage

public final void setFileDataStorage()
Set the data storage in files.


setDataUnsafe

public final <ObjectType> DataPacketId setDataUnsafe(String name,
                                                     ObjectType object)
                                 throws DataIOException
Sets the given object as unsafe data.

Specified by:
setDataUnsafe in interface DataStorage
Type Parameters:
ObjectType - the type of the object to set
Parameters:
name - the name of the data to set
object - the object to set
Returns:
the unique data packet id
Throws:
DataIOException - in case of error while writing the data

setDataSafe

public final DataPacketId setDataSafe(String name,
                                      Serializable serializableObject)
                               throws DataIOException,
                                      DataConcurrencyException
Sets the given object as safe data.

Specified by:
setDataSafe in interface DataStorage
Type Parameters:
ObjectType - the type of the object to set
Parameters:
name - the name of the data to set
object - the object to set
Returns:
the unique data packet id
Throws:
DataIOException - in case of error while writing the data
DataConcurrencyException - in case of concurrent access to the data

getDataUnsafe

public final <ObjectType> ObjectType getDataUnsafe(DataPacketId packetId)
                               throws DataIOException
Gets the unsafe data associated with the given unique id.

Specified by:
getDataUnsafe in interface DataStorage
Parameters:
packetId - the id of the packet to fetch
Returns:
the object associated with the given id
Throws:
DataIOException - in case of error while reading the data

getDataSafe

public final <ObjectType extends Serializable> ObjectType getDataSafe(DataPacketId packetId)
                                                  throws DataIOException,
                                                         DataConcurrencyException
Description copied from interface: DataStorage
Gets the data object corresponding to the given unique id. This method is safe.

Specified by:
getDataSafe in interface DataStorage
Parameters:
packetId -
Returns:
Throws:
DataIOException
DataConcurrencyException - in case of concurrent access to the data

setDataSafe

public final boolean setDataSafe(Serializable serializableObject,
                                 DataPacketId packetId)
                          throws DataIOException,
                                 DataConcurrencyException
Description copied from interface: DataStorage
Sets the object with the given unique id in the data storage.

Specified by:
setDataSafe in interface DataStorage
Parameters:
serializableObject - the object to set
packetId - the unique id of the object to set
Returns:
true in case of success
Throws:
DataIOException - if the data writting failed
DataConcurrencyException - in case of concurrent access to the data
See Also:
org.keridwen.core.data.storage.manager.DataStorage#setDataSafe(org.keridwen.core.model.manager.DataAccessReader[], org.keridwen.core.data.storage.packet.DataPacketId)

addDataPacketListener

public final boolean addDataPacketListener(DataPacketId packetId,
                                           DataPacketListener listener)
Add a listener on a data packet with given Id

Specified by:
addDataPacketListener in interface DataStorage
Parameters:
packetId -

removeDataPacketListener

public final boolean removeDataPacketListener(DataPacketId packetId,
                                              DataPacketListener listener)
remove a listener from a data packet with given Id

Specified by:
removeDataPacketListener in interface DataStorage
Parameters:
packetId -

setLogPacketInformation

public final void setLogPacketInformation(DataPacketId id,
                                          String log)

getLogPacketInformation

public final boolean getLogPacketInformation()
Returns:
the logPacketInformations

setLogPacketInformation

public final void setLogPacketInformation(boolean logPacketInformations)
Parameters:
logPacketInformations - the logPacketInformations to set

getPacketInformation

public final String getPacketInformation(DataPacketId packetId)
Description copied from interface: DataStorage
Gets the information of the packet with the given id.

Specified by:
getPacketInformation in interface DataStorage
Parameters:
packetId - the id of the packet
Returns:
the string information regarding the data packet
See Also:
DataStorage.getPacketInformation(org.keridwen.core.data.storage.packet.DataPacketId)

isWriteLocked

public final Boolean isWriteLocked(DataPacketId packetId)
Description copied from interface: DataStorage
Checks if the data packet with the given id is write locked.

Specified by:
isWriteLocked in interface DataStorage
Parameters:
packetId - the id of the packet to check
Returns:
true if the packet is locked for writing. Returns null if no packet is found.
See Also:
DataStorage.isWriteLocked(org.keridwen.core.data.storage.packet.DataPacketId)

isReadLocked

public final Boolean isReadLocked(DataPacketId packetId)
Description copied from interface: DataStorage
Checks if the data packet with the given id is read locked.

Specified by:
isReadLocked in interface DataStorage
Parameters:
packetId - the id of the packet to check
Returns:
true if the packet is locked for reading. Returns null if no packet is found.
See Also:
DataStorage.isReadLocked(org.keridwen.core.data.storage.packet.DataPacketId)

getDataSafe

public final <ObjectType extends Serializable> ObjectType getDataSafe(String objectName)
                                                  throws DataIOException,
                                                         DataConcurrencyException
Description copied from interface: DataStorage
Gets the data object corresponding to the given name. This method is safe.

Specified by:
getDataSafe in interface DataStorage
Parameters:
objectName - the name of the object to retrieve
Returns:
the retrieved object
Throws:
DataIOException - in case data reading failed
DataConcurrencyException - in case of concurrent access to the data
See Also:
DataStorage.getDataSafe(java.lang.String)

getDataUnsafe

public final <ObjectType> ObjectType getDataUnsafe(String objectName)
                               throws DataIOException
Description copied from interface: DataStorage
Gets the data object corresponding to the given name. This method is not safe.

Specified by:
getDataUnsafe in interface DataStorage
Parameters:
objectName - the name of the object to retrieve
Returns:
the retrieved object
Throws:
DataIOException - in case data reading failed
See Also:
DataStorage.getDataUnsafe(java.lang.String)

getDataListSafe

public final Set<DataPacketId> getDataListSafe(Class<?> objectClass)
Description copied from interface: DataStorage
Gets the list of ids for the objects of the given type. This method is safe.

Specified by:
getDataListSafe in interface DataStorage
Parameters:
objectClass - the type of object to fetch
Returns:
the list of unique ids of the objects
See Also:
org.keridwen.core.data.storage.manager.DataStorage#getDataList(java.lang.Class)

getDataListUnsafe

public final Set<DataPacketId> getDataListUnsafe(Class<?> objectClass)
Description copied from interface: DataStorage
Gets the list of ids for the objects of the given type. This method is safe.

Specified by:
getDataListUnsafe in interface DataStorage
Parameters:
objectClass - the type of object to fetch
Returns:
the list of unique ids of the objects
See Also:
org.keridwen.core.data.storage.manager.DataStorage#getDataList(java.lang.Class)

addDataStorageListener

public final boolean addDataStorageListener(DataStorageListener listener)
Description copied from interface: DataStorage
Adds a listener on this data storage.

Specified by:
addDataStorageListener in interface DataStorage
Parameters:
listener - the listener to add

removeDataStorageListener

public final boolean removeDataStorageListener(DataStorageListener listener)
Description copied from interface: DataStorage
Removes a listener from this data storage.

Specified by:
removeDataStorageListener in interface DataStorage
Parameters:
listener - the listener to remove

fireDataManagerEvent

protected final void fireDataManagerEvent(DataStorageEvent event)
fire an event to the Data manager listeners



Copyright © 2010-2013 Artenum. All Rights Reserved.