Skip to content

Commit

Permalink
Adding javadocs to new public API pieces
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmoore committed Nov 15, 2016
1 parent ac3d7e2 commit 78c43f1
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/basho/riak/client/api/RiakClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
* </ul>
* @author Dave Rusek <drusek at basho dot com>
* @author Brian Roach <roach at basho dot com>
* @author Alex Moore <amoore at basho.com>
* @author Sergey Galkin <srggal at gmail dot com>
* @since 2.0
*/
Expand Down Expand Up @@ -433,6 +434,7 @@ public <T,S> RiakFuture<T,S> executeAsync(RiakCommand<T,S> command)
* the result iterator can block the consuming thread from seeing the done()
* status until the timeout is reached.
* @return a RiakFuture for the operation
* @since 2.1.0
* @see RiakFuture
*/
public <I extends StreamableRiakCommand.StreamableResponse,S> RiakFuture<I,S> executeAsyncStreaming(StreamableRiakCommand<I, S, ?, ?> command, int timeoutMS)
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/com/basho/riak/client/api/StreamableRiakCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
* @param <S> The response type returned by "streaming mode" {@link executeAsyncStreaming}
* @param <R> The response type returned by the "batch mode" @{link executeAsync}
* @param <I> The query info type
* @author Dave Rusek
* @author Brian Roach <roach at basho.com>
* @author Alex Moore <amoore at basho.com>
* @author Sergey Galkin <srggal at gmail dot com>
* @since 2.0
*/
Expand Down Expand Up @@ -65,11 +64,27 @@ protected StreamableResponse()
{
}

/**
* Whether the results are to be streamed back.
* If true, results will appear in this class's iterator.
* If false, they will appear in the original result collection.
* @return true if the results are to be streamed.
*/
public boolean isStreamable()
{
return chunkedResponseIterator != null;
}

/**
* Get an iterator over the result data.
*
* If using the streaming API, this method will block
* and wait for more data if none is immediately available.
* It is also advisable to check {@link Thread#isInterrupted()}
* in environments where thread interrupts must be obeyed.
*
* @return an iterator over the result data.
*/
@Override
public Iterator<T> iterator() {
if (isStreamable()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@
import java.util.concurrent.TransferQueue;
import java.util.function.Function;

/**
* Transforms a stream of response chunks to a Iterable of response items.
*
* When iterating over this class's {@link Iterator} this class will lazily walk
* through the response chunks's iterators and convert the items.
* It will also wait for more response chunks if none are available.
*
* Since this class polls for new "streaming" data, it is advisable
* to check {@link Thread#isInterrupted()} while using this class's
* {@link Iterator} in environments where thread interrupts must be obeyed.
*
* @param <FinalT> The final converted type that this class exposes as part of its iterator.
* @param <ChunkT> The type of the response chunks, contains an Iterable&lt;{@link CoreT}&gt;
* @param <CoreT> The raw response type, will get converted to {@link FinalT}.
* @author Alex Moore <amoore at basho.com>
* @author Sergey Galkin <srggal at gmail dot com>
* @since 2.1.0
*/
public class ChunkedResponseIterator<FinalT, ChunkT extends Iterable<CoreT>, CoreT> implements Iterator<FinalT>
{
private final int timeout;
Expand Down Expand Up @@ -62,6 +80,19 @@ public ChunkedResponseIterator(StreamingRiakFuture<ChunkT, ?> coreFuture,
hasNext();
}

/**
* Returns {@code true} if the iteration has more elements.
* (In other words, returns {@code true} if {@link #next} would
* return an element rather than throwing an exception.)
*
* This method will block and wait for more data if none is immediately available.
*
* <b>Riak Java Client Note:</b> Since this class polls for
* new "streaming" data, it is advisable to check {@link Thread#isInterrupted()}
* in environments where thread interrupts must be obeyed.
*
* @return {@code true} if the iteration has more elements
*/
@Override
public boolean hasNext()
{
Expand Down Expand Up @@ -109,16 +140,37 @@ private boolean possibleChunksRemaining()
return !coreFuture.isDone() || !chunkQueue.isEmpty();
}

/**
* Returns whether this response contains a continuation.
* Only run this once the operation is complete, otherwise it will return true as it's
* @return Whether this response has a continuation.
*/
public boolean hasContinuation()
{
return continuation != null || possibleChunksRemaining();
}

/**
* Returns the current value of the continuation.
* Only run this once the operation is complete, or else you will get a null value.
* @return The continuation value (if any).
*/
public BinaryValue getContinuation()
{
return continuation;
}

/**
* Returns the next element in the iteration.
* This method will block and wait for more data if none is immediately available.
*
* <b>Riak Java Client Note:</b> Since this class polls for
* new "streaming" data, it is advisable to check {@link Thread#isInterrupted()}
* in environments where thread interrupts must be obeyed.
*
* @return the next element in the iteration
* @throws NoSuchElementException if the iteration has no more elements
*/
@Override
public FinalT next()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,19 @@ private class MapReduceResponseIterator implements Iterator<Response>
this.pollTimeout = pollTimeout;
}

/**
* Returns {@code true} if the iteration has more elements.
* (In other words, returns {@code true} if {@link #next} would
* return an element rather than throwing an exception.)
*
* This method will block and wait for more data if none is immediately available.
*
* <b>Riak Java Client Note:</b> Since this class polls for
* new "streaming" data, it is advisable to check {@link Thread#isInterrupted()}
* in environments where thread interrupts must be obeyed.
*
* @return {@code true} if the iteration has more elements
*/
@Override
public boolean hasNext()
{
Expand Down Expand Up @@ -478,6 +491,17 @@ private boolean peekWaitForNextQueueEntry() throws InterruptedException
return !resultsQueue.isEmpty();
}

/**
* Returns the next element in the iteration.
* This method will block and wait for more data if none is immediately available.
*
* <b>Riak Java Client Note:</b> Since this class polls for
* new "streaming" data, it is advisable to check {@link Thread#isInterrupted()}
* in environments where thread interrupts must be obeyed.
*
* @return the next element in the iteration
* @throws NoSuchElementException if the iteration has no more elements
*/
@Override
public Response next()
{
Expand Down

0 comments on commit 78c43f1

Please sign in to comment.