use of rx.functions.Action1 in project ribbon by Netflix.
the class HttpMetaRequest method convertToRibbonResponse.
private Observable<RibbonResponse<Observable<T>>> convertToRibbonResponse(final HystrixObservableCommandChain<T> commandChain, final Observable<ResultCommandPair<T>> hystrixNotificationObservable) {
return Observable.create(new OnSubscribe<RibbonResponse<Observable<T>>>() {
@Override
public void call(final Subscriber<? super RibbonResponse<Observable<T>>> t1) {
final Subject<T, T> subject = ReplaySubject.create();
hystrixNotificationObservable.materialize().subscribe(new Action1<Notification<ResultCommandPair<T>>>() {
AtomicBoolean first = new AtomicBoolean(true);
@Override
public void call(Notification<ResultCommandPair<T>> notification) {
if (first.compareAndSet(true, false)) {
HystrixObservableCommand<T> command = notification.isOnError() ? commandChain.getLastCommand() : notification.getValue().getCommand();
t1.onNext(new ResponseWithSubject<T>(subject, command));
t1.onCompleted();
}
if (notification.isOnNext()) {
subject.onNext(notification.getValue().getResult());
} else if (notification.isOnCompleted()) {
subject.onCompleted();
} else {
// onError
subject.onError(notification.getThrowable());
}
}
});
}
});
}
use of rx.functions.Action1 in project azure-tools-for-java by Microsoft.
the class AzureDockerUtils method refreshDockerSubscriptions.
public static Map<String, AzureDockerSubscription> refreshDockerSubscriptions(AzureManager azureAuthManager) {
Map<String, AzureDockerSubscription> subsMap = new HashMap<>();
try {
if (DEBUG)
System.out.format("Get AzureDockerHostsManage subscription details: %s\n", new Date().toString());
SubscriptionManager subscriptionManager = azureAuthManager.getSubscriptionManager();
List<SubscriptionDetail> subscriptions = subscriptionManager.getSubscriptionDetails();
if (subscriptions != null) {
if (DEBUG)
System.out.format("Get AzureDockerHostsManage Docker subscription details: %s\n", new Date().toString());
Observable.from(subscriptions).flatMap(subscriptionDetail -> {
return Observable.create(new Observable.OnSubscribe<AzureDockerSubscription>() {
@Override
public void call(Subscriber<? super AzureDockerSubscription> dockerSubscriptionSubscriber) {
if (subscriptionDetail.isSelected()) {
AzureDockerSubscription dockerSubscription = new AzureDockerSubscription();
dockerSubscription.id = subscriptionDetail.getSubscriptionId();
try {
if (DEBUG)
System.out.format("\tGet AzureDockerHostsManage Docker subscription: %s at %s\n", dockerSubscription.id, new Date().toString());
dockerSubscription.tid = subscriptionDetail.getTenantId();
dockerSubscription.name = subscriptionDetail.getSubscriptionName();
dockerSubscription.azureClient = azureAuthManager.getAzure(dockerSubscription.id);
dockerSubscription.keyVaultClient = azureAuthManager.getKeyVaultClient(subscriptionDetail.getTenantId());
dockerSubscription.isSelected = true;
if (AzureDockerUtils.hasServicePrincipalAzureManager(azureAuthManager)) {
dockerSubscription.userId = null;
dockerSubscription.servicePrincipalId = azureAuthManager.getCurrentUserId();
} else {
dockerSubscription.userId = azureAuthManager.getCurrentUserId();
dockerSubscription.servicePrincipalId = null;
}
dockerSubscriptionSubscriber.onNext(dockerSubscription);
} catch (Exception e) {
e.printStackTrace();
DefaultLoader.getUIHelper().showError(e.getMessage(), "Error Loading Subscription Details for " + dockerSubscription.id);
}
}
dockerSubscriptionSubscriber.onCompleted();
}
}).subscribeOn(Schedulers.io());
}).subscribeOn(Schedulers.io()).toBlocking().subscribe(new Action1<AzureDockerSubscription>() {
@Override
public void call(AzureDockerSubscription dockerSubscription) {
subsMap.put(dockerSubscription.id, dockerSubscription);
}
});
}
if (DEBUG)
System.out.format("Get AzureDockerHostsManage locations: %s\n", new Date().toString());
List<Subscription> azureSubscriptionList = azureAuthManager.getSubscriptions();
for (Subscription subscription : azureSubscriptionList) {
AzureDockerSubscription dockerSubscription = subsMap.get(subscription.subscriptionId());
if (dockerSubscription != null) {
List<String> locations = subscription.listLocations().stream().sorted(Comparator.comparing(Location::displayName)).map(o -> o.name().toLowerCase()).collect(Collectors.toList());
dockerSubscription.locations = locations;
}
}
} catch (Exception e) {
e.printStackTrace();
DefaultLoader.getUIHelper().showError(e.getMessage(), "Error loading subscription details");
}
return subsMap;
}
use of rx.functions.Action1 in project azure-tools-for-java by Microsoft.
the class AzureDockerCertVaultOps method getVault.
public static AzureDockerCertVault getVault(AzureDockerCertVault certVault, KeyVaultClient keyVaultClient) throws AzureDockerException {
if (certVault == null || keyVaultClient == null || certVault.uri == null) {
throw new AzureDockerException("Unexpected argument values; azureClient, vault name and resourceGroupName cannot be null");
}
String vaultUri = certVault.uri;
try {
SecretBundle secret = keyVaultClient.getSecret(vaultUri, SECRETENTRY_DOCKERHOSTNAMES);
if (secret != null) {
certVault.hostName = secret.value();
} else {
certVault.hostName = null;
return null;
}
} catch (Exception e) {
return null;
}
//Execute Key Vault Secret read in parallel
Map<String, String> secretNamesAndValueMap = new HashMap<>();
Observable.from(DOCKERHOST_SECRETS).flatMap(secretName -> {
return Observable.create(new Observable.OnSubscribe<Pair<String, String>>() {
@Override
public void call(Subscriber<? super Pair<String, String>> subscriber) {
keyVaultClient.getSecretAsync(vaultUri, secretName, new ServiceCallback<SecretBundle>() {
@Override
public void failure(Throwable throwable) {
subscriber.onCompleted();
}
@Override
public void success(SecretBundle secretBundle) {
if (secretBundle != null) {
subscriber.onNext(new Pair<>(secretName, secretBundle.value()));
}
subscriber.onCompleted();
}
});
}
}).subscribeOn(Schedulers.io());
}, 5).subscribeOn(Schedulers.io()).toBlocking().subscribe(new Action1<Pair<String, String>>() {
@Override
public void call(Pair<String, String> secretNameAndValue) {
secretNamesAndValueMap.put(secretNameAndValue.first(), secretNameAndValue.second());
}
});
String currentSecretValue;
currentSecretValue = secretNamesAndValueMap.get("vmUsername");
if (currentSecretValue != null && !currentSecretValue.isEmpty()) {
certVault.vmUsername = currentSecretValue;
}
currentSecretValue = secretNamesAndValueMap.get("vmPwd");
if (currentSecretValue != null && !currentSecretValue.isEmpty()) {
certVault.vmPwd = currentSecretValue;
}
currentSecretValue = secretNamesAndValueMap.get("sshKey");
if (currentSecretValue != null && !currentSecretValue.isEmpty()) {
certVault.sshKey = currentSecretValue;
}
currentSecretValue = secretNamesAndValueMap.get("sshPubKey");
if (currentSecretValue != null && !currentSecretValue.isEmpty()) {
certVault.sshPubKey = currentSecretValue;
}
currentSecretValue = secretNamesAndValueMap.get("tlsCACert");
if (currentSecretValue != null && !currentSecretValue.isEmpty()) {
certVault.tlsCACert = currentSecretValue;
}
currentSecretValue = secretNamesAndValueMap.get("tlsCAKey");
if (currentSecretValue != null && !currentSecretValue.isEmpty()) {
certVault.tlsCAKey = currentSecretValue;
}
currentSecretValue = secretNamesAndValueMap.get("tlsClientCert");
if (currentSecretValue != null && !currentSecretValue.isEmpty()) {
certVault.tlsClientCert = currentSecretValue;
}
currentSecretValue = secretNamesAndValueMap.get("tlsClientKey");
if (currentSecretValue != null && !currentSecretValue.isEmpty()) {
certVault.tlsClientKey = currentSecretValue;
}
currentSecretValue = secretNamesAndValueMap.get("tlsServerCert");
if (currentSecretValue != null && !currentSecretValue.isEmpty()) {
certVault.tlsServerCert = currentSecretValue;
}
currentSecretValue = secretNamesAndValueMap.get("tlsServerKey");
if (currentSecretValue != null && !currentSecretValue.isEmpty()) {
certVault.tlsServerKey = currentSecretValue;
}
return certVault;
}
use of rx.functions.Action1 in project mosby by sockeqwe.
the class MailProviderTest method createMail.
@Test
public void createMail() {
final Mail mail = new Mail();
mail.id(-1);
final int id = mailProvider.getLastMailId();
final AtomicBoolean successCalled = new AtomicBoolean(false);
mailProvider.addMailWithDelay(mail).subscribe(new Subscriber<Mail>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
Assert.fail("error occcurred");
}
@Override
public void onNext(Mail created) {
Assert.assertEquals(mail, created);
Assert.assertEquals(created.getId(), id + 1);
successCalled.set(true);
mailProvider.getMail(id).subscribe(new Action1<Mail>() {
@Override
public void call(Mail queried) {
Assert.assertEquals(queried.getId(), id);
}
});
}
});
Assert.assertTrue(successCalled.get());
}
use of rx.functions.Action1 in project frodo by android10.
the class LogStreamObservable method get.
@Override
<T> Observable<T> get(T type) throws Throwable {
final StopWatch stopWatch = new StopWatch();
final Counter emittedItems = new Counter(joinPoint.getMethodName());
return ((Observable<T>) joinPoint.proceed()).doOnSubscribe(new Action0() {
@Override
public void call() {
stopWatch.start();
}
}).doOnNext(new Action1<T>() {
@Override
public void call(T value) {
emittedItems.increment();
messageManager.printObservableOnNextWithValue(observableInfo, value);
}
}).doOnError(new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
messageManager.printObservableOnError(observableInfo, throwable);
}
}).doOnTerminate(new Action0() {
@Override
public void call() {
stopWatch.stop();
observableInfo.setTotalExecutionTime(stopWatch.getTotalTimeMillis());
observableInfo.setTotalEmittedItems(emittedItems.tally());
messageManager.printObservableItemTimeInfo(observableInfo);
}
});
}
Aggregations