io.vertx.core.net.impl.NetSocketInternal Java Examples

The following examples show how to use io.vertx.core.net.impl.NetSocketInternal. 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: PgConnectionFactory.java    From vertx-sql-client with Apache License 2.0 6 votes vote down vote up
private void doConnect(boolean ssl, Promise<Connection> promise) {
  Future<NetSocket> soFut;
  try {
    soFut = client.connect(socketAddress, (String) null);
  } catch (Exception e) {
    // Client is closed
    promise.fail(e);
    return;
  }
  Future<Connection> connFut = soFut.map(so -> newSocketConnection((NetSocketInternal) so));
  if (ssl && !socketAddress.isDomainSocket()) {
    // upgrade connection to SSL if needed
    connFut = connFut.flatMap(conn -> Future.future(p -> {
      PgSocketConnection socket = (PgSocketConnection) conn;
      socket.upgradeToSSLConnection(ar2 -> {
        if (ar2.succeeded()) {
          p.complete(conn);
        } else {
          p.fail(ar2.cause());
        }
      });
    }));
  }
  connFut.onComplete(promise);
}
 
Example #2
Source File: ProtonReceiverImplTest.java    From vertx-proton with Apache License 2.0 6 votes vote down vote up
@Test
public void testFlowWithExistingDrainOutstandingThrowsISE() {
  ProtonConnectionImpl conn = new ProtonConnectionImpl(null, null, null);
  conn.bindClient(null, Mockito.mock(NetSocketInternal.class), null, new ProtonTransportOptions());
  conn.fireDisconnect();
  ProtonReceiver receiver = conn.createReceiver("address");

  AtomicBoolean drain1complete = new AtomicBoolean();

  receiver.setPrefetch(0);
  receiver.flow(1);
  receiver.drain(0, h -> {
    drain1complete.set(true);
  });

  try {
    receiver.flow(1);
    fail("should have thrown due to outstanding drain operation");
  } catch (IllegalStateException ise) {
    // Expected
    assertFalse("drain should not have been completed", drain1complete.get());
  }
}
 
Example #3
Source File: ProtonReceiverImplTest.java    From vertx-proton with Apache License 2.0 6 votes vote down vote up
@Test
public void testDrainWithExistingDrainOutstandingThrowsISE() {
  ProtonConnectionImpl conn = new ProtonConnectionImpl(null, null, null);
  conn.bindClient(null, Mockito.mock(NetSocketInternal.class), null, new ProtonTransportOptions());
  conn.fireDisconnect();
  ProtonReceiver receiver = conn.createReceiver("address");

  AtomicBoolean drain1complete = new AtomicBoolean();

  receiver.setPrefetch(0);
  receiver.flow(1);
  receiver.drain(0, h -> {
    drain1complete.set(true);
  });

  try {
    receiver.drain(0, h2-> {});
    fail("should have thrown due to outstanding drain operation");
  } catch (IllegalStateException ise) {
    // Expected
    assertFalse("first drain should not have been completed", drain1complete.get());
  }
}
 
Example #4
Source File: MqttServerImpl.java    From vertx-mqtt with Apache License 2.0 6 votes vote down vote up
@Override
public Future<MqttServer> listen(int port, String host) {
  Handler<MqttEndpoint> h1 = endpointHandler;
  Handler<Throwable> h2 = exceptionHandler;
  server.connectHandler(so -> {
    NetSocketInternal soi = (NetSocketInternal) so;
    ChannelPipeline pipeline = soi.channelHandlerContext().pipeline();

    initChannel(pipeline);
    MqttServerConnection conn = new MqttServerConnection(soi, options);

    soi.messageHandler(msg -> {
      synchronized (conn) {
        conn.handleMessage(msg);
      }
    });

    conn.init(h1, h2);

  });
  return server.listen(port, host).map(this);
}
 
