org.gcube.data.streams.delegates
Class MonitoredStream<E>

java.lang.Object
  extended by org.gcube.data.streams.LookAheadStream<E2>
      extended by org.gcube.data.streams.delegates.MonitoredStream<E>
Type Parameters:
E - the type of stream elements
All Implemented Interfaces:
Iterator<E>, Stream<E>

public class MonitoredStream<E>
extends LookAheadStream<E2>

A Stream that notifies an StreamListener of key iteration events.

Author:
Fabio Simeoni

Field Summary
 
Fields inherited from class org.gcube.data.streams.LookAheadStream
element, hasNext
 
Constructor Summary
MonitoredStream(Stream<E> stream, StreamListener listener)
          Creates an instance with a Stream and a StreamListener.
 
Method Summary
 void close()
          Closes the stream unconditionally, releasing any resources that it may be using.
protected  boolean delegateHasNext()
          Returns true if the underlying stream has more elements.
protected  E delegateNext()
          Returns an element of the underlying stream
 boolean isClosed()
          Returns true if the stream has been closed.
 URI locator()
          Returns the stream locator.
 void remove()
           
protected  Stream<E1> stream()
          Returns the underlying Stream.
 
Methods inherited from class org.gcube.data.streams.LookAheadStream
hasNext, next, setHandler
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MonitoredStream

public MonitoredStream(Stream<E> stream,
                       StreamListener listener)
                throws IllegalArgumentException
Creates an instance with a Stream and a StreamListener.

Parameters:
stream - the stream
listener - the listener
Throws:
IllegalArgumentException - if the stream or the listener are null
Method Detail

delegateNext

protected E delegateNext()
Description copied from class: LookAheadStream
Returns an element of the underlying stream

Specified by:
delegateNext in class LookAheadStream<E>
Returns:
the element

delegateHasNext

protected boolean delegateHasNext()
Description copied from class: LookAheadStream
Returns true if the underlying stream has more elements.

Specified by:
delegateHasNext in class LookAheadStream<E>
Returns:
true if the underlying stream has more elements

close

public void close()
Description copied from interface: Stream
Closes the stream unconditionally, releasing any resources that it may be using.

Subsequent invocations of this method have no effect.
Subsequents invocations of Stream.hasNext() return false.
Subsequent invocations of Stream.next() throw NoSuchElementExceptions.

Failures are logged by implementations and suppressed otherwise.

Specified by:
close in interface Stream<E>

stream

protected Stream<E1> stream()
Returns the underlying Stream.

Returns:
the stream

locator

public URI locator()
            throws IllegalStateException
Description copied from interface: Stream
Returns the stream locator.

Returns:
the locator
Throws:
IllegalStateException - if the stream is no longer addressable at the time of invocation.

remove

public void remove()

isClosed

public boolean isClosed()
Description copied from interface: Stream
Returns true if the stream has been closed.

Returns:
true if the stream has been closed


Copyright © 2012. All Rights Reserved.