net.sf.asyncobjects.io.util
Class ExhaustingInput<D extends BatchedData<D>,I extends AInput<D>>

java.lang.Object
  extended by net.sf.asyncobjects.AsyncUnicastServer<FacetType>
      extended by net.sf.asyncobjects.util.CloseableWrapper<I,I>
          extended by net.sf.asyncobjects.io.util.ExhaustingInput<D,I>
Type Parameters:
D - a batched data type
I - an input type
All Implemented Interfaces:
ACloseable, AsyncObject, ExplicitSharing, AInput<D>
Direct Known Subclasses:
ExhaustingByteInput, ExhaustingTextInput

public class ExhaustingInput<D extends BatchedData<D>,I extends AInput<D>>
extends CloseableWrapper<I,I>
implements AInput<D>

This input waits until stream is fully readed. The stream is fully reads out the stream on the close. This class is required for some protocol implementations.

Note that the exhausted() promise is resolved the first time EOF is reached. Because AInput.pushback(net.sf.asyncobjects.io.BatchedData) methods could reverse this condition, the class handles pushbacks itself.

Author:
const

Nested Class Summary
 
Nested classes/interfaces inherited from class net.sf.asyncobjects.util.CloseableWrapper
CloseableWrapper.InvalidatingWhen<I,R>
 
Field Summary
 
Fields inherited from class net.sf.asyncobjects.util.CloseableWrapper
closeWrapper, requests, wrapped
 
Constructor Summary
ExhaustingInput(D empty, I stream, boolean closeStream)
          A construcor
 
Method Summary
protected  void afterInvalidate(Throwable problem)
          Perform additional invalidation for the stream.
protected  Promise<Void> beforeClose()
          Handle close operation
 Promise<Void> exhausted()
           
 Promise<Boolean> isPushbackSupported()
           
 Promise<Void> pushback(D data)
          Pushback
 Promise<D> read(int limit)
          Read data
 
Methods inherited from class net.sf.asyncobjects.util.CloseableWrapper
close, closed, ensureOpen, ensureValid, invalidate, 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.ACloseable
close
 
Methods inherited from interface net.sf.asyncobjects.AsyncObject
dereference, isImmediate
 

Constructor Detail

ExhaustingInput

public ExhaustingInput(D empty,
                       I stream,
                       boolean closeStream)
A construcor

Parameters:
empty - a empty data
stream - a stream
closeStream - if true stream is closed
Method Detail

exhausted

public Promise<Void> exhausted()
Returns:
a promise for the exhaused indicator. It resolves when failure encountered or when stream is completely read.

read

public Promise<D> read(int limit)
Read data

Specified by:
read in interface AInput<D extends BatchedData<D>>
Parameters:
limit - a limit for data to read
Returns:
a promise for read data
See Also:
AInput.read(int)

beforeClose

protected Promise<Void> beforeClose()
Description copied from class: CloseableWrapper
Handle close operation

Overrides:
beforeClose in class CloseableWrapper<I extends AInput<D>,I extends AInput<D>>
Returns:
a promise that resolves when handling close is finished
See Also:
CloseableWrapper.beforeClose()

afterInvalidate

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

Overrides:
afterInvalidate in class CloseableWrapper<I extends AInput<D>,I extends AInput<D>>
Parameters:
problem - a problem.
See Also:
CloseableWrapper.afterInvalidate(java.lang.Throwable)

isPushbackSupported

public Promise<Boolean> isPushbackSupported()
Specified by:
isPushbackSupported in interface AInput<D extends BatchedData<D>>
Returns:
true if pushback supported for this stream
See Also:
AInput.isPushbackSupported()

pushback

public Promise<Void> pushback(D data)
Pushback

Specified by:
pushback in interface AInput<D extends BatchedData<D>>
Parameters:
data - a data to push back
Returns:
when pushback finishes
See Also:
AInput.pushback(net.sf.asyncobjects.io.BatchedData)


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