TrueZIP 6.8.2

de.schlichtherle.io
Class OutputArchiveMetaData

java.lang.Object
  extended by de.schlichtherle.io.OutputArchiveMetaData

public final class OutputArchiveMetaData
extends Object

This class is not intended for public use! It's only public in order to implement ArchiveDrivers.

Annotates an OutputArchive with the methods required for safe writing of archive entries. As an implication of this, it's also responsible for the synchronization of the streams between multiple threads.

Since:
TrueZIP 6.0
Version:
$Id: OutputArchiveMetaData.java 06f3ba684701 2010/11/04 01:15:55 christian $
Author:
Christian Schlichtherle

Nested Class Summary
private  class OutputArchiveMetaData.EntryOutputStream
          An OutputStream to write the entry data to an OutputArchive.
 
Field Summary
private  Archive archive
          The archive which uses this instance.
private static String CLASS_NAME
           
private static Logger logger
           
private  OutputArchive outArchive
           
private  boolean stopped
           
private  Map streams
          The pool of all open entry streams.
 
Constructor Summary
OutputArchiveMetaData(Archive archive, OutputArchive outArchive)
          Creates a new instance of OutputArchiveMetaData and sets itself as the meta data for the given output archive.
 
Method Summary
(package private)  ArchiveException closeAllOutputStreams(ArchiveException exceptionChain)
          Closes and disconnects all entry streams for the archive containing this metadata object.
(package private)  OutputStream createOutputStream(ArchiveEntry entry, ArchiveEntry srcEntry)
           
private  int threadStreams()
          Returns the number of streams opened by the current thread.
(package private)  int waitAllOutputStreamsByOtherThreads(long timeout)
          Waits until all entry streams which have been opened (and not yet closed) by all other threads are closed or a timeout occurs.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_NAME

private static final String CLASS_NAME
See Also:
Constant Field Values

logger

private static final Logger logger

archive

private final Archive archive
The archive which uses this instance. Although this field is actually never used in this class, it makes an archive controller strongly reachable from any entry stream in use by any thread. This is required to keep the archive controller from being garbarge collected meanwhile.

Detail: While this is really required for input streams for archives which are unmodified, it's actually not required for output streams, since the archive file system is touched for these streams anyway, which in turn schedules the archive controller for the next update, which in turn prevents it from being garbage collected. However, it's provided for symmetry between input archive meta data and output archive meta data.


outArchive

private final OutputArchive outArchive

streams

private final Map streams
The pool of all open entry streams. This is implemented as a map where the keys are the streams and the value is the current thread. If File.isLenient() is true, then the map is actually instantiated as a WeakHashMap. Otherwise, it's a HashMap. The weak hash map allows the garbage collector to pick up an entry stream if there are no more references to it. This reduces the likeliness of an ArchiveBusyWarningException in case a sloppy client application has forgot to close a stream before calling File.umount() or File.update().


stopped

private volatile boolean stopped
Constructor Detail

OutputArchiveMetaData

OutputArchiveMetaData(Archive archive,
                      OutputArchive outArchive)
Creates a new instance of OutputArchiveMetaData and sets itself as the meta data for the given output archive.

Method Detail

createOutputStream

OutputStream createOutputStream(ArchiveEntry entry,
                                ArchiveEntry srcEntry)
                          throws IOException
Throws:
IOException

waitAllOutputStreamsByOtherThreads

int waitAllOutputStreamsByOtherThreads(long timeout)
Waits until all entry streams which have been opened (and not yet closed) by all other threads are closed or a timeout occurs. If the current thread is interrupted while waiting, a warning message is logged using java.util.logging and this method returns.

Unless otherwise prevented, another thread could immediately open another stream upon return of this method. So there is actually no guarantee that really all streams are closed upon return of this method - use carefully!

Returns:
The number of all open streams.

threadStreams

private int threadStreams()
Returns the number of streams opened by the current thread.


closeAllOutputStreams

ArchiveException closeAllOutputStreams(ArchiveException exceptionChain)
Closes and disconnects all entry streams for the archive containing this metadata object. Disconnecting means that any subsequent operation on the entry streams will throw an IOException, with the exception of their close() method.


TrueZIP 6.8.2

Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.