TrueZIP Kernel 7.0-rc2

de.schlichtherle.truezip.socket
Class ConcurrentInputShop<E extends Entry>

java.lang.Object
  extended by de.schlichtherle.truezip.entry.DecoratingEntryContainer<E,I>
      extended by de.schlichtherle.truezip.socket.DecoratingInputShop<E,InputShop<E>>
          extended by de.schlichtherle.truezip.socket.ConcurrentInputShop<E>
Type Parameters:
E - The type of the entries.
All Implemented Interfaces:
EntryContainer<E>, InputService<E>, InputShop<E>, Closeable, Iterable<E>
Direct Known Subclasses:
FsDefaultArchiveController.Input

@ThreadSafe
public class ConcurrentInputShop<E extends Entry>
extends DecoratingInputShop<E,InputShop<E>>

Decorates an InputShop to add accounting and multithreading synchronization for all input streams or read only files created by the decorated input shop.

Author:
Christian Schlichtherle
See Also:
ConcurrentOutputShop

Nested Class Summary
private  class ConcurrentInputShop.ConcurrentInputStream
           
private  class ConcurrentInputShop.ConcurrentReadOnlyFile
           
private  class ConcurrentInputShop.SynchronizedConcurrentInputStream
           
private  class ConcurrentInputShop.SynchronizedConcurrentReadOnlyFile
           
 
Field Summary
private static String CLASS_NAME
           
private  boolean closed
           
private static Logger logger
           
private  Map<Closeable,Thread> threads
          The pool of all open entry streams.
 
Fields inherited from class de.schlichtherle.truezip.entry.DecoratingEntryContainer
delegate
 
Constructor Summary
ConcurrentInputShop(InputShop<E> input)
          Constructs a concurrent input shop.
 
Method Summary
private  void assertNotShopClosed()
          Needs to be externally synchronized!
 void close()
          Closes this concurrent output shop.
<E extends Exception>
void
closeAll(ExceptionHandler<IOException,E> handler)
          Closes and disconnects all entry input streams and read only file created by this concurrent input shop.
 InputSocket<? extends E> getInputSocket(String name)
          Returns an input socket for read access to the given entry.
private  int threadStreams()
          Returns the number of streams opened by the current thread.
 int waitCloseOthers(long timeout)
          Waits until all entry input streams and read only files which have been opened by other threads get closed or a timeout occurs.
 
Methods inherited from class de.schlichtherle.truezip.entry.DecoratingEntryContainer
getEntry, getSize, iterator, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface de.schlichtherle.truezip.entry.EntryContainer
getEntry, getSize, iterator
 

Field Detail

CLASS_NAME

private static final String CLASS_NAME

logger

private static final Logger logger

threads

private final Map<Closeable,Thread> threads
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. 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 InputBusyException in case a sloppy client application has forgot to close a stream before this input shop gets closed.


closed

private volatile boolean closed
Constructor Detail

ConcurrentInputShop

public ConcurrentInputShop(InputShop<E> input)
Constructs a concurrent input shop.

Parameters:
input - the shop to decorate.
Throws:
NullPointerException - if input is null.
Method Detail

waitCloseOthers

public final int waitCloseOthers(long timeout)
Waits until all entry input streams and read only files which have been opened by other threads get 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.


closeAll

public final <E extends Exception> void closeAll(ExceptionHandler<IOException,E> handler)
                    throws E extends Exception
Closes and disconnects all entry input streams and read only file created by this concurrent input shop. Disconnecting means that any subsequent operation on the entry streams will throw an IOException, with the exception of their close() method.

Throws:
E extends Exception

close

public final void close()
                 throws IOException
Closes this concurrent output shop.

Specified by:
close in interface Closeable
Overrides:
close in class DecoratingInputShop<E extends Entry,InputShop<E extends Entry>>
Throws:
IllegalStateException - If any open input streams or read only files are detected.
IOException
See Also:
closeAll(de.schlichtherle.truezip.util.ExceptionHandler)

assertNotShopClosed

private void assertNotShopClosed()
                          throws IOException
Needs to be externally synchronized!

Throws:
IOException

getInputSocket

public final InputSocket<? extends E> getInputSocket(String name)
Description copied from interface: InputService
Returns an input socket for read access to the given entry.

Specified by:
getInputSocket in interface InputService<E extends Entry>
Overrides:
getInputSocket in class DecoratingInputShop<E extends Entry,InputShop<E extends Entry>>
Parameters:
name - a non-null entry name.
Returns:
An input socket for reading from the local target.

TrueZIP Kernel 7.0-rc2

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