Example #1
0
  /*
   * @see org.alfresco.repo.content.ContentStore#delete(java.lang.String)
   */
  @Override
  public boolean delete(String contentUrl) {
    ReentrantReadWriteLock readWriteLock = readWriteLock(contentUrl);
    ReadLock readLock = readWriteLock.readLock();
    readLock.lock();
    try {
      if (!cache.contains(contentUrl)) {
        // The item isn't in the cache, so simply delete from the backing store
        return backingStore.delete(contentUrl);
      }
    } finally {
      readLock.unlock();
    }

    WriteLock writeLock = readWriteLock.writeLock();
    writeLock.lock();
    try {
      // Double check the content still exists in the cache
      if (cache.contains(contentUrl)) {
        // The item is in the cache, so remove.
        cache.remove(contentUrl);
      }
      // Whether the item was in the cache or not, it must still be deleted from the backing store.
      return backingStore.delete(contentUrl);
    } finally {
      writeLock.unlock();
    }
  }
Example #2
0
  /*
   * @see org.alfresco.repo.content.ContentStore#getWriter(org.alfresco.repo.content.ContentContext)
   */
  @Override
  public ContentWriter getWriter(final ContentContext context) {
    if (cacheOnInbound) {
      final ContentWriter bsWriter = backingStore.getWriter(context);

      // write to cache
      final ContentWriter cacheWriter = cache.getWriter(bsWriter.getContentUrl());

      cacheWriter.addListener(
          new ContentStreamListener() {
            @Override
            public void contentStreamClosed() throws ContentIOException {
              // Finished writing to the cache, so copy to the backing store -
              // ensuring that the encoding attributes are set to the same as for the cache writer.
              bsWriter.setEncoding(cacheWriter.getEncoding());
              bsWriter.setLocale(cacheWriter.getLocale());
              bsWriter.setMimetype(cacheWriter.getMimetype());
              bsWriter.putContent(cacheWriter.getReader());
            }
          });

      return cacheWriter;
    } else {
      // No need to invalidate the cache for this content URL, since a content URL
      // is only ever written to once.
      return backingStore.getWriter(context);
    }
  }
  public void testProtectedRemoval() throws Exception {
    cleaner.setProtectDays(1);
    // add some content to the store
    ContentWriter writer = store.getWriter(ContentStore.NEW_CONTENT_CONTEXT);
    writer.putContent("ABC");
    String contentUrl = writer.getContentUrl();

    // fire the cleaner
    cleaner.execute();

    // the content should have disappeared as it is not in the database
    assertTrue("Protected content was deleted", store.exists(contentUrl));
    assertFalse(
        "Content listener was called with deletion of protected URL",
        deletedUrls.contains(contentUrl));
  }
Example #4
0
  private ContentReader attemptCacheAndRead(String url) {
    ContentReader reader = null;
    try {
      if (!cache.contains(url)) {
        if (cache.put(url, backingStore.getReader(url))) {
          reader = cache.getReader(url);
        }
      } else {
        reader = cache.getReader(url);
      }
    } catch (CacheMissException e) {
      cache.remove(url);
    }

    return reader;
  }
Example #5
0
 private ContentReader cacheAndRead(String url) {
   WriteLock writeLock = readWriteLock(url).writeLock();
   writeLock.lock();
   try {
     for (int i = 0; i < maxCacheTries; i++) {
       ContentReader reader = attemptCacheAndRead(url);
       if (reader != null) {
         return reader;
       }
     }
     // Have tried multiple times to cache the item and read it back from the cache
     // but there is a recurring problem - give up and return the item from the backing store.
     return backingStore.getReader(url);
   } finally {
     writeLock.unlock();
   }
 }
Example #6
0
 /*
  * @see org.alfresco.repo.content.ContentStore#getSpaceUsed()
  */
 @Override
 public long getSpaceUsed() {
   return backingStore.getSpaceUsed();
 }
Example #7
0
 /*
  * @see org.alfresco.repo.content.ContentStore#getTotalSize()
  */
 @Override
 public long getTotalSize() {
   return backingStore.getTotalSize();
 }
Example #8
0
 /*
  * @see org.alfresco.repo.content.ContentStore#isWriteSupported()
  */
 @Override
 public boolean isWriteSupported() {
   return backingStore.isWriteSupported();
 }
Example #9
0
 /*
  * @see org.alfresco.repo.content.ContentStore#isContentUrlSupported(java.lang.String)
  */
 @Override
 public boolean isContentUrlSupported(String contentUrl) {
   return backingStore.isContentUrlSupported(contentUrl);
 }
Example #10
0
 /*
  * @see org.alfresco.repo.content.ContentStore#getUrls(java.util.Date, java.util.Date, org.alfresco.repo.content.ContentStore.ContentUrlHandler)
  */
 @Override
 public void getUrls(Date createdAfter, Date createdBefore, ContentUrlHandler handler)
     throws ContentIOException {
   backingStore.getUrls(createdAfter, createdBefore, handler);
 }
Example #11
0
 /*
  * @see org.alfresco.repo.content.ContentStore#getUrls(org.alfresco.repo.content.ContentStore.ContentUrlHandler)
  */
 @Override
 public void getUrls(ContentUrlHandler handler) throws ContentIOException {
   backingStore.getUrls(handler);
 }
Example #12
0
 /*
  * @see org.alfresco.repo.content.ContentStore#exists(java.lang.String)
  */
 @Override
 public boolean exists(String contentUrl) {
   return backingStore.exists(contentUrl);
 }
Example #13
0
 /*
  * @see org.alfresco.repo.content.ContentStore#getRootLocation()
  */
 @Override
 public String getRootLocation() {
   return backingStore.getRootLocation();
 }
Example #14
0
 /*
  * @see org.alfresco.repo.content.ContentStore#getSpaceTotal()
  */
 @Override
 public long getSpaceTotal() {
   return backingStore.getSpaceTotal();
 }