Example usage for io.vertx.core.net SocketAddress domainSocketAddress

List of usage examples for io.vertx.core.net SocketAddress domainSocketAddress

Introduction

In this page you can find the example usage for io.vertx.core.net SocketAddress domainSocketAddress.

Prototype

static SocketAddress domainSocketAddress(String path) 

Source Link

Document

Create a domain socket address.

Usage

From source file:io.reactiverse.pgclient.impl.PgConnectionFactory.java

License:Apache License

private void doConnect(boolean ssl, Handler<AsyncResult<SocketConnection>> handler) {
    if (Vertx.currentContext() != ctx) {
        throw new IllegalStateException();
    }// w  ww . j a  v a 2 s .  com
    SocketAddress socketAddress;
    if (!isUsingDomainSocket) {
        socketAddress = SocketAddress.inetSocketAddress(port, host);
    } else {
        socketAddress = SocketAddress.domainSocketAddress(host + "/.s.PGSQL." + port);
    }

    Future<NetSocket> future = Future.<NetSocket>future().setHandler(ar -> {
        if (ar.succeeded()) {
            NetSocketInternal socket = (NetSocketInternal) ar.result();
            SocketConnection conn = newSocketConnection(socket);

            if (ssl && !isUsingDomainSocket) {
                // upgrade connection to SSL if needed
                conn.upgradeToSSLConnection(ar2 -> {
                    if (ar2.succeeded()) {
                        handler.handle(Future.succeededFuture(conn));
                    } else {
                        handler.handle(Future.failedFuture(ar2.cause()));
                    }
                });
            } else {
                handler.handle(Future.succeededFuture(conn));
            }
        } else {
            handler.handle(Future.failedFuture(ar.cause()));
        }
    });

    try {
        client.connect(socketAddress, null, future);
    } catch (Exception e) {
        // Client is closed
        future.fail(e);
    }
}