Skip to content

Commit a10139b

Browse files
authored
Merge pull request #354 from rpmoore/lazy_loader_documentation
Lazy loader documentation
2 parents 9d68b99 + 675c024 commit a10139b

File tree

5 files changed

+60
-4
lines changed

5 files changed

+60
-4
lines changed

docker/docker-compose.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,3 @@ services:
1919
- GIT_BRANCH
2020
dns:
2121
- 10.1.0.9
22-
23-
24-

ds3-sdk/src/main/java/com/spectralogic/ds3client/helpers/pagination/PaginatingCommand.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,25 @@
2121
import java.io.IOException;
2222
import java.util.List;
2323

24+
/**
25+
* This interface is used to implement the call specific logic for any Spectra S3 paginated request.
26+
* @param <E> The type the iterator will return.
27+
* @param <T> The {@link AbstractPaginationRequest} that the command will invoke
28+
* @param <F> The {@link AbstractPaginationResponse} that will be returned by the {@link AbstractPaginationRequest}
29+
*/
2430
public interface PaginatingCommand<E, T extends AbstractPaginationRequest, F extends AbstractPaginationResponse> {
31+
/**
32+
* Creates an initial request. This should not modify any of the pagination values for the request
33+
*/
2534
T createRequest();
35+
36+
/**
37+
* Invokes the request and returns the response
38+
*/
2639
F invokeCommand(final T paginationRequest) throws IOException;
40+
41+
/**
42+
* Parses the response into the correct payload to be consumed by the iterator
43+
*/
2744
List<E> getResponseContents(F response);
2845
}

ds3-sdk/src/main/java/com/spectralogic/ds3client/helpers/pagination/SpectraS3PaginationLoader.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@
2525
import java.util.Collections;
2626
import java.util.List;
2727

28+
/**
29+
* This class is used as the base implementation for all Spectra S3 paginating calls. It requires a {@link PaginatingCommand} which implements the
30+
* call specific logic for each paginated request.
31+
* @param <T> The type returned by the iterator
32+
* @param <E> The {@link com.spectralogic.ds3client.commands.interfaces.AbstractPaginationRequest} this loader will invoke
33+
* @param <F> The {@link com.spectralogic.ds3client.commands.interfaces.AbstractPaginationResponse} that the {@link com.spectralogic.ds3client.commands.interfaces.AbstractPaginationRequest} will return.
34+
*/
2835
public class SpectraS3PaginationLoader<T, E extends AbstractPaginationRequest, F extends AbstractPaginationResponse> implements LazyIterable.LazyLoader<T> {
2936

3037
private final PaginatingCommand<T, E, F> paginatingCommand;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* ******************************************************************************
3+
* Copyright 2014-2016 Spectra Logic Corporation. All Rights Reserved.
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
5+
* this file except in compliance with the License. A copy of the License is located at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* or in the "license" file accompanying this file.
10+
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
12+
* specific language governing permissions and limitations under the License.
13+
* ****************************************************************************
14+
*/
15+
16+
/**
17+
* This package contains many base implementations for supporting Spectra S3 calls that
18+
* can be paginated.
19+
*/
20+
package com.spectralogic.ds3client.helpers.pagination;
21+

ds3-sdk/src/main/java/com/spectralogic/ds3client/utils/collections/LazyIterable.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
* Produces an Iterator that will lazily load content.
2626
* Our definition of lazy for this class, is that the Iterator is returned right
2727
* away with no data. Data is only then loaded, as needed, in pieces as defined by the LazyIterableLoader.
28+
*
29+
* To use, supply a {@link LazyLoaderFactory} which is used to fetch data as it is needed.
2830
*/
2931
public class LazyIterable<T> implements Iterable<T> {
3032

@@ -39,10 +41,23 @@ public Iterator<T> iterator() {
3941
return new LazyObjectIterator<>(lazyLoaderFactory.create());
4042
}
4143

44+
/**
45+
* A factory that creates instances of LazyLoaders. It's important that this factory
46+
* does not return the same loader, otherwise every iterator created with this factory
47+
* will share the same state and can lead to undefined behavior.
48+
* @param <T> The model that is returned by the iterator
49+
*/
4250
public interface LazyLoaderFactory<T> {
4351
LazyLoader<T> create();
4452
}
4553

54+
/**
55+
* A loader is responsible for returning new data on each call to {@link LazyLoader#getNextValues()}.
56+
*
57+
* If using a Spectra S3 API call see {@link com.spectralogic.ds3client.helpers.pagination.SpectraS3PaginationLoader}
58+
* as the base implementation to handle most of the details of creating a new LazyLoader
59+
* @param <T> The model that is returned by the iterator
60+
*/
4661
public interface LazyLoader<T> {
4762
List<T> getNextValues();
4863
}
@@ -97,6 +112,5 @@ private void loadCache() {
97112
public void remove() {
98113
throw new UnsupportedOperationException("The remove method on the LazyObjectIterator is not supported");
99114
}
100-
101115
}
102116
}

0 commit comments

Comments
 (0)