Skip to content

Commit aabdb9f

Browse files
committed
Merge pull request #20 from hansdude/master
Added api to helpers to control max parallelism.
2 parents b6c41e5 + ac55363 commit aabdb9f

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

src/main/java/com/spectralogic/ds3client/helpers/Ds3ClientHelpers.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ public interface WriteJob extends Job {
9191
* Note that it's possible for the {@code modifier} to be called simultaneously from multiple threads.
9292
*/
9393
public WriteJob withRequestModifier(PutRequestModifier modifier);
94+
95+
/**
96+
* Sets the maximum number of requests to execute at a time when fulfilling the job.
97+
*/
98+
public WriteJob withMaxParallelRequests(int maxParallelRequests);
9499
}
95100

96101
public interface ReadJob extends Job {
@@ -109,6 +114,11 @@ public interface ReadJob extends Job {
109114
* Note that it's possible for the {@code modifier} to be called simultaneously from multiple threads.
110115
*/
111116
public ReadJob withRequestModifier(GetRequestModifier modifier);
117+
118+
/**
119+
* Sets the maximum number of requests to execute at a time when fulfilling the job.
120+
*/
121+
public ReadJob withMaxParallelRequests(int maxParallelRequests);
112122
}
113123

114124
/**

src/main/java/com/spectralogic/ds3client/helpers/JobImpl.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import com.spectralogic.ds3client.serializer.XmlProcessingException;
3636

3737
abstract class JobImpl implements Job {
38-
private static final int THREAD_COUNT = 10;
38+
private int maxParallelRequests = 20;
3939

4040
private final Ds3ClientFactory clientFactory;
4141
private final UUID jobId;
@@ -63,6 +63,10 @@ public String getBucketName() {
6363
return this.bucketName;
6464
}
6565

66+
protected void setMaxParallelRequests(final int maxParallelRequests) {
67+
this.maxParallelRequests = maxParallelRequests;
68+
}
69+
6670
interface Transferrer {
6771
public void Transfer(Ds3Client client, UUID jobId, String bucketName, Ds3Object ds3Object)
6872
throws SignatureException, IOException;
@@ -77,7 +81,7 @@ protected void transferAll(final Transferrer transferrer)
7781

7882
private void transferObjects(final Transferrer transferrer, final Objects objects)
7983
throws SignatureException, IOException, XmlProcessingException {
80-
final ListeningExecutorService service = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(THREAD_COUNT));
84+
final ListeningExecutorService service = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(this.maxParallelRequests));
8185
try {
8286
final Ds3Client client = this.clientFactory.GetClientForServerId(objects.getServerId());
8387
final List<ListenableFuture<?>> tasks = new ArrayList<>();

src/main/java/com/spectralogic/ds3client/helpers/ReadJobImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,10 @@ public ReadJob withRequestModifier(final GetRequestModifier modifier) {
7070
this.modifier = modifier;
7171
return this;
7272
}
73+
74+
@Override
75+
public ReadJob withMaxParallelRequests(final int maxParallelRequests) {
76+
this.setMaxParallelRequests(maxParallelRequests);
77+
return this;
78+
}
7379
}

src/main/java/com/spectralogic/ds3client/helpers/WriteJobImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,10 @@ public WriteJob withRequestModifier(final PutRequestModifier modifier) {
6969
this.modifier = modifier;
7070
return this;
7171
}
72+
73+
@Override
74+
public WriteJob withMaxParallelRequests(final int maxParallelRequests) {
75+
this.setMaxParallelRequests(maxParallelRequests);
76+
return this;
77+
}
7278
}

0 commit comments

Comments
 (0)