minor refactorings to address Alec's feedback
This commit is contained in:
Родитель
edd91474d2
Коммит
b35dd140e1
|
@ -16,10 +16,15 @@ public class AsyncExample {
|
|||
// State to make the asynchronous getBuildsCurrent call
|
||||
private BuildsOperations buildsOperations;
|
||||
|
||||
// Initializes an http client, retrofit, and an ES client for autorest
|
||||
// Constructor creating a client using only the URL to the ES server
|
||||
public AsyncExample(String ESUrl)
|
||||
{
|
||||
EmbeddedSocialClientImpl esClient = new EmbeddedSocialClientImpl(ESUrl);
|
||||
this(new EmbeddedSocialClientImpl(ESUrl));
|
||||
}
|
||||
|
||||
// Constructor receiving a pre-created client
|
||||
public AsyncExample(EmbeddedSocialClientImpl esClient)
|
||||
{
|
||||
buildsOperations = esClient.getBuildsOperations();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package com.microsoft.test.embeddedsocial;
|
||||
|
||||
import com.microsoft.embeddedsocial.autorest.BuildsOperations;
|
||||
import com.microsoft.embeddedsocial.autorest.EmbeddedSocialBatchedClientImpl;
|
||||
import com.microsoft.embeddedsocial.autorest.EmbeddedSocialClientImpl;
|
||||
import com.microsoft.embeddedsocial.autorest.models.BuildsCurrentResponse;
|
||||
|
||||
/**
|
||||
* Created by ssaroiu on 3/6/2018.
|
||||
*/
|
||||
|
||||
public class BatchedExample {
|
||||
private EmbeddedSocialClientImpl esClient;
|
||||
|
||||
// Initializes an ES client that supports batching
|
||||
public BatchedExample(String ESUrl)
|
||||
{
|
||||
EmbeddedSocialBatchedClientImpl.Builder esBatchedClientBuilder = new EmbeddedSocialBatchedClientImpl.Builder().baseUrl(ESUrl);
|
||||
this.esClient = esBatchedClientBuilder.build().getEsClient();
|
||||
}
|
||||
|
||||
// Batches k requests into a single call to Embedded Social server
|
||||
public void run(int k) {
|
||||
for (int i = 0; i < k; i += 1) {
|
||||
AsyncExample asyncExample = new AsyncExample(this.esClient);
|
||||
asyncExample.run();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
package com.microsoft.test.embeddedsocial;
|
||||
|
||||
import com.microsoft.embeddedsocial.autorest.BuildsOperations;
|
||||
import com.microsoft.embeddedsocial.autorest.EmbeddedSocialBatchedClientImpl;
|
||||
import com.microsoft.embeddedsocial.autorest.EmbeddedSocialClientImpl;
|
||||
import com.microsoft.embeddedsocial.autorest.models.BuildsCurrentResponse;
|
||||
|
||||
/**
|
||||
* Created by ssaroiu on 3/6/2018.
|
||||
*/
|
||||
|
||||
public class BatchedSyncExample {
|
||||
// State to make the asynchronous getBuildsCurrent call
|
||||
private BuildsOperations buildsOperations;
|
||||
|
||||
// Initializes an http client, retrofit, and an ES client for autorest
|
||||
public BatchedSyncExample(String ESUrl)
|
||||
{
|
||||
EmbeddedSocialBatchedClientImpl.Builder esBatchedClientBuilder = new EmbeddedSocialBatchedClientImpl.Builder().baseUrl(ESUrl);
|
||||
EmbeddedSocialClientImpl esClient = esBatchedClientBuilder.build().getEsClient();
|
||||
buildsOperations = esClient.getBuildsOperations();
|
||||
}
|
||||
|
||||
// Makes a single synchronous call to getBuildsCurrent
|
||||
public void run() {
|
||||
String apiVersion = "N/A";
|
||||
|
||||
try {
|
||||
BuildsCurrentResponse buildsCurrent = buildsOperations.getBuildsCurrent().getBody();
|
||||
apiVersion = buildsCurrent.getServiceApiVersion();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.err.println("Call to Embedded Social failed with exception: " + e.getMessage());
|
||||
}
|
||||
|
||||
System.out.println("Batched synchronous call to ES completed. Returned API version: " + apiVersion);
|
||||
}
|
||||
|
||||
}
|
|
@ -11,13 +11,13 @@ public class Main {
|
|||
public static void main(String[] args) {
|
||||
SyncExample syncExample = new SyncExample(ESUrl);
|
||||
AsyncExample asyncExample = new AsyncExample(ESUrl);
|
||||
BatchedSyncExample batchedSyncExample = new BatchedSyncExample(ESUrl);
|
||||
BatchedExample batchedExample = new BatchedExample(ESUrl);
|
||||
|
||||
// syncExample makes single synchronous call
|
||||
syncExample.run();
|
||||
|
||||
// batchedSyncExample makes single batched synchronous call
|
||||
batchedSyncExample.run();
|
||||
batchedExample.run(1);
|
||||
|
||||
// asyncExample makes single asynchronous call
|
||||
asyncExample.run();
|
||||
|
|
Загрузка…
Ссылка в новой задаче