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

java.lang.Object
  extended by net.sf.asyncobjects.AsyncUnicastServer<I>
      extended by net.sf.asyncobjects.io.util.GeneratingInput<D,I>
Type Parameters:
D - a batched data type
I - a facet type
All Implemented Interfaces:
ACloseable, AsyncObject, ExplicitSharing, AInput<D>
Direct Known Subclasses:
RandomByteInput, RandomTextInput, RepeatingInput

public abstract class GeneratingInput<D extends BatchedData<D>,I extends AInput<D>>
extends AsyncUnicastServer<I>
implements AInput<D>

A input that generates some data.

Author:
const

Field Summary
static long UNLIMITED
          a unlimited value
 
Constructor Summary
GeneratingInput()
          A consructor
GeneratingInput(long toGenerate)
          A consructor
 
Method Summary
 Promise<Void> close()
          Close resource
protected abstract  D generate(int limit)
          Generate at most limit of the data
 Promise<Long> generated()
           
 Promise<Boolean> isPushbackSupported()
           
 Promise<Void> pushback(D data)
          Attempt to return some data to stream.
 Promise<D> read(int limit)
          Read some data.
 
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

UNLIMITED

public static final long UNLIMITED
a unlimited value

See Also:
Constant Field Values
Constructor Detail

GeneratingInput

public GeneratingInput()
A consructor


GeneratingInput

public GeneratingInput(long toGenerate)
A consructor

Parameters:
toGenerate - amount element to generate
Method Detail

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)
Description copied from interface: AInput
Attempt to return some data to stream. Most streams do not support this operation. Note that pushback operation has the same priority as read operation.

Specified by:
pushback in interface AInput<D extends BatchedData<D>>
Parameters:
data - a data to unread.
Returns:
a promise for null or exception if stream does not supports unreading.
See Also:
AInput.pushback(net.sf.asyncobjects.io.BatchedData)

read

public Promise<D> read(int limit)
Description copied from interface: AInput
Read some data.

Specified by:
read in interface AInput<D extends BatchedData<D>>
Parameters:
limit - a maximum amount of data elements to read.
Returns:
Promise for non-empty data batch that contains read inforation or null if eof is reached.
See Also:
AInput.read(int)

generate

protected abstract D generate(int limit)
Generate at most limit of the data

Parameters:
limit - a limit on generated data
Returns:
a generated data

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()

generated

public Promise<Long> generated()
Returns:
a promise that resolves when stream is closed with amount of generated bytes.


Copyright 2002-2007 Constantine Plotnikov. All Rights Reserved.