Example #5
Source File: MSSQLConnectionFactory.java    From vertx-sql-client with Apache License 2.0 6 votes vote down vote up
public void doConnect(Promise<Connection> promise) {
  Future<NetSocket> fut = netClient.connect(port, host);
  fut.onComplete(ar -> {
    if (ar.succeeded()) {
      NetSocket so = ar.result();
      MSSQLSocketConnection conn = new MSSQLSocketConnection((NetSocketInternal) so, false, 0, sql -> true, 1, context);
      conn.init();
      conn.sendPreLoginMessage(false, preLogin -> {
        if (preLogin.succeeded()) {
          conn.sendLoginMessage(username, password, database, properties, promise);
        } else {
          promise.fail(preLogin.cause());
        }
      });
    } else {
      promise.fail(ar.cause());
    }
  });
}
 
Example #6
Source File: DB2SocketConnection.java    From vertx-sql-client with Apache License 2.0 5 votes vote down vote up
public DB2SocketConnection(NetSocketInternal socket,
    boolean cachePreparedStatements,
    int preparedStatementCacheSize,
    Predicate<String> preparedStatementCacheSqlFilter,
    int pipeliningLimit,
    ContextInternal context) {
  super(socket, cachePreparedStatements, preparedStatementCacheSize, preparedStatementCacheSqlFilter, pipeliningLimit, context);
}
 
Example #7
Source File: MSSQLSocketConnection.java    From vertx-sql-client with Apache License 2.0 5 votes vote down vote up
MSSQLSocketConnection(NetSocketInternal socket,
                      boolean cachePreparedStatements,
                      int preparedStatementCacheSize,
                      Predicate<String> preparedStatementCacheSqlFilter,
                      int pipeliningLimit,
                      ContextInternal context) {
  super(socket, cachePreparedStatements, preparedStatementCacheSize, preparedStatementCacheSqlFilter, pipeliningLimit, context);
}
 
Example #8
Source File: SocketConnectionBase.java    From vertx-sql-client with Apache License 2.0 5 votes vote down vote up
public SocketConnectionBase(NetSocketInternal socket,
                            boolean cachePreparedStatements,
                            int preparedStatementCacheSize,
                            Predicate<String> preparedStatementCacheSqlFilter,
                            int pipeliningLimit,
                            ContextInternal context) {
  this.socket = socket;
  this.context = context;
  this.pipeliningLimit = pipeliningLimit;
  this.paused = false;
  this.psCache = cachePreparedStatements ? new PreparedStatementCache(preparedStatementCacheSize) : null;
  this.preparedStatementCacheSqlFilter = preparedStatementCacheSqlFilter;
}
 
Example #9
Source File: MySQLSocketConnection.java    From vertx-sql-client with Apache License 2.0 5 votes vote down vote up
public MySQLSocketConnection(NetSocketInternal socket,
                             boolean cachePreparedStatements,
                             int preparedStatementCacheSize,
                             Predicate<String> preparedStatementCacheSqlFilter,
                             ContextInternal context) {
  super(socket, cachePreparedStatements, preparedStatementCacheSize, preparedStatementCacheSqlFilter, 1, context);
}
 
Example #10
Source File: MySQLConnectionFactory.java    From vertx-sql-client with Apache License 2.0 5 votes vote down vote up
private void doConnect(Promise<Connection> promise) {
  Future<NetSocket> fut = netClient.connect(port, host);
  fut.onComplete(ar -> {
    if (ar.succeeded()) {
      NetSocket so = ar.result();
      MySQLSocketConnection conn = new MySQLSocketConnection((NetSocketInternal) so, cachePreparedStatements, preparedStatementCacheSize, preparedStatementCacheSqlFilter, context);
      conn.init();
      conn.sendStartupMessage(username, password, database, collation, serverRsaPublicKey, connectionAttributes, sslMode, initialCapabilitiesFlags, charsetEncoding, promise);
    } else {
      promise.fail(ar.cause());
    }
  });
}
 
