SMILA (incubation) API documentation

org.eclipse.smila.objectstore.filesystem
Class SimpleObjectStoreService

java.lang.Object
  extended by org.eclipse.smila.objectstore.filesystem.SimpleObjectStoreService
All Implemented Interfaces:
ObjectStoreService

public class SimpleObjectStoreService
extends java.lang.Object
implements ObjectStoreService

A file system based implementation of ObjectStoreService.

The following rules apply to this store implementation:


Field Summary
static java.lang.String BUNDLE_ID
          The Constant BUNDLE_ID.
static java.lang.String PROPERTY_FILE_LOCKING
          property for file locking requested.
static java.lang.String PROPERTY_ROOT_PATH
          property for root of object store.
static java.lang.String VALID_STORENAME_EXPRESSION
          the regular expression to determine whether store names are valid.
 
Fields inherited from interface org.eclipse.smila.objectstore.ObjectStoreService
KEY_OBJECT_COUNT, KEY_OBJECTS, KEY_SIZE, KEY_STORE_NAME, KEY_STORE_PROPERTIES
 
Constructor Summary
SimpleObjectStoreService()
           
 
Method Summary
protected  void activate(ComponentContext context)
          Cleans the temporary stores that were open when the system went down.
 void appendToObject(java.lang.String storeName, java.lang.String objectId, byte[] data)
          append the data to the given store and object.
 void clearStore(java.lang.String storeName)
          Remove all objects from the named store.
 void createStore(java.lang.String storeName, AnyMap storeProperties)
          Creates a store with the given configuration properties.
 void ensureStore(java.lang.String storeName)
          Ensures that a store with the given name existing, regardless of the exact configuration properties.
 boolean existsObject(java.lang.String storeName, java.lang.String objectId)
          
 boolean existsStore(java.lang.String storeName)
          
 void finishObject(java.lang.String storeName, java.lang.String objectId)
          Prevent further append calls to this object.
 byte[] getObject(java.lang.String storeName, java.lang.String objectId)
          get the complete content of an object.
 StoreObject getObjectInfo(java.lang.String storeName, java.lang.String objectId)
          get information about a single object.
 AnyMap getStoreInfo(java.lang.String storeName, boolean includeObjectInfos)
          get a description of the current store state to be displayed in administration tools (e.g.
 java.util.Collection<java.lang.String> getStoreNames()
          
 java.util.Collection<StoreObject> getStoreObjectInfos(java.lang.String storeName)
          Get information about all current objects in the named store.
 java.util.Collection<StoreObject> getStoreObjectInfos(java.lang.String storeName, java.lang.String objectIdPrefix)
          Get information about all current objects in the named store that have an ID that starts with the given prefix.
 AnyMap getStoreProperties(java.lang.String storeName)
          get configuration properties of the named store.
 boolean isFileLockingRequested()
           
 boolean isValidStoreName(java.lang.String storeName)
          Check if the argument is a valid store name for this service implementation.
 void putObject(java.lang.String storeName, java.lang.String objectId, byte[] data)
          write the data to the given store and object.
 java.io.InputStream readObject(java.lang.String storeName, java.lang.String objectId)
          get a stream for reading the object content.
 void removeAllStores()
          remove all stores from the service.
 void removeObject(java.lang.String storeName, java.lang.String objectId)
          remove the object from the store.No exception is thrown if the object does not exist in the store currently (however, there is one if the store itself does not exist).
 void removeStore(java.lang.String storeName)
          remove a store completely, if it exists.
protected  void setFileLockingRequested(boolean fileLocking)
          Sets whether file locking is requested.
protected  void validateStore(java.lang.String storeName)
          Validates that the store name is valid and a store with the given name exists, throws an exception if it does not exist.
protected  void validateStoreName(java.lang.String storeName)
          Validates that the storeName is a valid one, throws an exception if it does not exist.
 StoreOutputStream writeObject(java.lang.String storeName, java.lang.String objectId)
          open a stream for creating a data object and writing it.
protected  void writeToObject(java.lang.String storeName, java.lang.String objectId, byte[] data)
          Puts data to an object in the store.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VALID_STORENAME_EXPRESSION

public static final java.lang.String VALID_STORENAME_EXPRESSION
the regular expression to determine whether store names are valid.

See Also:
Constant Field Values

BUNDLE_ID

public static final java.lang.String BUNDLE_ID
The Constant BUNDLE_ID.

See Also:
Constant Field Values

PROPERTY_ROOT_PATH

public static final java.lang.String PROPERTY_ROOT_PATH
property for root of object store.

See Also:
Constant Field Values

PROPERTY_FILE_LOCKING

public static final java.lang.String PROPERTY_FILE_LOCKING
property for file locking requested.

See Also:
Constant Field Values
Constructor Detail

SimpleObjectStoreService

public SimpleObjectStoreService()
Method Detail

activate

protected void activate(ComponentContext context)
                 throws java.io.IOException
Cleans the temporary stores that were open when the system went down.

Throws:
java.io.IOException - errors creating working dir.

getStoreNames

public java.util.Collection<java.lang.String> getStoreNames()
                                                     throws ObjectStoreException

Specified by:
getStoreNames in interface ObjectStoreService
Returns:
the names of all currently existing stores.
Throws:
ObjectStoreException - on error.

ensureStore

public void ensureStore(java.lang.String storeName)
                 throws ObjectStoreException
Ensures that a store with the given name existing, regardless of the exact configuration properties. If the store does not exist yet, it is created with some default properties.

Specified by:
ensureStore in interface ObjectStoreService
Throws:
InvalidStoreNameException - if the store name is not valid.
ObjectStoreException - other errors

isValidStoreName

public boolean isValidStoreName(java.lang.String storeName)
Check if the argument is a valid store name for this service implementation.

Specified by:
isValidStoreName in interface ObjectStoreService
Returns:
true if the string can be used as a store name, else false.

createStore

public void createStore(java.lang.String storeName,
                        AnyMap storeProperties)
                 throws ObjectStoreException
Creates a store with the given configuration properties. If properties are null, the service chooses default properties on its own.

Specified by:
createStore in interface ObjectStoreService
Parameters:
storeName - name of store to create
storeProperties - store configuration, may be null.
Throws:
InvalidStoreNameException - if the store name is not valid.
StoreExistsException - if a store with this name exists already.
ObjectStoreException - other errors.

getStoreProperties

public AnyMap getStoreProperties(java.lang.String storeName)
                          throws ObjectStoreException
get configuration properties of the named store.

Specified by:
getStoreProperties in interface ObjectStoreService
Returns:
configuration properties.
Throws:
InvalidStoreNameException - if the store name is not valid.
ObjectStoreException - error reading store properties.

getStoreInfo

public AnyMap getStoreInfo(java.lang.String storeName,
                           boolean includeObjectInfos)
                    throws ObjectStoreException
get a description of the current store state to be displayed in administration tools (e.g. by an Http handler). It should include the store properties and the complete object list, if includeObjectInfos == true. It can contain additional information.

Specified by:
getStoreInfo in interface ObjectStoreService
includeObjectInfos - set to true to include the list of current object infos in the result.
Returns:
store state information
Throws:
InvalidStoreNameException - if the store name is not valid.
NoSuchStoreException - if the store does not exist
ObjectStoreException - error reading store properties.

existsStore

public boolean existsStore(java.lang.String storeName)
                    throws ObjectStoreException

Specified by:
existsStore in interface ObjectStoreService
Returns:
true if a store with this name exists, else false.
Throws:
InvalidStoreNameException - if the store name is not valid.
ObjectStoreException - some error.

removeStore

public void removeStore(java.lang.String storeName)
                 throws ObjectStoreException
remove a store completely, if it exists. All objects in this store will be lost. No exception is thrown if the store does not exists currently.

Specified by:
removeStore in interface ObjectStoreService
Throws:
InvalidStoreNameException - if the store name is not valid.
ObjectStoreException - error deleting the store.

removeAllStores

public void removeAllStores()
                     throws ObjectStoreException
remove all stores from the service. All data will be lost, no store will exist anymore.

Specified by:
removeAllStores in interface ObjectStoreService
Throws:
ObjectStoreException - error removing the data.

clearStore

public void clearStore(java.lang.String storeName)
                throws ObjectStoreException
Remove all objects from the named store. The store itself will continue to exist with the same properties as before, it will just be empty as if newly created.

Specified by:
clearStore in interface ObjectStoreService
Throws:
InvalidStoreNameException - if the store name is not valid.
NoSuchStoreException - if the store does not exist.
ObjectStoreException - error clearing the store.

getStoreObjectInfos

public java.util.Collection<StoreObject> getStoreObjectInfos(java.lang.String storeName)
                                                      throws ObjectStoreException
Get information about all current objects in the named store.

Specified by:
getStoreObjectInfos in interface ObjectStoreService
Returns:
list of StoreObjects
Throws:
InvalidStoreNameException - if the store name is not valid.
NoSuchStoreException - if the store does not exist
ObjectStoreException - error determining the object info list.

getStoreObjectInfos

public java.util.Collection<StoreObject> getStoreObjectInfos(java.lang.String storeName,
                                                             java.lang.String objectIdPrefix)
                                                      throws ObjectStoreException
Get information about all current objects in the named store that have an ID that starts with the given prefix.

Specified by:
getStoreObjectInfos in interface ObjectStoreService
Returns:
list of StoreObjects with IDs matching the prefix.
Throws:
InvalidStoreNameException - if the store name is not valid.
NoSuchStoreException - if the store does not exist
ObjectStoreException - error determining the object info list.

getObject

public byte[] getObject(java.lang.String storeName,
                        java.lang.String objectId)
                 throws ObjectStoreException
get the complete content of an object. Use only if you are sure that the object is small enough to fit in memory.

Specified by:
getObject in interface ObjectStoreService
Throws:
InvalidStoreNameException - if the store name is not valid.
NoSuchStoreException - if the store does not exist
NoSuchObjectException - if the object does not exist
ObjectStoreException - other error reading the object

readObject

public java.io.InputStream readObject(java.lang.String storeName,
                                      java.lang.String objectId)
                               throws ObjectStoreException
get a stream for reading the object content.

Specified by:
readObject in interface ObjectStoreService
Throws:
InvalidStoreNameException - if the store name is not valid.
NoSuchStoreException - if the store does not exist
NoSuchObjectException - if the object does not exist
ObjectStoreException - other error reading the object

putObject

public void putObject(java.lang.String storeName,
                      java.lang.String objectId,
                      byte[] data)
               throws ObjectStoreException
write the data to the given store and object. If the object exists already, it is overwritten.

Specified by:
putObject in interface ObjectStoreService
Throws:
InvalidStoreNameException - if the store name is not valid.
NoSuchStoreException - if the store does not exist
ObjectStoreException - other error reading the object

appendToObject

public void appendToObject(java.lang.String storeName,
                           java.lang.String objectId,
                           byte[] data)
                    throws ObjectStoreException
append the data to the given store and object. If the object exists already, the new data is appended at the end of the object. If the object does not exist already, it is created.

Specified by:
appendToObject in interface ObjectStoreService
Throws:
InvalidStoreNameException - if the store name is not valid.
NoSuchStoreException - if the store does not exist
ObjectStoreException - other error reading the object

existsObject

public boolean existsObject(java.lang.String storeName,
                            java.lang.String objectId)
                     throws ObjectStoreException

Specified by:
existsObject in interface ObjectStoreService
Returns:
true if object exists in store, else false.
Throws:
InvalidStoreNameException - if the store name is not valid.
NoSuchStoreException - if the store does not exist
ObjectStoreException - error checking object existence.

removeObject

public void removeObject(java.lang.String storeName,
                         java.lang.String objectId)
                  throws ObjectStoreException
remove the object from the store.No exception is thrown if the object does not exist in the store currently (however, there is one if the store itself does not exist).

Specified by:
removeObject in interface ObjectStoreService
Throws:
InvalidStoreNameException - if the store name is not valid.
NoSuchStoreException - if the store does not exist
ObjectStoreException - error removing the object.

getObjectInfo

public StoreObject getObjectInfo(java.lang.String storeName,
                                 java.lang.String objectId)
                          throws ObjectStoreException
get information about a single object.

Specified by:
getObjectInfo in interface ObjectStoreService
Returns:
information about the object.
Throws:
InvalidStoreNameException - if the store name is not valid.
NoSuchStoreException - if the store does not exist.
NoSuchObjectException - if the object does not exist in the store.
ObjectStoreException - error reading the object info.

finishObject

public void finishObject(java.lang.String storeName,
                         java.lang.String objectId)
                  throws ObjectStoreException
Prevent further append calls to this object. It does not prevent the object from being removed. It is irrelevant for objects that were not created using ObjectStoreService.appendToObject(String, String, byte[]). The operation is optional: An implementation may choose not to support it, in this case it should just ignore the call and not throw an exception. However, in some pathological situations this may lead to data loss, because data could be appended for processing when the object is already considered as finished and the next processing steps have been started and miss the latest appends. This method is not supported in SimpleObjectStoreService.

Specified by:
finishObject in interface ObjectStoreService
Throws:
InvalidStoreNameException - if the store name is not valid.
NoSuchStoreException - if the store does not exist
ObjectStoreException

setFileLockingRequested

protected void setFileLockingRequested(boolean fileLocking)
Sets whether file locking is requested.

Parameters:
fileLocking - 'true' if file locking is requested, 'false' if not.

isFileLockingRequested

public boolean isFileLockingRequested()
Returns:
'true' if file locking is requested, 'false' if not.

validateStore

protected void validateStore(java.lang.String storeName)
                      throws ObjectStoreException
Validates that the store name is valid and a store with the given name exists, throws an exception if it does not exist.

Parameters:
storeName - the name of the store to check.
Throws:
ObjectStoreException - validation failed.

validateStoreName

protected void validateStoreName(java.lang.String storeName)
                          throws InvalidStoreNameException
Validates that the storeName is a valid one, throws an exception if it does not exist.

Parameters:
storeName - the name to check.
Throws:
InvalidStoreNameException - validation failed.

writeToObject

protected void writeToObject(java.lang.String storeName,
                             java.lang.String objectId,
                             byte[] data)
                      throws ObjectStoreException
Puts data to an object in the store.

Parameters:
storeName - the name of the store
objectId - the object id
data - the data to put (or append to) the object
Throws:
ObjectStoreException

writeObject

public StoreOutputStream writeObject(java.lang.String storeName,
                                     java.lang.String objectId)
                              throws ObjectStoreException
open a stream for creating a data object and writing it. If the object exists already, it is overwritten. The object will not become visible in the store until the stream is closed. To prevent the object from becoming visible then (because some error has occurred and the object is invalid), call StoreOutputStream.abort() before closing the stream.

Specified by:
writeObject in interface ObjectStoreService
Returns:
stream for writing data to the object.
Throws:
InvalidStoreNameException - if the store name is not valid.
NoSuchStoreException - if the store does not exist
ObjectStoreException - error creating the object.

SMILA (incubation) API documentation