TrueZIP Kernel 7.0-rc2

de.schlichtherle.truezip.socket
Class IOCache

java.lang.Object
  extended by de.schlichtherle.truezip.socket.IOCache

@ThreadSafe
@DefaultAnnotation(value=edu.umd.cs.findbugs.annotations.NonNull.class)
public final class IOCache
extends Object

Provides temporary caching services for input and output sockets with the following features:

Author:
Christian Schlichtherle

Nested Class Summary
private  class IOCache.Buffer
           
private static class IOCache.CacheEntry
          Proxies the decorated entry to hide socket connections.
private  class IOCache.CacheInputSocket
           
private  class IOCache.CacheOutputSocket
           
private  class IOCache.InputBufferPool
           
private static class IOCache.Lock
           
private  class IOCache.OutputBufferPool
           
static class IOCache.Strategy
          Provides different cache strategies.
private  class IOCache.WriteBackOutputBufferPool
           
private  class IOCache.WriteThroughOutputBufferPool
           
 
Field Summary
private  IOCache.Buffer buffer
           
private  InputSocket<?> input
           
private  IOCache.InputBufferPool inputBufferPool
           
private  IOCache.Lock lock
           
private  OutputSocket<?> output
           
private  IOCache.OutputBufferPool outputBufferPool
           
private  IOPool<?> pool
           
private  IOCache.Strategy strategy
           
 
Constructor Summary
private IOCache(IOCache.Strategy strategy, IOPool<?> pool)
          Constructs a new cache which applies the given caching strategy and uses the given pool to allocate and release temporary I/O entries.
 
Method Summary
 IOCache clear()
          Discards the entry data in this buffer.
 IOCache configure(InputSocket<?> input)
          Configures the input socket for reading the entry data from the backing store.
 IOCache configure(OutputSocket<?> output)
          Configures the output socket for writing the entry data to the backing store.
protected  void finalize()
           
 IOCache flush()
          Writes the cached entry data to the backing store unless already done.
private  IOCache.Buffer getBuffer()
           
 Entry getEntry()
           
private  IOCache.InputBufferPool getInputBufferPool()
           
 InputSocket<?> getInputSocket()
          Returns an input socket for reading the cached entry data.
private  IOCache.OutputBufferPool getOutputBufferPool()
           
 OutputSocket<?> getOutputSocket()
          Returns an output socket for writing the cached entry data.
private  void setBuffer(IOCache.Buffer newBuffer)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lock

private final IOCache.Lock lock

strategy

private final IOCache.Strategy strategy

pool

private final IOPool<?> pool

input

@Nullable
private volatile InputSocket<?> input

output

@Nullable
private volatile OutputSocket<?> output

inputBufferPool

@CheckForNull
private volatile IOCache.InputBufferPool inputBufferPool

outputBufferPool

@CheckForNull
private volatile IOCache.OutputBufferPool outputBufferPool

buffer

@CheckForNull
private volatile IOCache.Buffer buffer
Constructor Detail

IOCache

private IOCache(IOCache.Strategy strategy,
                IOPool<?> pool)
Constructs a new cache which applies the given caching strategy and uses the given pool to allocate and release temporary I/O entries.

Note that you need to call configure(InputSocket) before you can do any input. Likewise, you need to call configure(OutputSocket) before you can do any output.

Parameters:
strategy - the caching strategy.
pool - the pool for allocating and releasing temporary I/O entries.
Method Detail

configure

public IOCache configure(InputSocket<?> input)
Configures the input socket for reading the entry data from the backing store. This method needs to be called before any input can be done - otherwise a NullPointerException will be thrown on the first read attempt. Note that calling this method does not clear this cache.

Parameters:
input - an input socket for reading the entry data from the backing store.
Returns:
this

configure

public IOCache configure(OutputSocket<?> output)
Configures the output socket for writing the entry data to the backing store. This method needs to be called before any output can be done - otherwise a NullPointerException will be thrown on the first write attempt. Note that calling this method does not flush this cache.

Parameters:
output - an output socket for writing the entry data to the backing store.
Returns:
this

flush

public IOCache flush()
              throws IOException
Writes the cached entry data to the backing store unless already done. Whether or not this method needs to be called depends on the caching strategy. E.g. the caching strategy IOCache.Strategy.WRITE_THROUGH writes any changed entry data immediately, so calling this method has no effect.

Returns:
this
Throws:
IOException

clear

public IOCache clear()
              throws IOException
Discards the entry data in this buffer.

Returns:
this
Throws:
IOException

getEntry

@Nullable
public Entry getEntry()

getInputSocket

public InputSocket<?> getInputSocket()
Returns an input socket for reading the cached entry data.

Returns:
An input socket for reading the cached entry data.

getOutputSocket

public OutputSocket<?> getOutputSocket()
Returns an output socket for writing the cached entry data.

Returns:
An output socket for writing the cached entry data.

getInputBufferPool

private IOCache.InputBufferPool getInputBufferPool()

getOutputBufferPool

private IOCache.OutputBufferPool getOutputBufferPool()

getBuffer

@CheckForNull
private IOCache.Buffer getBuffer()

setBuffer

private void setBuffer(@CheckForNull
                       IOCache.Buffer newBuffer)
                throws IOException
Throws:
IOException

finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable

TrueZIP Kernel 7.0-rc2

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