TrueZIP Kernel 7.0-rc1

de.schlichtherle.truezip.fs.archive
Class FsDefaultArchiveController<E extends FsArchiveEntry>

java.lang.Object
  extended by de.schlichtherle.truezip.fs.FsController<FsConcurrentModel>
      extended by de.schlichtherle.truezip.fs.archive.FsArchiveController<E>
          extended by de.schlichtherle.truezip.fs.archive.FsFileSystemArchiveController<E>
              extended by de.schlichtherle.truezip.fs.archive.FsDefaultArchiveController<E>
Type Parameters:
E - The type of the archive entries.

@NotThreadSafe
@DefaultAnnotation(value=edu.umd.cs.findbugs.annotations.NonNull.class)
public final class FsDefaultArchiveController<E extends FsArchiveEntry>
extends FsFileSystemArchiveController<E>

This archive controller implements the mounting/unmounting strategy for the container archive file.

Author:
Christian Schlichtherle

Nested Class Summary
private static class FsDefaultArchiveController.DummyInputService<E extends Entry>
          A dummy input service to substitute for null.
private  class FsDefaultArchiveController.Input
          This member class makes this archive controller instance strongly reachable from any created input stream.
private  class FsDefaultArchiveController.Output
          This member class makes this archive controller instance strongly reachable from any created output stream.
private  class FsDefaultArchiveController.TouchListener
          An archive file system listener which makes the output before it touches the file system model.
 
Field Summary
private  FsArchiveDriver<E> driver
           
private  FsDefaultArchiveController.Input input
          An FsDefaultArchiveController.Input object used to mount the (virtual) archive file system and read the entries from the archive file.
private static BitField<FsOutputOption> MAKE_OUTPUT_OPTIONS
           
private static BitField<FsInputOption> MOUNT_INPUT_OPTIONS
           
private static BitField<FsOutputOption> MOUNT_MASK
           
private  FsDefaultArchiveController.Output output
          The (possibly temporary) FsDefaultArchiveController.Output we are writing newly created or modified entries to.
private  FsController<?> parent
           
private  FsEntryName parentName
           
private static BitField<FsSyncOption> SYNC_OPTIONS
           
private  FsArchiveFileSystemTouchListener<E> touchListener
           
private  boolean useRootTemplate
           
 
Constructor Summary
FsDefaultArchiveController(FsConcurrentModel model, FsArchiveDriver<E> driver, FsController<?> parent, boolean useRootTemplate)
           
 
Method Summary
(package private)  boolean autoSync(FsEntryName name, Entry.Access intention)
          Synchronizes the archive file only if the archive file has new data for the file system entry with the given path path.
private
<X extends IOException>
void
awaitSync(BitField<FsSyncOption> options, ExceptionHandler<? super FsSyncException,X> handler)
          Waits for all entry input and entry output streams to close or forces them to close, dependending on the options.
private
<X extends IOException>
void
commenceSync(ExceptionHandler<? super FsSyncException,X> handler)
          Closes and disconnects all entry streams of the output and input archive.
private
<X extends IOException>
void
commitSync(ExceptionHandler<? super FsSyncException,X> handler)
          Discards the file system and closes the output and input archive.
private static
<E extends FsArchiveEntry,X extends IOException>
void
copy(FsArchiveFileSystem<E> fileSystem, InputService<E> input, OutputService<E> output, ExceptionHandler<IOException,X> handler)
           
 Icon getClosedIcon()
           
(package private)  InputSocket<?> getInputSocket(String name)
           
 Icon getOpenIcon()
           
(package private)  OutputSocket<?> getOutputSocket(E entry)
           
 FsController<?> getParent()
          Returns the controller for the parent file system or null if and only if this file system is not federated, i.e. not a member of another file system.
private  boolean isTouched()
           
(package private)  void makeOutput(BitField<FsOutputOption> options, Entry rootTemplate)
           
(package private)  void mount(boolean autoCreate, BitField<FsOutputOption> options)
          Mounts the (virtual) archive file system from the target file.
