com.microsoft.azure.servicebus.Utils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of azure-servicebus Show documentation
Show all versions of azure-servicebus Show documentation
Java library for Azure Service Bus. Please note, a newer package com.azure:azure-messaging-servicebus for Azure Service Bus is available as of December 2020. While this package will continue to receive critical bug fixes, we strongly encourage you to upgrade. Read the migration guide at https://aka.ms/azsdk/java/migrate/sb for more details.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.microsoft.azure.servicebus;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import com.microsoft.azure.servicebus.primitives.ServiceBusException;
public final class Utils {
public static T completeFuture(CompletableFuture future) throws InterruptedException, ServiceBusException {
try {
return future.get();
} catch (InterruptedException ie) {
// Rare instance
throw ie;
} catch (ExecutionException ee) {
Throwable cause = ee.getCause();
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
} else if (cause instanceof Error) {
throw (Error) cause;
} else if (cause instanceof ServiceBusException) {
throw (ServiceBusException) cause;
} else {
throw new ServiceBusException(true, cause);
}
}
}
static void assertNonNull(String argumentName, Object argument) {
if (argument == null) {
throw new IllegalArgumentException("Argument '" + argumentName + "' is null.");
}
}
static MessageBody fromSequence(List