/** * Creates a blocking client with a configured default timeout for blocking requests. * The asynchronous calls won't have a timeout by default. * @param delegate underlying sphere client which may be initialized with the {@link SphereClientFactory}. * @param defaultTimeout the default maximum duration to wait (to block the thread) which should be greater than the timeout of the underlying HTTP client * @return wrapped client which can perform blocking calls. */ static BlockingSphereClient of(final SphereClient delegate, final Duration defaultTimeout) { return of(delegate, defaultTimeout.toMillis(), TimeUnit.MILLISECONDS); } }
/** * Creates a blocking client with a configured default timeout for blocking requests. * The asynchronous calls won't have a timeout by default. * @param delegate underlying sphere client which may be initialized with the {@link SphereClientFactory}. * @param defaultTimeout the default maximum duration to wait (to block the thread) which should be greater than the timeout of the underlying HTTP client * @return wrapped client which can perform blocking calls. */ static BlockingSphereClient of(final SphereClient delegate, final Duration defaultTimeout) { return of(delegate, defaultTimeout.toMillis(), TimeUnit.MILLISECONDS); } }
private BlockingSphereClient blockingClientOf(final SphereClient sphereClient) { return BlockingSphereClient.of(sphereClient, 500, TimeUnit.MILLISECONDS); } }
public static BlockingSphereClient clientForStatusCode(final int statusCode) { final SphereClient sphereClient = TestDoubleSphereClientFactory .createHttpTestDouble(intent -> HttpResponse.of(statusCode)); return BlockingSphereClient.of(sphereClient, Duration.ofMillis(100)); }
private BlockingSphereClient createSphereClient() { final SphereClientFactory factory = SphereClientFactory.of(); final SphereClient asyncSphereClient = factory.createClient( "jvm-sdk-dev-1", //replace with your project key "ELqF0rykXD2fyS8s-IhIPKfQ", //replace with your client id "222222222222222222222222222222226"); //replace with your client secret return BlockingSphereClient.of(asyncSphereClient, 20, TimeUnit.SECONDS); } }
public static void setupClient() { if (client == null) { final SphereClientConfig config = getSphereClientConfig(); final HttpClient httpClient = newHttpClient(); final SphereAccessTokenSupplier tokenSupplier = SphereAccessTokenSupplier.ofAutoRefresh(config, httpClient, false); final SphereClient underlying = SphereClient.of(config, httpClient, tokenSupplier); final SphereClient underlying1 = withMaybeDeprecationWarnTool(underlying); client = BlockingSphereClient.of(underlying1, 30, TimeUnit.SECONDS); assertProjectSettingsAreFine(client); } } //
public static void setupClient() { if (client == null) { final SphereClientConfig config = getSphereClientConfig(); final HttpClient httpClient = newHttpClient(); final SphereAccessTokenSupplier tokenSupplier = SphereAccessTokenSupplier.ofAutoRefresh(config, httpClient, false); final SphereClient underlying = SphereClient.of(config, httpClient, tokenSupplier); final SphereClient underlying1 = withMaybeDeprecationWarnTool(underlying); client = BlockingSphereClient.of(underlying1, 20, TimeUnit.SECONDS); assertProjectSettingsAreFine(client); } }
@Test public void integrationTest() { final HttpClient httpClient = AsyncHttpClientAdapter.of(new AsyncHttpClient()); final SphereClientConfig sphereClientConfig = IntegrationTest.getSphereClientConfig(); final SphereClientFactory factory = SphereClientFactory.of(() -> httpClient); try (final BlockingSphereClient sphereClient = BlockingSphereClient.of(factory.createClient(sphereClientConfig), 10, TimeUnit.SECONDS)) { final Project project = sphereClient.executeBlocking(ProjectGet.of()); assertThat(project.getKey()).isEqualTo(sphereClientConfig.getProjectKey()); } } }
}); final SimpleMetricsSphereClient simpleMetricsSphereClient = SimpleMetricsSphereClient.of(asyncClient); final BlockingSphereClient blockingSphereClient = BlockingSphereClient.of(simpleMetricsSphereClient, 10, TimeUnit.SECONDS); final Observable metricObservable = simpleMetricsSphereClient.getMetricObservable(); final MetricObserver metricObserver = new MetricObserver();