use of com.mongodb.connection.AsyncCompletionHandler in project mongo-java-driver by mongodb.
the class KeyManagementService method decryptKey.
Mono<Void> decryptKey(final MongoKeyDecryptor keyDecryptor) {
SocketSettings socketSettings = SocketSettings.builder().connectTimeout(timeoutMillis, MILLISECONDS).readTimeout(timeoutMillis, MILLISECONDS).build();
StreamFactory streamFactory = tlsChannelStreamFactoryFactory.create(socketSettings, SslSettings.builder().enabled(true).context(kmsProviderSslContextMap.get(keyDecryptor.getKmsProvider())).build());
ServerAddress serverAddress = new ServerAddress(keyDecryptor.getHostName());
LOGGER.info("Connecting to KMS server at " + serverAddress);
return Mono.<Void>create(sink -> {
Stream stream = streamFactory.create(serverAddress);
stream.openAsync(new AsyncCompletionHandler<Void>() {
@Override
public void completed(final Void ignored) {
streamWrite(stream, keyDecryptor, sink);
}
@Override
public void failed(final Throwable t) {
stream.close();
sink.error(t);
}
});
}).onErrorMap(this::unWrapException);
}
Aggregations