Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## things.thinger.io
Class StreamSourceFromStreamStalled

    java.lang.Object
      things.thinger.io.StreamSourceFromStreamStalled

All Implemented Interfaces:
  StreamSource

    public class StreamSourceFromStreamStalled

extends java.lang.Object
implements StreamSource

A character stream source. It will tee a single character, so be sure the underlying stream will starve it (pass EOF) if it should cross a barrier and read something it isn't allowed to have. See the HeaderProcessor for an example of how to do this.

I had to add this one to deal with socket streams, where you don't really know if you are at the end or not. It will treat no available bytes the same as EOF. This means it is somewhat sensitive to truncation on slow pipes. There is a slight delay given if the available count is 0 just to see if something shows up.

I really upped the delays, because network connections can seriously lag. It's a pain. The initial delay will always be way longer than subsequent reads.

Why not use timeouts, you ask? We really don't know what kind of stream we are getting. In all, a proper implementation would probably deal directly with the channels and leave the layers stream abstractions out of it. Since this is just a tool, I'm not going to bother. Unfortunately, it makes the mini-http server a little slow.

Version:
  1.0

  Version History

       EPG - Initial (toolkit) - 7 SEP 03
       EPG - Played with the delays - 10 MAY 07

Author:
  Erich P. Gatejen

Field Summary
`static int` | `INIT_STALL_PERIOD` This is the stall period in millis for the initialization.
`static int` | `INIT_STALL_RAMP` This is how much we increase the stall period for every iteration.
`static int` | `MAX_INIT_STALL` Maximum stall period for the initialization.
`static int` | `STALL_PERIOD` This is the stall period in millis.
`static int` | `STALL_RETRIES` Maximum stall period for the initialization.

Constructor Summary
`StreamSourceFromStreamStalled()` A null constructor.
`StreamSourceFromStreamStalled(java.io.InputStream source)` Constructor.

Method Summary
`int` | `available()` It'll try a few times until something is available or it runs out of time.
`boolean` | `hasMore()` Does the source have more to get?
`int` | `next()` Get the next character.
`void` | `reuse(java.io.InputStream source)` Reuse this object but with another stream.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### INIT_STALL_PERIOD

    public static final int INIT_STALL_PERIOD

  This is the stall period in millis for the initialization. It will be retried so many times. I don't really know the best value for this.

  See Also:
    Constant Field Values

### INIT_STALL_RAMP

    public static final int INIT_STALL_RAMP

  This is how much we increase the stall period for every iteration.

  See Also:
    Constant Field Values

### MAX_INIT_STALL

    public static final int MAX_INIT_STALL

  Maximum stall period for the initialization. After this, give up.

  See Also:
    Constant Field Values

### STALL_PERIOD

    public static final int STALL_PERIOD

  This is the stall period in millis. It will be retried so many times. I don't really know the best value for this.

  See Also:
    Constant Field Values

### STALL_RETRIES

    public static final int STALL_RETRIES

  Maximum stall period for the initialization. After this, give up.

  See Also:
    Constant Field Values

Constructor Detail

### StreamSourceFromStreamStalled

    public StreamSourceFromStreamStalled()

  A null constructor. You must call reuse() before the other methods or they will throw exceptions.

### StreamSourceFromStreamStalled

    public StreamSourceFromStreamStalled(java.io.InputStream source)
                                  throws java.lang.Throwable

  Constructor. Pass the stream to source.

  Parameters:
    `source` - the input stream source.
  Throws:
    `java.lang.Throwable`

Method Detail

### reuse

    public void reuse(java.io.InputStream source)
               throws java.lang.Throwable

  Reuse this object but with another stream. Since we anticipate using a lot of these, this should spare some heap thrash.

  Parameters:
    `source` - The input stream source.
  Throws:
    `java.lang.Exception`
    `java.lang.Throwable`

### next

    public int next()
             throws java.lang.Exception

  Get the next character. It'll throw an EOFException if there is nothing left. This

  This treats the available < 0 as EOF.

  Specified by:
    `next` in interface `StreamSource`
  Returns:
    the next character
  Throws:
    `java.lang.Exception`

### available

    public int available()
                  throws java.lang.Exception

  It'll try a few times until something is available or it runs out of time.

  Returns:
    the number available.
  Throws:
    `java.lang.Exception`

### hasMore

    public boolean hasMore()
                    throws java.lang.Exception

  Does the source have more to get?

  Specified by:
    `hasMore` in interface `StreamSource`
  Returns:
    true if it does, otherwise false.
  Throws:
    `java.lang.Exception`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Things.