Java Code Examples for reactor.core.publisher.MonoSink#success()

The following examples show how to use reactor.core.publisher.MonoSink#success() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultAggregationService.java    From jetlinks-community with Apache License 2.0 6 votes vote down vote up
private <T> ActionListener<T> translatorActionListener(MonoSink<T> sink) {
    return new ActionListener<T>() {
        @Override
        public void onResponse(T response) {
            sink.success(response);
        }

        @Override
        public void onFailure(Exception e) {
            if (e instanceof ElasticsearchException) {
                if (((ElasticsearchException) e).status().getStatus() == 404) {
                    sink.success();
                    return;
                } else if (((ElasticsearchException) e).status().getStatus() == 400) {
                    sink.error(new ElasticsearchParseException("查询参数格式错误", e));
                }
            }
            sink.error(e);
        }
    };
}
 
Example 2
Source File: SimpleConnectionPool.java    From styx with Apache License 2.0 5 votes vote down vote up
private void attemptBorrowConnection(MonoSink<Connection> sink, Connection connection) {
    borrowedCount.incrementAndGet();
    sink.onCancel(() -> {
        returnConnection(connection);
    });
    sink.success(connection);
}
 
Example 3
Source File: ReactorElasticSearchClient.java    From james-project with Apache License 2.0 5 votes vote down vote up
private static <T> ActionListener<T> getListener(MonoSink<T> sink) {
    return new ActionListener<T>() {
        @Override
        public void onResponse(T t) {
            sink.success(t);
        }

        @Override
        public void onFailure(Exception e) {
            sink.error(e);
        }
    };
}
 
Example 4
Source File: MonoMethodBridge.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
private MonoInvocation(MonoSink<Object> sink, Object[] args) {
    StreamObserver<Object> grpcStreamObserver = new ClientResponseObserver<Object, Object>() {
        @Override
        public void beforeStart(ClientCallStreamObserver requestStream) {
            sink.onCancel(() -> requestStream.cancel("React subscription cancelled", null));
        }

        @Override
        public void onNext(Object value) {
            if (emptyToVoidReply) {
                sink.success();
            } else {
                sink.success(value);
            }
        }

        @Override
        public void onError(Throwable error) {
            sink.error(error);
        }

        @Override
        public void onCompleted() {
            sink.success();
        }
    };

    Object[] grpcArgs = new Object[]{
            grpcArgPos < 0 ? Empty.getDefaultInstance() : args[grpcArgPos],
            grpcStreamObserver
    };

    GRPC_STUB invocationStub = handleCallMetadata(args)
            .withDeadline(Deadline.after(timeout.toMillis(), TimeUnit.MILLISECONDS));

    try {
        grpcMethod.invoke(invocationStub, grpcArgs);
    } catch (Exception e) {
        sink.error(e);
    }
}