Example #11
Source File: DB2ConnectionFactory.java    From vertx-sql-client with Apache License 2.0 5 votes vote down vote up
public void doConnect(Promise<Connection> promise) {
  Future<NetSocket> fut = netClient.connect(port, host);
  fut.onComplete(ar -> {
    if (ar.succeeded()) {
      NetSocket so = ar.result();
      DB2SocketConnection conn = new DB2SocketConnection((NetSocketInternal) so, cachePreparedStatements,
          preparedStatementCacheSize, preparedStatementCacheSqlFilter, pipeliningLimit, context);
      conn.init();
      conn.sendStartupMessage(username, password, database, connectionAttributes, promise);
    } else {
      promise.fail(ar.cause());
    }
  });
}
 
Example #12
Source File: ProtonTransport.java    From vertx-proton with Apache License 2.0 5 votes vote down vote up
void flush() {
  boolean done = false;
  while (!done) {
    ByteBuffer outputBuffer = transport.getOutputBuffer();
    if (outputBuffer != null && outputBuffer.hasRemaining()) {
      final NetSocketInternal internal = (NetSocketInternal) socket;
      final ByteBuf bb = internal.channelHandlerContext().alloc().directBuffer(outputBuffer.remaining());
      bb.writeBytes(outputBuffer);
      internal.writeMessage(bb);
      transport.outputConsumed();
    } else {
      done = true;
    }
  }
}
 
Example #13
Source File: PgSocketConnection.java    From vertx-sql-client with Apache License 2.0 5 votes vote down vote up
public PgSocketConnection(NetSocketInternal socket,
                          boolean cachePreparedStatements,
                          int preparedStatementCacheSize,
                          Predicate<String> preparedStatementCacheSqlFilter,
                          int pipeliningLimit,
                          ContextInternal context) {
  super(socket, cachePreparedStatements, preparedStatementCacheSize, preparedStatementCacheSqlFilter, pipeliningLimit, context);
}
 
Example #14
Source File: SocketConnectionBase.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
public NetSocketInternal socket() {
  return socket;
}
 
Example #15
Source File: MqttClientImpl.java    From vertx-mqtt with Apache License 2.0 4 votes vote down vote up
private synchronized NetSocketInternal connection() {
  return connection;
}
 
Example #16
Source File: MqttServerConnection.java    From vertx-mqtt with Apache License 2.0 4 votes vote down vote up
public MqttServerConnection(NetSocketInternal so, MqttServerOptions options) {
  this.so = so;
  this.chctx = so.channelHandlerContext();
  this.options = options;
}
 
Example #17
Source File: PgConnectionFactory.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
private PgSocketConnection newSocketConnection(NetSocketInternal socket) {
  return new PgSocketConnection(socket, cachePreparedStatements, preparedStatementCacheSize, preparedStatementCacheSqlFilter, pipeliningLimit, context);
}
 
Example #18
Source File: MqttEndpointImpl.java    From vertx-mqtt with Apache License 2.0 3 votes vote down vote up
/**
 * Constructor
 *
 * @param conn                 connection instance with the remote MQTT client
 * @param clientIdentifier     client identifier of the remote
 * @param auth                 instance with the authentication information
 * @param will                 instance with the will information
 * @param isCleanSession       if the sessione should be cleaned or not
 * @param protocolVersion      protocol version required by the client
 * @param protocolName         protocol name sent by the client
 * @param keepAliveTimeoutSeconds keep alive timeout (in seconds)
 */
public MqttEndpointImpl(NetSocketInternal conn, String clientIdentifier, MqttAuth auth, MqttWill will, boolean isCleanSession, int protocolVersion, String protocolName, int keepAliveTimeoutSeconds) {
  this.conn = conn;
  this.clientIdentifier = clientIdentifier;
  this.auth = auth;
  this.will = will;
  this.isCleanSession = isCleanSession;
  this.protocolVersion = protocolVersion;
  this.protocolName = protocolName;
  this.keepAliveTimeoutSeconds = keepAliveTimeoutSeconds;
}