org.gcube.contentmanagement.baselayer.inMessageImpl
Class InMemoryContentManager

java.lang.Object
  extended by org.gcube.contentmanagement.baselayer.inMessageImpl.InMemoryContentManager
All Implemented Interfaces:
InstantiableManager, RawFileContentManager

public class InMemoryContentManager
extends java.lang.Object
implements RawFileContentManager, InstantiableManager

This class keeps a copy of content passed with a SOAP message (or for passing to message) in momery. It should therefore only be used for small files.

In addition, since main memory is volatile, it can only be used for passing messages - not for permanently storing them.


Field Summary
 
Fields inherited from interface org.gcube.contentmanagement.baselayer.InstantiableManager
MANAGER_INSTANTIATION_METHOD_NAME
 
Method Summary
 boolean deleteBinaryContent(RawContentLocation location, BasicStorageHints hints)
          Removes the binary content from storage
 boolean existsBinaryContent(RawContentLocation location, BasicStorageHints hints)
          Checks whether there is content at this location
 BaseLayerStream getBinaryContent(byte[] bytes, BasicStorageHints hints)
          Wraps the content for reading as an input stream to the caller.
 BaseLayerStream getBinaryContent(RawContentLocation location, BasicStorageHints hints)
          Opens the content for reading and passes the input stream to the caller.
 byte[] getBytes(InMemoryRawContentLocation location, BasicStorageHints hints)
          Shorthand to directly reference the stored bytes instead of accessing them through a stream.
 java.lang.String getDataProvider()
          
static InMemoryContentManager getInstance()
          Factory method to return the singleton manager
static InMemoryContentManager getManagerInstance(java.lang.String[] params, java.lang.String managerName)
          Generic factory method that returns the singleton instance
 java.lang.String getUniqueStorageLocationIDFor(java.lang.String objectID)
           
 boolean handles(java.lang.String dataprovider)
          Checks whether the RawFileContentManager can handle this data.
 RawContentLocation makePermanentLocation(RawContentLocation currentLocation, BasicStorageHints hints)
          Returns a raw location, which can be stored and retrieved later without the need to pass again all the hints.
 RawContentLocation saveBinaryContent(java.lang.String uniqueStorageID, BaseLayerStream binaryFileContent, BasicStorageHints hints)
          Saves the passed binary content in the managed resource.
 RawContentLocation storeBytes(byte[] content, BasicStorageHints hints)
          Shorthand to store a reference to bytes directly without the need of copying them in memory
 RawContentLocation storeBytes(java.lang.String uniqueStorageID, byte[] content, BasicStorageHints hints)
          Shorthand to store a reference to bytes directly without the need of copying them in memory
 boolean supportsAppending()
          Tells whether this content manager supports appending content in addition to overwriting the content when storing
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static InMemoryContentManager getInstance()
Factory method to return the singleton manager

Returns:
the manager

saveBinaryContent

public RawContentLocation saveBinaryContent(java.lang.String uniqueStorageID,
                                            BaseLayerStream binaryFileContent,
                                            BasicStorageHints hints)
                                     throws BaseLayerException
Saves the passed binary content in the managed resource. If the resource did previously exist, it is updated and the old content is lost. If the resource did not exist, it will be newly created.

Specified by:
saveBinaryContent in interface RawFileContentManager
Parameters:
binaryFileContent - the content to store
uniqueStorageID - a unique ID to as a hint where to store the content
hints - the hints that should be used
Returns:
a "dummy" RawContentLocation, because the location is also stored within the hints and only this is evaluated for retrieving.
Throws:
BaseLayerException - in case of failure of underlying storage system

storeBytes

public RawContentLocation storeBytes(java.lang.String uniqueStorageID,
                                     byte[] content,
                                     BasicStorageHints hints)
Shorthand to store a reference to bytes directly without the need of copying them in memory

Parameters:
uniqueStorageID - a unique ID to as a hint where to store the content
content - the binary content to store
Returns:
the RawContentLocation where the content is now accessible

storeBytes

public RawContentLocation storeBytes(byte[] content,
                                     BasicStorageHints hints)
Shorthand to store a reference to bytes directly without the need of copying them in memory

