s243a

ArchiveStoreItem.java (freenet.client)

Oct 22nd, 2014
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.44 KB | None | 0 0
  1. //s243a pearltree node: http://www.pearltrees.com/s243a/archivestoreitem-freenet/id12827747
  2. /* This code is part of Freenet. It is distributed under the GNU General
  3.  * Public License, version 2 (or at your option any later version). See
  4.  * http://www.gnu.org/ for further details of the GPL. */
  5. package freenet.client;
  6.  
  7. import com.db4o.ObjectContainer;
  8.  
  9. import freenet.support.DoublyLinkedListImpl;
  10. import freenet.support.Logger;
  11. import freenet.support.api.Bucket;
  12.  
  13. /**
  14.  * Base class for items stored in the archive cache.
  15.  */
  16. abstract class ArchiveStoreItem extends DoublyLinkedListImpl.Item<ArchiveStoreItem> {
  17.     final ArchiveKey key;
  18.     final ArchiveStoreContext context;
  19.    
  20.     /** Basic constructor. */
  21.     ArchiveStoreItem(ArchiveKey key, ArchiveStoreContext context) {
  22.         this.key = key;
  23.         this.context = context;
  24.         context.addItem(this);
  25.     }
  26.  
  27.     /** Delete any stored data on disk etc.
  28.      * Override in subtypes for specific cleanup.
  29.      * Will be called with locks held, so should only do low level operations
  30.      * such as deletes.. */
  31.     void innerClose() { } // override in subtypes for cleanup
  32.    
  33.     /**
  34.      * Shortcut to start the removal/cleanup process.
  35.      */
  36.     final void close() {
  37.         context.removeItem(this);
  38.     }
  39.  
  40.     /**
  41.      * Return cached data as a Bucket, or throw an ArchiveFailureException.
  42.      */
  43.     abstract Bucket getDataOrThrow() throws ArchiveFailureException;
  44.  
  45.     /**
  46.      * Return the amount of cache space used by the item. May be called inside
  47.      * locks so should not take any nontrivial locks or take long.
  48.      */
  49.     abstract long spaceUsed();
  50.    
  51.     /**
  52.      * Get the data as a Bucket, and guarantee that it won't be freed until the
  53.      * returned object is either finalized or freed.
  54.      */
  55.     abstract Bucket getReaderBucket() throws ArchiveFailureException;
  56.    
  57.     public boolean objectCanNew(ObjectContainer container) {
  58.         Logger.error(this, "Trying to store an ArchiveStoreItem!", new Exception("error"));
  59.         return false;
  60.     }
  61.    
  62.     public boolean objectCanUpdate(ObjectContainer container) {
  63.         Logger.error(this, "Trying to store an ArchiveStoreItem!", new Exception("error"));
  64.         return false;
  65.     }
  66.    
  67.     public boolean objectCanActivate(ObjectContainer container) {
  68.         Logger.error(this, "Trying to store an ArchiveStoreItem!", new Exception("error"));
  69.         return false;
  70.     }
  71.    
  72.     public boolean objectCanDeactivate(ObjectContainer container) {
  73.         Logger.error(this, "Trying to store an ArchiveStoreItem!", new Exception("error"));
  74.         return false;
  75.     }
  76.    
  77. }
Add Comment
Please, Sign In to add comment