s243a

ArchiveHandler.java (freenet.client)

Oct 22nd, 2014
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.95 KB | None | 0 0
  1. //pearltree node: http://www.pearltrees.com/s243a/archivehandler-java/id12827426
  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.client.ArchiveManager.ARCHIVE_TYPE;
  10. import freenet.client.async.ClientContext;
  11. import freenet.keys.FreenetURI;
  12. import freenet.support.api.Bucket;
  13.  
  14. /**
  15.  * @author toad
  16.  * The public face (to Fetcher, for example) of ArchiveStoreContext.
  17.  * Mostly has methods for fetching stuff, but SingleFileFetcher needs to be able
  18.  * to download and then ask the ArchiveManager to extract it, so we include that
  19.  * functionality (extractToCache) too. Because ArchiveManager is not persistent,
  20.  * we have to pass it in to each method.
  21.  */
  22. public interface ArchiveHandler {
  23.  
  24.     /**
  25.      * Get the metadata for this ZIP manifest, as a Bucket.
  26.      * THE RETURNED BUCKET WILL ALWAYS BE NON-PERSISTENT.
  27.      * @return The metadata as a Bucket, or null.
  28.      * @param manager The ArchiveManager.
  29.      * @throws FetchException If the container could not be fetched.
  30.      * @throws MetadataParseException If there was an error parsing intermediary metadata.
  31.      */
  32.     public abstract Bucket getMetadata(ArchiveContext archiveContext,
  33.             ArchiveManager manager, ObjectContainer container)
  34.             throws ArchiveFailureException, ArchiveRestartException,
  35.             MetadataParseException, FetchException;
  36.  
  37.     /**
  38.      * Get a file from this ZIP manifest, as a Bucket.
  39.      * If possible, read it from cache. If not, return null.
  40.      * THE RETURNED BUCKET WILL ALWAYS BE NON-PERSISTENT.
  41.      * @param inSplitZipManifest If true, indicates that the key points to a splitfile zip manifest,
  42.      * which means that we need to pass a flag to the fetcher to tell it to pretend it was a straight
  43.      * splitfile.
  44.      * @param manager The ArchiveManager.
  45.      * @throws FetchException
  46.      * @throws MetadataParseException
  47.      */
  48.     public abstract Bucket get(String internalName,
  49.             ArchiveContext archiveContext, ArchiveManager manager, ObjectContainer container)
  50.             throws ArchiveFailureException, ArchiveRestartException,
  51.             MetadataParseException, FetchException;
  52.  
  53.     /**
  54.      * Get the archive type.
  55.      */
  56.     public abstract ARCHIVE_TYPE getArchiveType();
  57.  
  58.     /**
  59.      * Get the key.
  60.      */
  61.     public abstract FreenetURI getKey();
  62.    
  63.     /**
  64.      * Unpack a fetched archive to cache, and call the callback if there is one.
  65.      * @param bucket The downloaded data for the archive.
  66.      * @param actx The ArchiveContext.
  67.      * @param element The single element that the caller is especially interested in.
  68.      * @param callback Callback to be notified whether the content is available, and if so, fed the data.
  69.      * @param manager The ArchiveManager.
  70.      * @throws ArchiveFailureException
  71.      * @throws ArchiveRestartException
  72.      */
  73.     public abstract void extractToCache(Bucket bucket, ArchiveContext actx, String element, ArchiveExtractCallback callback, ArchiveManager manager,
  74.             ObjectContainer container, ClientContext context) throws ArchiveFailureException, ArchiveRestartException;
  75.  
  76.     /**
  77.      * Unpack a fetched archive on a separate thread for a persistent caller.
  78.      * This involves:
  79.      * - Add a tag to the database so that it will be restarted on a crash.
  80.      * - Run the actual unpack on a separate thread.
  81.      * - Copy the data to a persistent bucket.
  82.      * - Schedule a database job.
  83.      * - Call the callback.
  84.      * @param bucket
  85.      * @param actx
  86.      * @param element
  87.      * @param callback
  88.      * @param container
  89.      * @param context
  90.      */
  91.     public abstract void extractPersistentOffThread(Bucket bucket, boolean freeBucket, ArchiveContext actx, String element, ArchiveExtractCallback callback, ObjectContainer container, ClientContext context);
  92.    
  93.     public abstract void activateForExecution(ObjectContainer container);
  94.  
  95.     public abstract ArchiveHandler cloneHandler();
  96.  
  97.     public abstract void removeFrom(ObjectContainer container);
  98.    
  99. }
Add Comment
Please, Sign In to add comment