public class SimpleObjectStoreService extends java.lang.Object implements ObjectStoreService
A file system based implementation of ObjectStoreService.
The following rules apply to this store implementation:
getStoreObjectInfos(String, String).SimpleStoreOutputStream is closed or an
invocation of writeObject(String, String) method succeeded.
appendToObject(String, String, byte[]) method will append directly to
the visible object.| Modifier and Type | Field and Description |
|---|---|
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.
|
KEY_OBJECT_COUNT, KEY_OBJECTS, KEY_SIZE, KEY_STORE_NAME, KEY_STORE_PROPERTIES| Constructor and Description |
|---|
SimpleObjectStoreService() |
| Modifier and Type | Method and Description |
|---|---|
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.
|
long |
countStoreObjects(java.lang.String storeName,
java.lang.String objectIdPrefix)
Count all current objects in the named store that have an ID that starts with the given prefix.
|
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.
|
java.util.Collection<java.lang.String> |
getPrefixes(java.lang.String storeName,
java.lang.String objectIdPrefix)
Get all prefixes of objectIds (this can also include complete ObjectIds) in the named store that have an ID that
starts with the given prefix until the next separator (/).
|
AnyMap |
getStoreInfo(java.lang.String storeName,
boolean includeObjectInfos)
get a description of the current store state to be displayed in administration tools (e.g. by an Http handler).
|
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.
|
void |
removeObjects(java.lang.String storeName,
java.lang.String objectIdPrefix)
remove all objects from the store with an ID starting with the given prefix.
|
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.
|
public static final java.lang.String VALID_STORENAME_EXPRESSION
public static final java.lang.String BUNDLE_ID
public static final java.lang.String PROPERTY_ROOT_PATH
public static final java.lang.String PROPERTY_FILE_LOCKING
protected void activate(ComponentContext context)
throws java.io.IOException
java.io.IOException - errors creating working dir.public java.util.Collection<java.lang.String> getStoreNames()
throws ObjectStoreException
getStoreNames in interface ObjectStoreServiceObjectStoreException - on error.public void ensureStore(java.lang.String storeName)
throws ObjectStoreException
ensureStore in interface ObjectStoreServiceInvalidStoreNameException - if the store name is not valid.ObjectStoreException - other errorspublic boolean isValidStoreName(java.lang.String storeName)
isValidStoreName in interface ObjectStoreServicepublic void createStore(java.lang.String storeName,
AnyMap storeProperties)
throws ObjectStoreException
null, the service chooses
default properties on its own.createStore in interface ObjectStoreServicestoreName - name of store to createstoreProperties - store configuration, may be null.InvalidStoreNameException - if the store name is not valid.StoreExistsException - if a store with this name exists already.ObjectStoreException - other errors.public AnyMap getStoreProperties(java.lang.String storeName) throws ObjectStoreException
getStoreProperties in interface ObjectStoreServiceInvalidStoreNameException - if the store name is not valid.ObjectStoreException - error reading store properties.public AnyMap getStoreInfo(java.lang.String storeName, boolean includeObjectInfos) throws ObjectStoreException
includeObjectInfos == true. It
can contain additional information.getStoreInfo in interface ObjectStoreServiceincludeObjectInfos - set to true to include the list of current object infos in the result.InvalidStoreNameException - if the store name is not valid.NoSuchStoreException - if the store does not existObjectStoreException - error reading store properties.public boolean existsStore(java.lang.String storeName)
throws ObjectStoreException
existsStore in interface ObjectStoreServiceInvalidStoreNameException - if the store name is not valid.ObjectStoreException - some error.public void removeStore(java.lang.String storeName)
throws ObjectStoreException
removeStore in interface ObjectStoreServiceInvalidStoreNameException - if the store name is not valid.ObjectStoreException - error deleting the store.public void removeAllStores()
throws ObjectStoreException
removeAllStores in interface ObjectStoreServiceObjectStoreException - error removing the data.public void clearStore(java.lang.String storeName)
throws ObjectStoreException
clearStore in interface ObjectStoreServiceInvalidStoreNameException - if the store name is not valid.NoSuchStoreException - if the store does not exist.ObjectStoreException - error clearing the store.public java.util.Collection<StoreObject> getStoreObjectInfos(java.lang.String storeName) throws ObjectStoreException
getStoreObjectInfos in interface ObjectStoreServiceStoreObjectsInvalidStoreNameException - if the store name is not valid.NoSuchStoreException - if the store does not existObjectStoreException - error determining the object info list.public java.util.Collection<StoreObject> getStoreObjectInfos(java.lang.String storeName, java.lang.String objectIdPrefix) throws ObjectStoreException
getStoreObjectInfos in interface ObjectStoreServiceStoreObjects with IDs matching the prefix.InvalidStoreNameException - if the store name is not valid.NoSuchStoreException - if the store does not existObjectStoreException - error determining the object info list.public long countStoreObjects(java.lang.String storeName,
java.lang.String objectIdPrefix)
throws ObjectStoreException
ObjectStoreServicecountStoreObjects in interface ObjectStoreServiceStoreObjects with IDs matching the prefix.InvalidStoreNameException - if the store name is not valid.NoSuchStoreException - if the store does not existObjectStoreException - error determining the object info list.public java.util.Collection<java.lang.String> getPrefixes(java.lang.String storeName,
java.lang.String objectIdPrefix)
throws ObjectStoreException
getPrefixes in interface ObjectStoreServiceStrings with IDs matching the prefix.InvalidStoreNameException - if the store name is not valid.NoSuchStoreException - if the store does not existObjectStoreException - error determining the object info list.public byte[] getObject(java.lang.String storeName,
java.lang.String objectId)
throws ObjectStoreException
getObject in interface ObjectStoreServiceInvalidStoreNameException - if the store name is not valid.NoSuchStoreException - if the store does not existNoSuchObjectException - if the object does not existObjectStoreException - other error reading the objectpublic java.io.InputStream readObject(java.lang.String storeName,
java.lang.String objectId)
throws ObjectStoreException
readObject in interface ObjectStoreServiceInvalidStoreNameException - if the store name is not valid.NoSuchStoreException - if the store does not existNoSuchObjectException - if the object does not existObjectStoreException - other error reading the objectpublic void putObject(java.lang.String storeName,
java.lang.String objectId,
byte[] data)
throws ObjectStoreException
putObject in interface ObjectStoreServiceInvalidStoreNameException - if the store name is not valid.NoSuchStoreException - if the store does not existObjectStoreException - other error reading the objectpublic void appendToObject(java.lang.String storeName,
java.lang.String objectId,
byte[] data)
throws ObjectStoreException
appendToObject in interface ObjectStoreServiceInvalidStoreNameException - if the store name is not valid.NoSuchStoreException - if the store does not existObjectStoreException - other error reading the objectpublic boolean existsObject(java.lang.String storeName,
java.lang.String objectId)
throws ObjectStoreException
existsObject in interface ObjectStoreServiceInvalidStoreNameException - if the store name is not valid.NoSuchStoreException - if the store does not existObjectStoreException - error checking object existence.public void removeObject(java.lang.String storeName,
java.lang.String objectId)
throws ObjectStoreException
removeObject in interface ObjectStoreServiceInvalidStoreNameException - if the store name is not valid.NoSuchStoreException - if the store does not existObjectStoreException - error removing the object.public void removeObjects(java.lang.String storeName,
java.lang.String objectIdPrefix)
throws ObjectStoreException
ObjectStoreServiceremoveObjects in interface ObjectStoreServiceInvalidStoreNameException - if the store name is not valid.NoSuchStoreException - if the store does not existObjectStoreException - error removing the object.public StoreObject getObjectInfo(java.lang.String storeName, java.lang.String objectId) throws ObjectStoreException
getObjectInfo in interface ObjectStoreServiceInvalidStoreNameException - 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.public void finishObject(java.lang.String storeName,
java.lang.String objectId)
throws ObjectStoreException
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.finishObject in interface ObjectStoreServiceInvalidStoreNameException - if the store name is not valid.NoSuchStoreException - if the store does not existObjectStoreExceptionprotected void setFileLockingRequested(boolean fileLocking)
fileLocking - 'true' if file locking is requested, 'false' if not.public boolean isFileLockingRequested()
protected void validateStore(java.lang.String storeName)
throws ObjectStoreException
storeName - the name of the store to check.ObjectStoreException - validation failed.protected void validateStoreName(java.lang.String storeName)
throws InvalidStoreNameException
storeName - the name to check.InvalidStoreNameException - validation failed.protected void writeToObject(java.lang.String storeName,
java.lang.String objectId,
byte[] data)
throws ObjectStoreException
storeName - the name of the storeobjectId - the object iddata - the data to put (or append to) the objectObjectStoreExceptionpublic StoreOutputStream writeObject(java.lang.String storeName, java.lang.String objectId) throws ObjectStoreException
StoreOutputStream.abort() before
closing the stream.writeObject in interface ObjectStoreServiceInvalidStoreNameException - if the store name is not valid.NoSuchStoreException - if the store does not existObjectStoreException - error creating the object.