private
<X extends IOException>
void
performSync(ExceptionHandler<? super FsSyncException,X> handler)
          Synchronizes all entries in the (virtual) archive file system with the (temporary) output archive file.
private  boolean sync()
           
<X extends IOException>
void
sync(BitField<FsSyncOption> options, ExceptionHandler<? super FsSyncException,X> handler)
          Commits all unsynchronized changes to the contents of this file system to its parent file system.
 void unlink(FsEntryName name)
           
 
Methods inherited from class de.schlichtherle.truezip.fs.archive.FsFileSystemArchiveController
autoMount, getFileSystem, setFileSystem
 
Methods inherited from class de.schlichtherle.truezip.fs.archive.FsArchiveController
autoMount, getEntry, getInputSocket, getModel, getOutputSocket, isReadable, isReadOnly, isWritable, mknod, setReadOnly, setTime
 
Methods inherited from class de.schlichtherle.truezip.fs.FsController
equals, hashCode, sync, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MOUNT_MASK

private static final BitField<FsOutputOption> MOUNT_MASK

MOUNT_INPUT_OPTIONS

private static final BitField<FsInputOption> MOUNT_INPUT_OPTIONS

MAKE_OUTPUT_OPTIONS

private static final BitField<FsOutputOption> MAKE_OUTPUT_OPTIONS

SYNC_OPTIONS

private static final BitField<FsSyncOption> SYNC_OPTIONS

driver

private final FsArchiveDriver<E extends FsArchiveEntry> driver

parent

private final FsController<?> parent

parentName

private final FsEntryName parentName

useRootTemplate

private final boolean useRootTemplate

input

@Nullable
private FsDefaultArchiveController.Input input
An FsDefaultArchiveController.Input object used to mount the (virtual) archive file system and read the entries from the archive file.


output

@Nullable
private FsDefaultArchiveController.Output output
The (possibly temporary) FsDefaultArchiveController.Output we are writing newly created or modified entries to.


touchListener

private final FsArchiveFileSystemTouchListener<E extends FsArchiveEntry> touchListener
Constructor Detail

FsDefaultArchiveController

public FsDefaultArchiveController(FsConcurrentModel model,
                                  FsArchiveDriver<E> driver,
                                  FsController<?> parent,
                                  boolean useRootTemplate)
Method Detail

getParent

public FsController<?> getParent()
Description copied from class: FsController
Returns the controller for the parent file system or null if and only if this file system is not federated, i.e. not a member of another file system.

Specified by:
getParent in class FsController<FsConcurrentModel>

getOpenIcon

public Icon getOpenIcon()
                 throws IOException
Specified by:
getOpenIcon in class FsController<FsConcurrentModel>
Throws:
IOException

getClosedIcon

public Icon getClosedIcon()
                   throws IOException
Specified by:
getClosedIcon in class FsController<FsConcurrentModel>
Throws:
IOException

mount

void mount(boolean autoCreate,
           BitField<FsOutputOption> options)
     throws IOException
Description copied from class: FsFileSystemArchiveController
Mounts the (virtual) archive file system from the target file. This method is called while the write lock to mount the file system for this controller is acquired.

Upon normal termination, this method is expected to have called FsFileSystemArchiveController.ResetFileSystem to assign the fully initialized file system to this controller. Other than this, the method must not have any side effects on the state of this class or its super class. It may, however, have side effects on the state of the sub class.

Specified by:
mount in class FsFileSystemArchiveController<E extends FsArchiveEntry>
Parameters:
autoCreate - If the archive file does not exist and this is true, a new file system with only a (virtual) root directory is created with its last modification time set to the system's current time.
Throws:
IOException

makeOutput

void makeOutput(BitField<FsOutputOption> options,
                Entry rootTemplate)
          throws IOException
Throws:
IOException

getInputSocket

InputSocket<?> getInputSocket(String name)
                        throws IOException