Parameters:
content - the binary content to store
Returns:
the RawContentLocation where the content is now accessible

getBytes

public byte[] getBytes(InMemoryRawContentLocation location,
                       BasicStorageHints hints)
                throws BaseLayerException
Shorthand to directly reference the stored bytes instead of accessing them through a stream.

Parameters:
location - the InMemoryRawContentLocation holding the bytes
hints - must contain the real locatin where the content is accessible and will be deleted afterwards - will be set by storing automatically
Returns:
the content stored in the managed resource
Throws:
BaseLayerException - in case of failure of underlying storage system

getBinaryContent

public BaseLayerStream getBinaryContent(RawContentLocation location,
                                        BasicStorageHints hints)
Opens the content for reading and passes the input stream to the caller.

Specified by:
getBinaryContent in interface RawFileContentManager
Parameters:
location - the RawContentLocation where the content is accessible
hints - the hints that should be used
Returns:
the content stored in the managed resource

getBinaryContent

public BaseLayerStream getBinaryContent(byte[] bytes,
                                        BasicStorageHints hints)
Wraps the content for reading as an input stream to the caller.

Parameters:
bytes - the raw content
Returns:
the content stored in the managed resource

deleteBinaryContent

public boolean deleteBinaryContent(RawContentLocation location,
                                   BasicStorageHints hints)
                            throws BaseLayerException
Removes the binary content from storage

Specified by:
deleteBinaryContent in interface RawFileContentManager
Parameters:
location - the RawContentLocation where the content is accessible
hints - the hints that should be used
Returns:
true, if content has been deleted successfully; false if the content did not exist and therefore the operation had no effect.
Throws:
BaseLayerException - in case of failure of underlying storage system

existsBinaryContent

public boolean existsBinaryContent(RawContentLocation location,
                                   BasicStorageHints hints)
                            throws BaseLayerException
Checks whether there is content at this location

Specified by:
existsBinaryContent in interface RawFileContentManager
Parameters:
location - the RawContentLocation where the content is accessible
Returns:
true, if there is content at this location; false otherwise
Throws:
BaseLayerException - in case of failure of underlying storage system

handles

public boolean handles(java.lang.String dataprovider)
Checks whether the RawFileContentManager can handle this data.

This means that it can handle the requests for content stored at this dataprovider. In the ideal case, this also checks if it has all required access rights. But this cannot be enforced as a strong requirement before the actual calls take place.

Specified by:
handles in interface RawFileContentManager
Parameters:
dataprovider -
Returns:
true, if it can do, false otherwise

getDataProvider

public java.lang.String getDataProvider()

Specified by:
getDataProvider in interface RawFileContentManager
Returns:
a string identifying this data source

supportsAppending

public boolean supportsAppending()
Tells whether this content manager supports appending content in addition to overwriting the content when storing

Specified by:
supportsAppending in interface RawFileContentManager
Returns:
true, if appending is supported
See Also:
BasicStorageHints#HINT_NAME_APPEND_CONTENT

makePermanentLocation

public RawContentLocation makePermanentLocation(RawContentLocation currentLocation,
                                                BasicStorageHints hints)
                                         throws ValueNotValidException
Returns a raw location, which can be stored and retrieved later without the need to pass again all the hints.

This is of particular interest for username / password combinations.

Specified by:
makePermanentLocation in interface RawFileContentManager
Parameters:
currentLocation - the location, where content can be accessed currently (may require information from the hints)
hints - hints, that may be needed to request the content
Returns:
a location which can be accessed without providing again the hints. This may not always be possible.
Throws:
ValueNotValidException - If some hints was not defined correctly or there is no possibility to include that in the permanent location.

getManagerInstance

public static InMemoryContentManager getManagerInstance(java.lang.String[] params,
                                                        java.lang.String managerName)
                                                 throws BaseLayerException
Generic factory method that returns the singleton instance

Parameters:
params - currently not used at all
managerName - the name of the manager (currently not in use)
Returns:
the manager
Throws:
BaseLayerException - if something goes wrong

getUniqueStorageLocationIDFor

public java.lang.String getUniqueStorageLocationIDFor(java.lang.String objectID)
Specified by:
getUniqueStorageLocationIDFor in interface RawFileContentManager