org.alfresco.repo.content.caching
Class CachingContentStore

java.lang.Object
  extended by org.alfresco.repo.content.caching.CachingContentStore
All Implemented Interfaces:
ContentStore

public class CachingContentStore
extends java.lang.Object
implements ContentStore

Implementation of ContentStore that wraps any other ContentStore (the backing store) transparently providing caching of content in that backing store.

CachingContentStore should only be used to wrap content stores that are significantly slower that FileContentStore - otherwise performance may actually degrade from its use.

It is important that cacheOnInbound is set to true for exceptionally slow backing stores, e.g. org.alfresco.enterprise.repo.content.xam.XAMContentStore


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.alfresco.repo.content.ContentStore
ContentStore.ContentUrlHandler
 
Field Summary
 
Fields inherited from interface org.alfresco.repo.content.ContentStore
NEW_CONTENT_CONTEXT, PROTOCOL_DELIMITER
 
Constructor Summary
CachingContentStore()
           
CachingContentStore(ContentStore backingStore, ContentCache cache, boolean cacheOnInbound)
           
 
Method Summary
 boolean delete(java.lang.String contentUrl)
          Deletes the content at the given URL.
 boolean exists(java.lang.String contentUrl)
          Check for the existence of content in the store.
 org.alfresco.service.cmr.repository.ContentReader getReader(java.lang.String contentUrl)
          Get the accessor with which to read from the content at the given URL.
 java.lang.String getRootLocation()
          Get the location where the store is rooted.
 long getSpaceFree()
          Calcualates the remaing free space in the underlying store.
 long getSpaceTotal()
          Calculates the total storage space of the underlying store.
 long getSpaceUsed()
          Calculates the total size of stored content, excluding any other data in the underlying storage.
 long getTotalSize()
           
 void getUrls(ContentStore.ContentUrlHandler handler)
          Get all URLs for the store, regardless of creation time.
 void getUrls(java.util.Date createdAfter, java.util.Date createdBefore, ContentStore.ContentUrlHandler handler)
          Get a set of all content URLs in the store.
 org.alfresco.service.cmr.repository.ContentWriter getWriter(ContentContext context)
          Get an accessor with which to write content to a location within the store.
 org.alfresco.service.cmr.repository.ContentWriter getWriter(org.alfresco.service.cmr.repository.ContentReader existingContentReader, java.lang.String newContentUrl)
          Shortcut method to ContentStore.getWriter(ContentContext).
 boolean isContentUrlSupported(java.lang.String contentUrl)
          Check if the content URL format is supported by the store.
 boolean isWriteSupported()
          Check if the store supports write requests.
 java.util.concurrent.locks.ReentrantReadWriteLock readWriteLock(java.lang.String url)
          Get a ReentrantReadWriteLock for a given URL.
 void setBackingStore(ContentStore backingStore)
           
 void setCache(ContentCache cache)
           
 void setCacheOnInbound(boolean cacheOnInbound)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachingContentStore

public CachingContentStore()

CachingContentStore

public CachingContentStore(ContentStore backingStore,
                           ContentCache cache,
                           boolean cacheOnInbound)
Method Detail

isContentUrlSupported

public boolean isContentUrlSupported(java.lang.String contentUrl)
Description copied from interface: ContentStore
Check if the content URL format is supported by the store.

Specified by:
isContentUrlSupported in interface ContentStore
Parameters:
contentUrl - the content URL to check
Returns:
Returns true if none of the other methods on the store will throw an UnsupportedContentUrlException when given this URL.

isWriteSupported

public boolean isWriteSupported()
Description copied from interface: ContentStore
Check if the store supports write requests.

Specified by:
isWriteSupported in interface ContentStore
Returns:
Return true is the store supports write operations

getTotalSize

public long getTotalSize()
Specified by:
getTotalSize in interface ContentStore
See Also:
ContentStore.getSpaceFree(), ContentStore.getSpaceTotal()

getSpaceUsed

public long getSpaceUsed()
Description copied from interface: ContentStore
Calculates the total size of stored content, excluding any other data in the underlying storage.

NOTE: Calculating this value can be time-consuming - use sparingly.

NOTE: For efficiency, some implementations may provide a guess. If not, this call could take a long time.

Specified by:
getSpaceUsed in interface ContentStore
Returns:
Returns the total, possibly approximate size (in bytes) of the binary data stored or -1 if no size data is available.

getSpaceFree

public long getSpaceFree()
Description copied from interface: ContentStore
Calcualates the remaing free space in the underlying store.

NOTE: For efficiency, some implementations may provide a guess.

Implementations should focus on calculating a size value quickly, rather than accurately.

Specified by:
getSpaceFree in interface ContentStore
Returns:
Returns the total, possibly approximate, free space (in bytes) available to the store or -1 if no size data is available.

getSpaceTotal

public long getSpaceTotal()
Description copied from interface: ContentStore
Calculates the total storage space of the underlying store.

NOTE: For efficiency, some implementations may provide a guess.

Implementations should focus on calculating a size value quickly, rather than accurately.

Specified by:
getSpaceTotal in interface ContentStore
Returns:
Returns the total, possibly approximate, size (in bytes) of the underlying store or -1 if no size data is available.

getRootLocation

public java.lang.String getRootLocation()
Description copied from interface: ContentStore
Get the location where the store is rooted. The format of the returned value will depend on the specific implementation of the store.

Specified by:
getRootLocation in interface ContentStore
Returns:
Returns the store's root location or . if no information is available

exists

public boolean exists(java.lang.String contentUrl)
Description copied from interface: ContentStore
Check for the existence of content in the store.

The implementation of this may be more efficient than first getting a reader to check for existence, although that check should also be performed.

Specified by:
exists in interface ContentStore
Parameters:
contentUrl - the path to the content
Returns:
Returns true if the content exists, otherwise false if the content doesn't exist or if the URL is not applicable to this store.
See Also:
ContentReader.exists()

getReader

public org.alfresco.service.cmr.repository.ContentReader getReader(java.lang.String contentUrl)
Description copied from interface: ContentStore
Get the accessor with which to read from the content at the given URL. The reader is stateful and can only be used once.

Specified by:
getReader in interface ContentStore
Parameters:
contentUrl - the path to where the content is located
Returns:
Returns a read-only content accessor for the given URL. There may be no content at the given URL, but the reader must still be returned.
See Also:
ContentStore.exists(String), ContentReader.exists(), EmptyContentReader

getWriter

public org.alfresco.service.cmr.repository.ContentWriter getWriter(ContentContext context)
Description copied from interface: ContentStore
Get an accessor with which to write content to a location within the store. The writer is stateful and can only be used once. The location may be specified but must, in that case, be a valid and unused URL.

The store will ensure that the new content URL will be valid for all subsequent read attempts.

By supplying a reader to existing content, the store implementation may enable random access. The store implementation can enable this by copying the existing content into the new location before supplying a writer onto the new content.

Specified by:
getWriter in interface ContentStore
Parameters:
context - the context of content.
Returns:
Returns a write-only content accessor
See Also:
#getWriteSupport(), ContentAccessor.addListener(ContentStreamListener), ContentAccessor.getContentUrl()

getWriter

public org.alfresco.service.cmr.repository.ContentWriter getWriter(org.alfresco.service.cmr.repository.ContentReader existingContentReader,
                                                                   java.lang.String newContentUrl)
Description copied from interface: ContentStore
Shortcut method to ContentStore.getWriter(ContentContext).

Specified by:
getWriter in interface ContentStore
See Also:
ContentStore.getWriter(ContentContext)

getUrls

public void getUrls(ContentStore.ContentUrlHandler handler)
             throws org.alfresco.service.cmr.repository.ContentIOException
Description copied from interface: ContentStore
Get all URLs for the store, regardless of creation time.

Specified by:
getUrls in interface ContentStore
Throws:
org.alfresco.service.cmr.repository.ContentIOException - if an IO error occurs
See Also:
#getUrls(Date, Date)

getUrls

public void getUrls(java.util.Date createdAfter,
                    java.util.Date createdBefore,
                    ContentStore.ContentUrlHandler handler)
             throws org.alfresco.service.cmr.repository.ContentIOException
Description copied from interface: ContentStore
Get a set of all content URLs in the store. This indicates all content available for reads.

Specified by:
getUrls in interface ContentStore
Parameters:
createdAfter - all URLs returned must have been created after this date. May be null.
createdBefore - all URLs returned must have been created before this date. May be null.
handler - the callback that will passed each URL
Throws:
org.alfresco.service.cmr.repository.ContentIOException - if an error occurs

delete

public boolean delete(java.lang.String contentUrl)
Description copied from interface: ContentStore
Deletes the content at the given URL.

A delete cannot be forced since it is much better to have the file remain longer than desired rather than deleted prematurely.

Specified by:
delete in interface ContentStore
Parameters:
contentUrl - the URL of the content to delete
Returns:
Returns true if the content was deleted (either by this or another operation), otherwise false. If the content no longer exists, then true is returned.

readWriteLock

public java.util.concurrent.locks.ReentrantReadWriteLock readWriteLock(java.lang.String url)
Get a ReentrantReadWriteLock for a given URL. The lock is from a pool rather than per URL, so some contention is expected.

Parameters:
url -
Returns:

setBackingStore

public void setBackingStore(ContentStore backingStore)

setCache

public void setCache(ContentCache cache)

setCacheOnInbound

public void setCacheOnInbound(boolean cacheOnInbound)


Copyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.