
com.microsoft.azure.management.keyvault.implementation.KeyVaultFutures Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of azure-mgmt-keyvault Show documentation
Show all versions of azure-mgmt-keyvault Show documentation
This package contains Microsoft Azure Key Vault Management SDK. This package is in low maintenance mode and being phased out. To use the latest Azure SDK for resource management, please see https://aka.ms/azsdk/java/mgmt
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/
package com.microsoft.azure.management.keyvault.implementation;
import com.microsoft.azure.ListOperationCallback;
import com.microsoft.azure.management.apigeneration.LangDefinition;
import com.microsoft.rest.ServiceCallback;
import com.microsoft.rest.ServiceFuture;
import rx.Emitter;
import rx.Emitter.BackpressureMode;
import rx.Observable;
import rx.Subscription;
import rx.functions.Action1;
import rx.functions.Func0;
import rx.functions.Func1;
import java.util.List;
/**
* A collection of utilities for converting futures in Key Vault client to observables.
*/
@LangDefinition
final class KeyVaultFutures {
abstract static class ServiceFutureConverter {
abstract ServiceFuture callAsync();
abstract T wrapModel(TInner inner);
ServiceFuture toFuture(final ServiceCallback callback) {
final KeyVaultFuture future = new KeyVaultFuture<>();
Observable.from(callAsync())
.subscribe(new Action1() {
@Override
public void call(TInner inner) {
T fluent = wrapModel(inner);
if (callback != null) {
callback.success(fluent);
}
future.success(fluent);
}
}, new Action1() {
@Override
public void call(Throwable throwable) {
if (callback != null) {
callback.failure(throwable);
}
future.failure(throwable);
}
});
return future;
}
public Observable toObservable() {
return Observable.defer(new Func0>() {
@Override
public Observable call() {
return Observable.from(toFuture(null));
}
});
}
}
abstract static class ListCallbackObserver {
abstract void list(ListOperationCallback callback);
abstract Observable typeConvertAsync(TInner inner);
Observable toObservable() {
return Observable
.create(new Action1>>() {
@Override
public void call(final Emitter> emitter) {
list(new ListOperationCallback() {
@Override
public PagingBehavior progress(List partial) {
emitter.onNext(partial);
return PagingBehavior.CONTINUE;
}
@Override
public void success() {
emitter.onCompleted();
}
@Override
public void failure(Throwable t) {
emitter.onError(t);
}
});
}
}, BackpressureMode.BUFFER)
.flatMap(new Func1, Observable>() {
@Override
public Observable call(List secretItems) {
return Observable.from(secretItems);
}
}).flatMap(new Func1>() {
@Override
public Observable call(TInner tInner) {
return typeConvertAsync(tInner);
}
});
}
}
static class KeyVaultFuture extends ServiceFuture {
KeyVaultFuture() {
super();
}
@Override
protected void setSubscription(Subscription subscription) {
super.setSubscription(subscription);
}
boolean failure(Throwable t) {
return setException(t);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy