forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89fc914
commit ac061a5
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
azure-client-runtime/src/main/java/com/microsoft/azure/ParallelServiceCall.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.microsoft.azure; | ||
|
||
import com.microsoft.rest.ServiceCall; | ||
|
||
import java.util.concurrent.ConcurrentLinkedQueue; | ||
|
||
/** | ||
* Type represents a set of REST calls running possibly in parallel. | ||
*/ | ||
public class ParallelServiceCall<T> extends ServiceCall<T> { | ||
private ConcurrentLinkedQueue<ServiceCall<?>> serviceCalls; | ||
|
||
/** | ||
* Creates a ParallelServiceCall. | ||
*/ | ||
public ParallelServiceCall() { | ||
super(null); | ||
this.serviceCalls = new ConcurrentLinkedQueue<>(); | ||
} | ||
|
||
/** | ||
* Cancels all the service calls currently executing. | ||
*/ | ||
public void cancel() { | ||
for (ServiceCall<?> call : this.serviceCalls) { | ||
call.cancel(); | ||
} | ||
} | ||
|
||
/** | ||
* @return true if the call has been canceled; false otherwise. | ||
*/ | ||
public boolean isCancelled() { | ||
for (ServiceCall<?> call : this.serviceCalls) { | ||
if (!call.isCanceled()) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* Add a call to the list of parallel calls. | ||
* | ||
* @param call the call | ||
*/ | ||
public void addCall(ServiceCall<?> call) { | ||
this.serviceCalls.add(call); | ||
} | ||
} |