net.sf.asyncobjects.util
Class CloseableWrapper<FacetType extends ACloseable,WrappedType extends ACloseable>

java.lang.Object
  extended by net.sf.asyncobjects.AsyncUnicastServer<FacetType>
      extended by net.sf.asyncobjects.util.CloseableWrapper<FacetType,WrappedType>
Type Parameters:
FacetType - A facet stream type
WrappedType - A wrapped stream type
All Implemented Interfaces:
ACloseable, AsyncObject, ExplicitSharing
Direct Known Subclasses:
BoundedInput, DecoderTextInput, EncoderTextOutput, ExhaustingInput, SavingInput, UncloseableInput

public abstract class CloseableWrapper<FacetType extends ACloseable,WrappedType extends ACloseable>
extends AsyncUnicastServer<FacetType>
implements ACloseable

This is a base class for closeables that built upon other closeable objects. The class is mostly used of for IO. However it could be useful for implementing other resources that implement ACloseable interface.

Author:
const

Nested Class Summary
protected  class CloseableWrapper.InvalidatingWhen<I,R>
          When that invalidates the stream in case of exception
 
Field Summary
protected  boolean closeWrapper
          if true, inner stream should be closed
protected  RequestQueue requests
          a request queue
protected  WrappedType wrapped
          wrapped closeable
 
Constructor Summary
CloseableWrapper(WrappedType stream, boolean closeWrapper)
          A constructor
 
Method Summary
protected  void afterInvalidate(Throwable problem)
          Perform additional invalidation for the stream.
protected  Promise<Void> beforeClose()
          Handle close operation
 Promise<Void> close()
          Close resource
 Promise<Void> closed()
           
protected  void ensureOpen()
          Ensure that stream is open
protected  void ensureValid()
          Ensure that stream is valid.
protected  void invalidate(Throwable problem)
          Invalidate the closeable
protected  boolean isValid()
           
 
Methods inherited from class net.sf.asyncobjects.AsyncUnicastServer
dereference, export, isImmediate, myVat, promise
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.asyncobjects.AsyncObject
dereference, isImmediate
 

Field Detail

requests

protected final RequestQueue requests
a request queue


wrapped

protected final WrappedType extends ACloseable wrapped
wrapped closeable


closeWrapper

protected final boolean closeWrapper
if true, inner stream should be closed

Constructor Detail

CloseableWrapper

public CloseableWrapper(WrappedType stream,
                        boolean closeWrapper)
A constructor

Parameters:
stream - inner stream to work with
closeWrapper - if true inner stream will be closed when close operation executed.
Method Detail

closed

public Promise<Void> closed()
Returns:
a promise that resolves when stream is closed

close

public Promise<Void> close()
Description copied from interface: ACloseable
Close resource

Specified by:
close in interface ACloseable
Returns:
a promise that resolves when object is closed.
See Also:
ACloseable.close()

ensureValid

protected final void ensureValid()
Ensure that stream is valid.


ensureOpen

protected final void ensureOpen()
Ensure that stream is open


afterInvalidate

protected void afterInvalidate(Throwable problem)
Perform additional invalidation for the stream. Override this method to perform additional invalidation. If the method throws an exception, it is logged and ignored.

Parameters:
problem - a problem.

beforeClose

protected Promise<Void> beforeClose()
                             throws Throwable
Handle close operation

Returns:
a promise that resolves when handling close is finished
Throws:
Throwable - if there is aproblem during execution

invalidate

protected final void invalidate(Throwable problem)
Invalidate the closeable

Parameters:
problem - a problem that caused invalidation or null

isValid

protected boolean isValid()
Returns:
true if the object is still valid


Copyright © 2002-2007 Constantine Plotnikov. All Rights Reserved.