Azure Core provides shared primitives, abstractions, and helpers for modern Java Azure SDK client libraries
—
Essential utilities including configuration management, logging, metrics, tracing, polling operations, and helper functions for Azure SDK development.
Centralized configuration system supporting environment variables, system properties, and programmatic configuration.
/**
* Contains configuration information used to build client libraries.
*/
class Configuration {
/**
* Gets the global configuration instance.
* @return Global Configuration instance
*/
public static Configuration getGlobalConfiguration();
/**
* Creates a new Configuration instance.
*/
public Configuration();
/**
* Creates a Configuration instance with the provided configuration source.
* @param configurationSource Source of configuration values
*/
public Configuration(ConfigurationSource configurationSource);
/**
* Gets the value of the configuration.
* @param name Name of the configuration property
* @return Configuration value or null if not found
*/
public String get(String name);
/**
* Gets the value of the configuration.
* @param name Name of the configuration property
* @param defaultValue Default value if configuration is not found
* @return Configuration value or default value
*/
public String get(String name, String defaultValue);
/**
* Gets the value of the configuration and converts it to the specified type.
* @param <T> Type to convert to
* @param name Name of the configuration property
* @param converter Function to convert string to desired type
* @return Converted configuration value or null
*/
public <T> T get(String name, Function<String, T> converter);
/**
* Gets the value of the configuration and converts it to the specified type.
* @param <T> Type to convert to
* @param name Name of the configuration property
* @param converter Function to convert string to desired type
* @param defaultValue Default value if configuration is not found
* @return Converted configuration value or default value
*/
public <T> T get(String name, Function<String, T> converter, T defaultValue);
/**
* Gets the value of the configuration with generic default value.
* @param <T> Type of the configuration value
* @param name Name of the configuration property
* @param defaultValue Default value if configuration is not found
* @return Configuration value or default value
*/
public <T> T get(String name, T defaultValue);
/**
* Gets the value of the configuration property.
* @param <T> Type of the configuration property
* @param property The configuration property
* @return Configuration value or null if not found
*/
public <T> T get(ConfigurationProperty<T> property);
/**
* Determines if the configuration contains the specified property.
* @param property The configuration property to check
* @return true if the configuration contains the property
*/
public boolean contains(ConfigurationProperty<?> property);
/**
* Adds a configuration property.
* @param name Name of the configuration property
* @param value Value of the configuration property
* @return Updated Configuration instance
*/
public Configuration put(String name, String value);
/**
* Removes a configuration property.
* @param name Name of the configuration property to remove
* @return Updated Configuration instance
*/
public Configuration remove(String name);
/**
* Determines if the configuration contains the specified property.
* @param name Name of the configuration property
* @return true if the configuration contains the property
*/
public boolean contains(String name);
/**
* Creates a clone of the Configuration object.
* @return Cloned Configuration instance
*/
public Configuration clone();
}
/**
* Represents configuration property with type safety and validation.
*/
class ConfigurationProperty<T> {
/**
* Gets the property name.
* @return Property name
*/
public String getName();
/**
* Gets the default value for the property.
* @return Default value
*/
public T getDefaultValue();
/**
* Converts string value to property type.
* @param value String value to convert
* @return Converted value
*/
public T convert(String value);
}
/**
* Builder for Configuration instances.
*/
class ConfigurationBuilder {
/**
* Creates a ConfigurationBuilder.
*/
public ConfigurationBuilder();
/**
* Adds a configuration source.
* @param configurationSource Source to add
* @return Updated ConfigurationBuilder
*/
public ConfigurationBuilder putConfigurationSource(ConfigurationSource configurationSource);
/**
* Builds the Configuration instance.
* @return Configuration instance
*/
public Configuration build();
}
/**
* Interface for configuration sources.
*/
interface ConfigurationSource {
/**
* Gets properties from the configuration source.
* @param name Property name
* @return Property value or null if not found
*/
String getPropertyValue(String name);
}Thread-safe context system for passing metadata through call chains.
/**
* Context offers a means of passing arbitrary data (key-value pairs) to pipeline policies.
*/
class Context {
/**
* Signifies that no data needs to be passed to the pipeline.
*/
public static final Context NONE;
/**
* Constructs a new Context object with the specified key-value pair.
* @param key The key with which the specified value should be associated
* @param value The value to be associated with the specified key
* @throws IllegalArgumentException If key is null
*/
public Context(Object key, Object value);
/**
* Adds a new immutable Context object with the specified key-value pair to the existing Context chain.
* @param key The key with which the specified value is to be associated
* @param value The value to be associated with the specified key
* @return Context object containing the specified pair added to the set of pairs
* @throws IllegalArgumentException If key is null
*/
public Context addData(Object key, Object value);
/**
* Gets the value associated with the specified key.
* @param key The key whose associated value is to be returned
* @return Optional containing the value associated with the key, empty Optional otherwise
* @throws IllegalArgumentException If key is null
*/
public Optional<Object> getData(Object key);
/**
* Gets all values as a Map.
* @return Map containing all key-value pairs in the context
*/
public Map<Object, Object> getValues();
}Structured logging system optimized for Azure SDK usage patterns.
/**
* This class is a logging abstraction layer over SLF4J.
*/
class ClientLogger {
/**
* Creates a ClientLogger for the specified class.
* @param clazz Class to create logger for
*/
public ClientLogger(Class<?> clazz);
/**
* Creates a ClientLogger with the specified name.
* @param className Name for the logger
*/
public ClientLogger(String className);
/**
* Logs a message at verbose level.
* @param message Message to log
*/
public void verbose(String message);
/**
* Logs a message with arguments at verbose level.
* @param format Message format string
* @param args Arguments for the format string
*/
public void verbose(String format, Object... args);
/**
* Logs an informational message.
* @param message Message to log
*/
public void info(String message);
/**
* Logs an informational message with arguments.
* @param format Message format string
* @param args Arguments for the format string
*/
public void info(String format, Object... args);
/**
* Logs a warning message.
* @param message Message to log
*/
public void warning(String message);
/**
* Logs a warning message with arguments.
* @param format Message format string
* @param args Arguments for the format string
*/
public void warning(String format, Object... args);
/**
* Logs an error message.
* @param message Message to log
*/
public void error(String message);
/**
* Logs an error message with throwable.
* @param message Message to log
* @param throwable Exception to log
*/
public void error(String message, Throwable throwable);
/**
* Logs an error message with arguments.
* @param format Message format string
* @param args Arguments for the format string
*/
public void error(String format, Object... args);
/**
* Determines if logging is enabled for the specified log level.
* @param logLevel Log level to check
* @return true if logging is enabled for the level
*/
public boolean canLogAtLevel(LogLevel logLevel);
/**
* Logs a message at the specified level.
* @param logLevel Level to log at
* @param message Message to log
*/
public void log(LogLevel logLevel, String message);
/**
* Logs a message with arguments at the specified level.
* @param logLevel Level to log at
* @param format Message format string
* @param args Arguments for the format string
*/
public void log(LogLevel logLevel, String format, Object... args);
/**
* Logs a message with throwable at the specified level.
* @param logLevel Level to log at
* @param message Message to log
* @param throwable Exception to log
*/
public void log(LogLevel logLevel, String message, Throwable throwable);
}
/**
* Enumeration of log levels.
*/
enum LogLevel {
/**
* Indicates that log level is not set.
*/
NOT_SET(0),
/**
* Verbose logging level.
*/
VERBOSE(1),
/**
* Informational logging level.
*/
INFORMATIONAL(2),
/**
* Warning logging level.
*/
WARNING(3),
/**
* Error logging level.
*/
ERROR(4);
private final int value;
LogLevel(int value) {
this.value = value;
}
/**
* Gets the numeric value of the log level.
* @return Numeric value
*/
public int getValue() {
return value;
}
/**
* Creates LogLevel from numeric value.
* @param value Numeric value
* @return Corresponding LogLevel
*/
public static LogLevel fromValue(int value);
}Support for long-running operations with automatic polling and completion detection.
/**
* Synchronous poller for long-running operations.
*/
class SyncPoller<T, U> {
/**
* Polls and returns the current status of the long-running operation.
* @return PollResponse representing the current status
*/
public PollResponse<T> poll();
/**
* Waits for polling to complete.
* @return Final PollResponse when operation completes
*/
public PollResponse<T> waitForCompletion();
/**
* Waits for polling to complete within the specified timeout.
* @param timeout Maximum time to wait
* @return Final PollResponse when operation completes
*/
public PollResponse<T> waitForCompletion(Duration timeout);
/**
* Waits until the long-running operation reaches a specified status.
* @param statusToWaitFor Status to wait for
* @return PollResponse when the specified status is reached
*/
public PollResponse<T> waitUntil(LongRunningOperationStatus statusToWaitFor);
/**
* Waits until the long-running operation reaches a specified status within timeout.
* @param statusToWaitFor Status to wait for
* @param timeout Maximum time to wait
* @return PollResponse when the specified status is reached
*/
public PollResponse<T> waitUntil(LongRunningOperationStatus statusToWaitFor, Duration timeout);
/**
* Gets the final result of the long-running operation.
* @return Final result when operation completes
*/
public U getFinalResult();
/**
* Cancels the long-running operation.
*/
public void cancelOperation();
/**
* Gets the polling interval.
* @return Duration between polls
*/
public Duration getPollInterval();
}
/**
* Asynchronous poller for long-running operations.
*/
class PollerFlux<T, U> {
/**
* Creates a PollerFlux instance.
* @param pollInterval Duration between polling attempts
* @param pollOperation Function that performs polling
* @param cancelOperation Function that cancels the operation
* @param fetchResultOperation Function that fetches the final result
* @return PollerFlux instance
*/
public static <T, U> PollerFlux<T, U> create(
Duration pollInterval,
Function<PollingContext<T>, Mono<PollResponse<T>>> pollOperation,
Function<PollingContext<T>, Mono<T>> cancelOperation,
Function<PollingContext<T>, Mono<U>> fetchResultOperation);
/**
* Subscribes to the polling flux.
* @return Flux of PollResponse objects
*/
public Flux<PollResponse<T>> flux();
/**
* Gets the final result when polling completes.
* @return Mono containing the final result
*/
public Mono<U> getFinalResult();
/**
* Cancels the long-running operation.
* @return Mono representing the cancellation operation
*/
public Mono<T> cancelOperation();
/**
* Gets the last polling response.
* @return Mono containing the last poll response
*/
public Mono<PollResponse<T>> getLastPollResponse();
/**
* Creates a SyncPoller from this PollerFlux.
* @return SyncPoller instance
*/
public SyncPoller<T, U> getSyncPoller();
}
/**
* Response from a polling operation.
*/
class PollResponse<T> {
/**
* Creates a PollResponse.
* @param status Status of the long-running operation
* @param value Current value from the service
*/
public PollResponse(LongRunningOperationStatus status, T value);
/**
* Creates a PollResponse.
* @param status Status of the long-running operation
* @param value Current value from the service
* @param retryAfter Suggested retry interval
*/
public PollResponse(LongRunningOperationStatus status, T value, Duration retryAfter);
/**
* Gets the status of the long-running operation.
* @return Operation status
*/
public LongRunningOperationStatus getStatus();
/**
* Gets the current value from the service.
* @return Current poll value
*/
public T getValue();
/**
* Gets the suggested retry interval.
* @return Retry interval or null if not specified
*/
public Duration getRetryAfter();
}
/**
* Represents the status of a long-running operation.
*/
enum LongRunningOperationStatus {
/**
* The operation is not started.
*/
NOT_STARTED,
/**
* The operation is in progress.
*/
IN_PROGRESS,
/**
* The operation completed successfully.
*/
SUCCESSFULLY_COMPLETED,
/**
* The operation failed.
*/
FAILED,
/**
* The operation was cancelled.
*/
USER_CANCELLED;
/**
* Checks if the status represents a completed operation.
* @return true if operation is complete
*/
public boolean isComplete() {
return this == SUCCESSFULLY_COMPLETED || this == FAILED || this == USER_CANCELLED;
}
}
/**
* Context passed to polling operations.
*/
class PollingContext<T> {
/**
* Gets the latest poll response.
* @return Latest PollResponse
*/
public PollResponse<T> getLatestResponse();
/**
* Sets data in the polling context.
* @param key Data key
* @param value Data value
*/
public void setData(String key, Object value);
/**
* Gets data from the polling context.
* @param key Data key
* @return Data value or null if not found
*/
public Object getData(String key);
/**
* Gets the HTTP pipeline for making requests.
* @return HttpPipeline instance
*/
public HttpPipeline getHttpPipeline();
/**
* Gets the serializer adapter.
* @return SerializerAdapter instance
*/
public SerializerAdapter getSerializerAdapter();
}/**
* Utility methods for Azure Core functionality.
*/
class CoreUtils {
/**
* Checks if a string is null or empty.
* @param string String to check
* @return true if string is null or empty
*/
public static boolean isNullOrEmpty(String string);
/**
* Gets the first non-null value from the provided options.
* @param <T> Type of the values
* @param values Values to check
* @return First non-null value or null if all are null
*/
@SafeVarargs
public static <T> T firstNonNull(T... values);
/**
* Creates a deep copy of the provided object using serialization.
* @param <T> Type of the object
* @param object Object to clone
* @param clazz Class of the object
* @return Deep copy of the object
*/
public static <T> T clone(T object, Class<T> clazz);
/**
* Gets the application ID from the configuration.
* @param configuration Configuration instance
* @return Application ID or null if not configured
*/
public static String getApplicationId(Configuration configuration);
/**
* Extracts the error from a Mono or Flux.
* @param throwable Throwable from reactive stream
* @return Extracted Throwable
*/
public static Throwable extractAndWrapException(Throwable throwable);
/**
* Finds the first throwable in the causal chain that is an instance of the provided class.
* @param <T> Type of throwable to find
* @param throwable Root throwable
* @param clazz Class to search for
* @return First matching throwable or null
*/
public static <T extends Throwable> T findFirstOfType(Throwable throwable, Class<T> clazz);
}
/**
* Utility methods for working with Reactor Flux.
*/
class FluxUtil {
/**
* Collects ByteBuffer Flux into a single byte array.
* @param stream Flux of ByteBuffer
* @return Mono containing collected byte array
*/
public static Mono<byte[]> collectBytesInByteBufferStream(Flux<ByteBuffer> stream);
/**
* Converts a ByteBuffer Flux to a BinaryData.
* @param stream Flux of ByteBuffer
* @return Mono containing BinaryData
*/
public static Mono<BinaryData> toBinaryData(Flux<ByteBuffer> stream);
/**
* Writes a ByteBuffer Flux to an OutputStream.
* @param stream Flux of ByteBuffer
* @param outputStream Target OutputStream
* @return Mono representing the write operation
*/
public static Mono<Void> writeToOutputStream(Flux<ByteBuffer> stream, OutputStream outputStream);
/**
* Creates a Flux that emits after a delay with exponential backoff.
* @param delay Initial delay
* @param maxRetries Maximum number of retries
* @return Flux with exponential backoff
*/
public static Flux<Long> createExponentialBackoffFlux(Duration delay, int maxRetries);
}
/**
* Entity tag utility for HTTP caching.
*/
class ETag {
/**
* The wildcard ETag.
*/
public static final ETag ALL = new ETag("*");
/**
* Creates an ETag.
* @param eTag ETag string value
*/
public ETag(String eTag);
/**
* Gets the ETag value.
* @return ETag string
*/
public String toString();
/**
* Checks if this ETag equals another.
* @param other Other ETag to compare
* @return true if equal
*/
@Override
public boolean equals(Object other);
/**
* Gets the hash code.
* @return Hash code
*/
@Override
public int hashCode();
}
/**
* Builder for constructing URLs.
*/
class UrlBuilder {
/**
* Creates a UrlBuilder.
*/
public UrlBuilder();
/**
* Sets the scheme (protocol).
* @param scheme URL scheme
* @return Updated UrlBuilder
*/
public UrlBuilder setScheme(String scheme);
/**
* Sets the host.
* @param host URL host
* @return Updated UrlBuilder
*/
public UrlBuilder setHost(String host);
/**
* Sets the port.
* @param port URL port
* @return Updated UrlBuilder
*/
public UrlBuilder setPort(int port);
/**
* Sets the path.
* @param path URL path
* @return Updated UrlBuilder
*/
public UrlBuilder setPath(String path);
/**
* Adds a query parameter.
* @param name Parameter name
* @param value Parameter value
* @return Updated UrlBuilder
*/
public UrlBuilder setQueryParameter(String name, String value);
/**
* Removes a query parameter.
* @param name Parameter name to remove
* @return Updated UrlBuilder
*/
public UrlBuilder removeQueryParameter(String name);
/**
* Builds the URL.
* @return Constructed URL
*/
public URL toURL();
/**
* Builds the URL string.
* @return URL as string
*/
public String toString();
}/**
* Iterable stream that can be iterated multiple times.
*/
class IterableStream<T> implements Iterable<T> {
/**
* Creates an IterableStream from an Iterable.
* @param <T> Element type
* @param iterable Source iterable
* @return IterableStream instance
*/
public static <T> IterableStream<T> of(Iterable<T> iterable);
/**
* Gets an iterator over elements.
* @return Iterator over elements
*/
@Override
public Iterator<T> iterator();
/**
* Gets a stream of elements.
* @return Stream of elements
*/
public Stream<T> stream();
/**
* Applies a function to each element and returns a new IterableStream.
* @param <U> Result element type
* @param mapper Function to apply
* @return Mapped IterableStream
*/
public <U> IterableStream<U> map(Function<T, U> mapper);
/**
* Filters elements based on a predicate.
* @param predicate Filter predicate
* @return Filtered IterableStream
*/
public IterableStream<T> filter(Predicate<T> predicate);
}
/**
* Continuable page interface for paging operations.
*/
interface ContinuablePage<C, T> {
/**
* Gets the continuation token.
* @return Continuation token or null if no more pages
*/
C getContinuationToken();
/**
* Gets the elements on this page.
* @return Iterable of page elements
*/
IterableStream<T> getElements();
}
/**
* Synchronous paged iterable with continuation support.
*/
class ContinuablePagedIterable<C, T> extends PagedIterable<T> {
/**
* Gets pages as an iterable with continuation tokens.
* @return Iterable of pages
*/
public Iterable<ContinuablePage<C, T>> iterableByPage();
/**
* Gets pages starting from a continuation token.
* @param continuationToken Token to start from
* @return Iterable of pages
*/
public Iterable<ContinuablePage<C, T>> iterableByPage(C continuationToken);
/**
* Gets pages with a preferred page size.
* @param preferredPageSize Preferred number of elements per page
* @return Iterable of pages
*/
public Iterable<ContinuablePage<C, T>> iterableByPage(int preferredPageSize);
/**
* Gets pages starting from a continuation token with preferred page size.
* @param continuationToken Token to start from
* @param preferredPageSize Preferred number of elements per page
* @return Iterable of pages
*/
public Iterable<ContinuablePage<C, T>> iterableByPage(C continuationToken, int preferredPageSize);
}
/**
* Asynchronous paged flux with continuation support.
*/
class ContinuablePagedFlux<C, T> extends PagedFlux<T> {
/**
* Gets pages as a flux with continuation tokens.
* @return Flux of pages
*/
public Flux<ContinuablePage<C, T>> byPage();
/**
* Gets pages starting from a continuation token.
* @param continuationToken Token to start from
* @return Flux of pages
*/
public Flux<ContinuablePage<C, T>> byPage(C continuationToken);
/**
* Gets pages with a preferred page size.
* @param preferredPageSize Preferred number of elements per page
* @return Flux of pages
*/
public Flux<ContinuablePage<C, T>> byPage(int preferredPageSize);
/**
* Gets pages starting from a continuation token with preferred page size.
* @param continuationToken Token to start from
* @param preferredPageSize Preferred number of elements per page
* @return Flux of pages
*/
public Flux<ContinuablePage<C, T>> byPage(C continuationToken, int preferredPageSize);
}import com.azure.core.util.Configuration;
import com.azure.core.util.ConfigurationBuilder;
// Using global configuration
Configuration config = Configuration.getGlobalConfiguration();
// Get configuration values with defaults
String endpoint = config.get("AZURE_ENDPOINT", "https://default.azure.com");
int timeout = config.get("TIMEOUT", Integer::parseInt, 30);
boolean enableLogging = config.get("ENABLE_LOGGING", Boolean::parseBoolean, false);
// Programmatically set configuration
config.put("API_VERSION", "2023-01-01")
.put("MAX_RETRIES", "3");
// Create custom configuration
Configuration customConfig = new ConfigurationBuilder()
.putConfigurationSource(new MyCustomConfigSource())
.build();
// Check if configuration exists
if (config.contains("SECRET_KEY")) {
String secret = config.get("SECRET_KEY");
// Use secret
}import com.azure.core.util.Context;
// Create context with metadata
Context context = Context.NONE
.addData("user-id", "user123")
.addData("correlation-id", UUID.randomUUID().toString())
.addData("operation", "create-user");
// Extract data from context
Optional<Object> userId = context.getData("user-id");
String correlationId = (String) context.getData("correlation-id").orElse(null);
// Pass context through operations
httpClient.send(request, context);
// Add HTTP request ID tracking
Context trackedContext = context.setHttpRequestId("req-456");
String requestId = trackedContext.getHttpRequestId();import com.azure.core.util.logging.ClientLogger;
import com.azure.core.util.logging.LogLevel;
class MyService {
private static final ClientLogger LOGGER = new ClientLogger(MyService.class);
public void processData(String data) {
LOGGER.info("Processing data for request: {}", data);
try {
// Process data
LOGGER.verbose("Data processing steps completed successfully");
} catch (Exception e) {
LOGGER.error("Failed to process data", e);
throw e;
}
}
public void conditionalLogging() {
if (LOGGER.canLogAtLevel(LogLevel.VERBOSE)) {
// Expensive operation only if verbose logging is enabled
String expensiveDebugInfo = computeExpensiveDebugInfo();
LOGGER.verbose("Debug info: {}", expensiveDebugInfo);
}
}
}import com.azure.core.util.polling.*;
import java.time.Duration;
// Synchronous polling
SyncPoller<OperationStatus, String> poller = // ... create poller
// Poll until completion
PollResponse<OperationStatus> finalResponse = poller.waitForCompletion();
// Poll with timeout
PollResponse<OperationStatus> response = poller.waitForCompletion(Duration.ofMinutes(5));
// Wait for specific status
poller.waitUntil(LongRunningOperationStatus.IN_PROGRESS);
// Get final result
if (finalResponse.getStatus() == LongRunningOperationStatus.SUCCESSFULLY_COMPLETED) {
String result = poller.getFinalResult();
System.out.println("Operation completed: " + result);
}
// Asynchronous polling
PollerFlux<OperationStatus, String> asyncPoller = // ... create async poller
asyncPoller.flux()
.doOnNext(pollResponse -> {
System.out.println("Current status: " + pollResponse.getStatus());
})
.then(asyncPoller.getFinalResult())
.subscribe(result -> {
System.out.println("Final result: " + result);
});import com.azure.core.util.UrlBuilder;
// Build complex URLs
UrlBuilder builder = new UrlBuilder()
.setScheme("https")
.setHost("api.example.com")
.setPort(443)
.setPath("/v1/users")
.setQueryParameter("limit", "50")
.setQueryParameter("offset", "100")
.setQueryParameter("filter", "active=true");
URL url = builder.toURL();
String urlString = builder.toString();
// Modify existing URLs
builder.removeQueryParameter("offset")
.setQueryParameter("sort", "created_date");import com.azure.core.util.ETag;
// Create ETags
ETag strongETag = new ETag("\"686897696a7c876b7e\"");
ETag weakETag = new ETag("W/\"686897696a7c876b7e\"");
ETag wildcardETag = ETag.ALL;
// Use in conditional requests
HttpRequest request = new HttpRequest(HttpMethod.GET, url);
request.setHeader("If-None-Match", strongETag.toString());
// Compare ETags
if (eTag1.equals(eTag2)) {
System.out.println("Resources are the same");
}import com.azure.core.util.CoreUtils;
import com.azure.core.util.FluxUtil;
// String utilities
String value = CoreUtils.firstNonNull(null, "", "default");
boolean isEmpty = CoreUtils.isNullOrEmpty(someString);
// Exception handling
try {
// Some operation
} catch (Exception e) {
Throwable rootCause = CoreUtils.findFirstOfType(e, IllegalArgumentException.class);
if (rootCause != null) {
// Handle specific exception type
}
}
// Flux utilities
Flux<ByteBuffer> dataFlux = // ... get data flux
Mono<byte[]> bytes = FluxUtil.collectBytesInByteBufferStream(dataFlux);
Mono<BinaryData> binaryData = FluxUtil.toBinaryData(dataFlux);
// Write to output stream
OutputStream outputStream = // ... get output stream
FluxUtil.writeToOutputStream(dataFlux, outputStream).block();Configuration options for HTTP clients with timeout, proxy, and connection pool settings.
/**
* General configuration options for HttpClients.
*/
class HttpClientOptions extends ClientOptions {
/**
* Creates a new instance of HttpClientOptions.
*/
public HttpClientOptions();
/**
* Sets the proxy options that the HttpClient will use.
* @param proxyOptions The proxy options to use
* @return The updated HttpClientOptions object
*/
public HttpClientOptions setProxyOptions(ProxyOptions proxyOptions);
/**
* Gets the proxy options that the HttpClient will use.
* @return The proxy options to use
*/
public ProxyOptions getProxyOptions();
/**
* Sets the configuration store that the HttpClient will use.
* @param configuration The configuration store to use
* @return The updated HttpClientOptions object
*/
public HttpClientOptions setConfiguration(Configuration configuration);
/**
* Gets the configuration store that the HttpClient will use.
* @return The configuration store to use
*/
public Configuration getConfiguration();
/**
* Sets the connection timeout for a request to be sent.
* @param connectTimeout Connect timeout duration
* @return The updated HttpClientOptions object
*/
public HttpClientOptions setConnectTimeout(Duration connectTimeout);
/**
* Gets the connection timeout for a request to be sent.
* @return The connection timeout of a request to be sent
*/
public Duration getConnectTimeout();
/**
* Sets the writing timeout for a request to be sent.
* @param writeTimeout Write operation timeout duration
* @return The updated HttpClientOptions object
*/
public HttpClientOptions setWriteTimeout(Duration writeTimeout);
/**
* Gets the writing timeout for a request to be sent.
* @return The writing timeout of a request to be sent
*/
public Duration getWriteTimeout();
/**
* Sets the response timeout duration used when waiting for a server to reply.
* @param responseTimeout Response timeout duration
* @return The updated HttpClientOptions object
*/
public HttpClientOptions setResponseTimeout(Duration responseTimeout);
/**
* Gets the response timeout duration used when waiting for a server to reply.
* @return The response timeout duration
*/
public Duration getResponseTimeout();
/**
* Sets the read timeout duration used when reading the server response.
* @param readTimeout Read timeout duration
* @return The updated HttpClientOptions object
*/
public HttpClientOptions setReadTimeout(Duration readTimeout);
/**
* Gets the read timeout duration used when reading the server response.
* @return The read timeout duration
*/
public Duration getReadTimeout();
/**
* Sets the maximum connection pool size used by the underlying HTTP client.
* @param maximumConnectionPoolSize The maximum connection pool size
* @return The updated HttpClientOptions object
*/
public HttpClientOptions setMaximumConnectionPoolSize(Integer maximumConnectionPoolSize);
/**
* Gets the maximum connection pool size used by the underlying HTTP client.
* @return The maximum connection pool size
*/
public Integer getMaximumConnectionPoolSize();
/**
* Sets the duration of time before an idle connection.
* @param connectionIdleTimeout The connection idle timeout duration
* @return The updated HttpClientOptions object
*/
public HttpClientOptions setConnectionIdleTimeout(Duration connectionIdleTimeout);
/**
* Gets the duration of time before an idle connection is closed.
* @return The connection idle timeout duration
*/
public Duration getConnectionIdleTimeout();
}Interface for asynchronous resource cleanup operations.
/**
* Interface for close operations that are asynchronous.
*/
interface AsyncCloseable {
/**
* Begins the close operation. If one is in progress, will return that existing close operation.
* @return A Mono representing the close operation
*/
Mono<Void> closeAsync();
}Interface for service version specification in Azure SDK clients.
/**
* A generic interface for sending HTTP requests using the provided service version.
*/
interface ServiceVersion {
/**
* Gets the string representation of the ServiceVersion.
* @return the string representation of the ServiceVersion
*/
String getVersion();
}Utility for building user agent strings for Azure client libraries.
/**
* Utility for building user agent string for Azure client libraries.
*/
class UserAgentUtil {
/**
* Default UserAgent header.
*/
public static final String DEFAULT_USER_AGENT_HEADER = "azsdk-java";
/**
* Return user agent string for the given sdk name and version.
* @param applicationId Name of the application
* @param sdkName Name of the SDK
* @param sdkVersion Version of the SDK
* @param configuration The configuration to use to determine if platform info should be included
* @return User agent string as specified in design guidelines
*/
public static String toUserAgentString(String applicationId, String sdkName, String sdkVersion,
Configuration configuration);
}Utilities for Base64 and Base64URL encoding and decoding operations.
/**
* Utility type exposing Base64 encoding and decoding methods.
*/
class Base64Util {
/**
* Encodes a byte array to base64.
* @param src the byte array to encode
* @return the base64 encoded bytes
*/
public static byte[] encode(byte[] src);
/**
* Encodes a byte array to base64 URL format.
* @param src the byte array to encode
* @return the base64 URL encoded bytes
*/
public static byte[] encodeURLWithoutPadding(byte[] src);
/**
* Encodes a byte array to a base 64 string.
* @param src the byte array to encode
* @return the base64 encoded string
*/
public static String encodeToString(byte[] src);
/**
* Decodes a base64 encoded byte array.
* @param encoded the byte array to decode
* @return the decoded byte array
*/
public static byte[] decode(byte[] encoded);
/**
* Decodes a byte array in base64 URL format.
* @param src the byte array to decode
* @return the decoded byte array
*/
public static byte[] decodeURL(byte[] src);
/**
* Decodes a base64 encoded string.
* @param encoded the string to decode
* @return the decoded byte array
*/
public static byte[] decodeString(String encoded);
}
/**
* Encodes and decodes using Base64 URL encoding.
*/
class Base64Url {
/**
* Creates a new Base64Url object with the specified encoded string.
* @param string The encoded string
*/
public Base64Url(String string);
/**
* Creates a new Base64Url object with the specified encoded bytes.
* @param bytes The encoded bytes
*/
public Base64Url(byte[] bytes);
/**
* Encodes a byte array into Base64Url encoded bytes.
* @param bytes The byte array to encode
* @return A new Base64Url instance
*/
public static Base64Url encode(byte[] bytes);
/**
* Returns the underlying encoded byte array.
* @return The underlying encoded byte array
*/
public byte[] encodedBytes();
/**
* Decode the bytes and returns its value.
* @return The decoded byte array
*/
public byte[] decodedBytes();
/**
* Gets the string representation.
* @return String representation of the encoded bytes
*/
@Override
public String toString();
}Interfaces and classes for tracking progress of I/O operations.
/**
* A ProgressListener is an interface that can be used to listen to the progress of I/O transfers.
*/
@FunctionalInterface
interface ProgressListener {
/**
* The callback function invoked as progress is reported.
* @param progress The total progress at the current point of time
*/
void handleProgress(long progress);
}
/**
* ProgressReporter offers a convenient way to add progress tracking to I/O operations.
*/
class ProgressReporter {
/**
* Creates a ProgressReporter that notifies ProgressListener.
* @param progressListener The ProgressListener to be notified about progress
* @return The ProgressReporter instance
*/
public static ProgressReporter withProgressListener(ProgressListener progressListener);
/**
* Creates child ProgressReporter that can be used to track sub-progress.
* @return The child ProgressReporter
*/
public ProgressReporter createChild();
/**
* Resets progress to zero and notifies.
*/
public void reset();
/**
* Accumulates the provided progress and notifies.
* @param progress The number to be accumulated
*/
public void reportProgress(long progress);
}Install with Tessl CLI
npx tessl i tessl/maven-com-azure--azure-core