本文整理汇总了Java中ratpack.exec.Promise类的典型用法代码示例。如果您正苦于以下问题:Java Promise类的具体用法?Java Promise怎么用?Java Promise使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Promise类属于ratpack.exec包,在下文中一共展示了Promise类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: flow
import ratpack.exec.Promise; //导入依赖的package包/类
/**
* @param promise
* @param strategy The {@link BackpressureStrategy} to use
* @param <T>
* @return
* @see RxRatpack#observe(Promise)
*/
public static <T> Flowable<T> flow(Promise<T> promise, BackpressureStrategy strategy) {
return Flowable.create(subscriber ->
promise.onError(subscriber::onError).then(value -> {
subscriber.onNext(value);
subscriber.onComplete();
}),
strategy);
}
示例2: accept
import ratpack.exec.Promise; //导入依赖的package包/类
@Override
public void accept(Throwable e) throws Exception {
if (e instanceof OnErrorNotImplementedException) {
Promise.error(e.getCause()).then(Action.noop());
} else if (e instanceof UndeliverableException) {
Promise.error(e.getCause()).then(Action.noop());
} else {
Promise.error(e).then(Action.noop());
}
}
示例3: backoff
import ratpack.exec.Promise; //导入依赖的package包/类
public Promise<Void> backoff() {
return Blocking.op(() -> {
log.debug("Circuit is OPEN. Waiting...");
Thread.sleep(waitTime());
mark();
}).promise();
}
示例4: check
import ratpack.exec.Promise; //导入依赖的package包/类
@Override
public Promise<Result> check(Registry registry) throws Exception {
return eurekaService.isAvailable().map(available -> {
if (available) {
return Result.healthy();
}
return Result.unhealthy("EurekaService: Not available");
});
}
示例5: consume
import ratpack.exec.Promise; //导入依赖的package包/类
private Promise<Void> consume(ReceiveMessageResult result) {
List<Promise<Void>> promises = result.getMessages().stream()
.map(this::consume)
.collect(Collectors.toList());
return SerialBatch.of(promises)
.yieldAll()
.flatMap(v -> Promise.value(null));
}
示例6: deleteMessage
import ratpack.exec.Promise; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private Promise<Void> deleteMessage(Message message) {
return getQueueUrl()
.map(url -> new DeleteMessageRequest(url, message.getReceiptHandle()))
.flatMap(sqs::deleteMessage)
.transform(transformer.recover(t -> new DeleteMessageResult()));
}
示例7: getReceiveMessageRequest
import ratpack.exec.Promise; //导入依赖的package包/类
private Promise<ReceiveMessageRequest> getReceiveMessageRequest() {
ReceiveMessageRequest request = consumer.getReceiveMessageRequest();
if (request.getQueueUrl() == null || request.getQueueUrl().isEmpty()) {
return getQueueUrl()
.map((url) -> {
request.withQueueUrl(url);
return request;
});
}
return Promise.value(request);
}
示例8: getBook
import ratpack.exec.Promise; //导入依赖的package包/类
@Override
public Promise<Book> getBook(String isbn) {
// TODO - Implement getBooks function
// Hint - checkout Blocking#get(Block) to see how to integrate blocking code with Ratpack
// Hint - lab07.jooq.tables.Book.BOOK is the representation for the underlying `book` table
// Hint - checkout SelectWhereStep#where(Condition...) and ResultQuery#fetchOneInto(Class)
return Blocking.get(() ->
create.select().from(BOOK).where(BOOK.ISBN.equal(isbn)).fetchOneInto(Book.class)
);
}
示例9: setTopicAttributes
import ratpack.exec.Promise; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Promise<SetTopicAttributesResult> setTopicAttributes(
String topicArn,
String attributeName,
String attributeValue
) {
return Blocking.get(() -> sns().setTopicAttributes(topicArn, attributeName, attributeValue))
.transform(breaker);
}
示例10: requestStream
import ratpack.exec.Promise; //导入依赖的package包/类
@Override
public Promise<StreamedResponse> requestStream(URI uri, Action<? super RequestSpec> action) {
final AtomicReference<Span> span = new AtomicReference<>();
return delegate
.requestStream(uri, (RequestSpec requestSpec) -> {
WrappedRequestSpec captor = new WrappedRequestSpec(handler, injector, requestSpec, span);
// streamed request doesn't set the http method.
// start span here until a better solution presents itself.
span.set(handler.handleSend(injector, captor.getHeaders(), captor));
action.execute(captor);
})
.wiretap(response -> streamedResponseWithSpan(response, span));
}
示例11: createTopic
import ratpack.exec.Promise; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Promise<CreateTopicResult> createTopic(CreateTopicRequest request) {
LOG.trace("creating sns topic request={}", request);
return Blocking.get(() -> sns().createTopic(request))
.transform(breaker);
}
示例12: deleteTopic
import ratpack.exec.Promise; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Promise<DeleteTopicResult> deleteTopic(DeleteTopicRequest request) {
LOG.debug("deleting sns topic request={}", request);
return Blocking.get(() -> sns().deleteTopic(request))
.transform(breaker);
}
示例13: addPermission
import ratpack.exec.Promise; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Promise<AddPermissionResult> addPermission(
String topicArn,
String label,
List<String> aWSAccountIds,
List<String> actionNames
) {
return Blocking.get(() -> sns().addPermission(topicArn, label, actionNames, actionNames))
.transform(breaker);
}
示例14: checkIfPhoneNumberIsOptedOut
import ratpack.exec.Promise; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Promise<CheckIfPhoneNumberIsOptedOutResult> checkIfPhoneNumberIsOptedOut(
CheckIfPhoneNumberIsOptedOutRequest request
) {
return Blocking.get(() -> sns().checkIfPhoneNumberIsOptedOut(request))
.transform(breaker);
}
示例15: confirmSubscription
import ratpack.exec.Promise; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Promise<ConfirmSubscriptionResult> confirmSubscription(
String topicArn,
String token,
String authenticateOnUnsubscribe
) {
return Blocking.get(() -> sns().confirmSubscription(topicArn, token, authenticateOnUnsubscribe))
.transform(breaker);
}