Specified by:
getInputSocket in class FsArchiveController<E extends FsArchiveEntry>
Throws:
IOException

getOutputSocket

OutputSocket<?> getOutputSocket(E entry)
                          throws IOException
Specified by:
getOutputSocket in class FsArchiveController<E extends FsArchiveEntry>
Throws:
IOException

unlink

public void unlink(FsEntryName name)
            throws IOException
Overrides:
unlink in class FsArchiveController<E extends FsArchiveEntry>
Throws:
IOException

autoSync

boolean autoSync(FsEntryName name,
                 @CheckForNull
                 Entry.Access intention)
           throws FsSyncException,
                  FsException
Description copied from class: FsArchiveController
Synchronizes the archive file only if the archive file has new data for the file system entry with the given path path.

Warning: As a side effect, all data structures may get reset (filesystem, entries, streams, etc.)! This method may require synchronization on the write lock!

Specified by:
autoSync in class FsArchiveController<E extends FsArchiveEntry>
Parameters:
name - the non-null entry name.
intention - the intended operation on the entry. If null, a pure file system operation with no I/O is intended.
Returns:
Whether or not a synchronization has been performed.
Throws:
FsNotWriteLockedException
FsSyncException
FsException
See Also:
FsController.sync(de.schlichtherle.truezip.util.BitField)

sync

private boolean sync()
              throws FsSyncException,
                     FsException
Throws:
FsSyncException
FsException

sync

public <X extends IOException> void sync(BitField<FsSyncOption> options,
                                         ExceptionHandler<? super FsSyncException,X> handler)
          throws X extends IOException
Description copied from class: FsController
Commits all unsynchronized changes to the contents of this file system to its parent file system. If this is not a federated file system, i.e. if its not a member of a parent file system, then nothing happens. Otherwise, the state of this file system controller is reset.

Specified by:
sync in class FsController<FsConcurrentModel>
Type Parameters:
X - the type of the IOException to throw at the discretion of the exception handler.
Parameters:
options - the synchronization options.
handler - the exception handling strategy for dealing with one or more input FsSyncExceptions which may trigger an X.
Throws:
X extends IOException

awaitSync

private <X extends IOException> void awaitSync(BitField<FsSyncOption> options,
                                               ExceptionHandler<? super FsSyncException,X> handler)
                throws X extends IOException
Waits for all entry input and entry output streams to close or forces them to close, dependending on the options.

Parameters:
options - the output options.
handler - the exception handler.
Throws:
FsSyncException - If any exceptional condition occurs throughout the processing of the container archive file.
X extends IOException

commenceSync

private <X extends IOException> void commenceSync(ExceptionHandler<? super FsSyncException,X> handler)
                   throws X extends IOException
Closes and disconnects all entry streams of the output and input archive.

Parameters:
handler - the exception handler.
Throws:
FsSyncException - If any exceptional condition occurs throughout the processing of the container archive file.
X extends IOException

performSync

private <X extends IOException> void performSync(ExceptionHandler<? super FsSyncException,X> handler)
                  throws X extends IOException
Synchronizes all entries in the (virtual) archive file system with the (temporary) output archive file.

Parameters:
handler - the exception handler.
Throws:
IOException - If any exceptional condition occurs throughout the processing of the container archive file.

copy

private static <E extends FsArchiveEntry,X extends IOException> void copy(FsArchiveFileSystem<E> fileSystem,
                                                                          InputService<E> input,
                                                                          OutputService<E> output,
                                                                          ExceptionHandler<IOException,X> handler)
                  throws X extends IOException
Throws:
X extends IOException

commitSync

private <X extends IOException> void commitSync(ExceptionHandler<? super FsSyncException,X> handler)
                 throws X extends IOException
Discards the file system and closes the output and input archive.

Parameters:
handler - the exception handler.
Throws:
FsSyncException - If any exceptional condition occurs throughout the processing of the container archive file.
X extends IOException

isTouched

private boolean isTouched()

TrueZIP Kernel 7.0-rc1

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