Search in sources :

Example 1 with IpcClientTcpEndpoint

use of org.apache.ignite.internal.util.ipc.loopback.IpcClientTcpEndpoint in project ignite by apache.

the class JdbcThinTcpIo method start.

/**
     * @throws IgniteCheckedException On error.
     * @throws IOException On IO error in handshake.
     */
public void start() throws IgniteCheckedException, IOException {
    Socket sock = new Socket();
    if (sockSndBuf != 0)
        sock.setSendBufferSize(sockSndBuf);
    if (sockRcvBuf != 0)
        sock.setReceiveBufferSize(sockRcvBuf);
    sock.setTcpNoDelay(tcpNoDelay);
    try {
        sock.connect(new InetSocketAddress(host, port));
    } catch (IOException e) {
        throw new IgniteCheckedException("Failed to connect to server [host=" + host + ", port=" + port + ']', e);
    }
    endpoint = new IpcClientTcpEndpoint(sock);
    out = new BufferedOutputStream(endpoint.outputStream());
    in = new BufferedInputStream(endpoint.inputStream());
    handshake();
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) BufferedInputStream(java.io.BufferedInputStream) InetSocketAddress(java.net.InetSocketAddress) IpcClientTcpEndpoint(org.apache.ignite.internal.util.ipc.loopback.IpcClientTcpEndpoint) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) Socket(java.net.Socket)

Example 2 with IpcClientTcpEndpoint

use of org.apache.ignite.internal.util.ipc.loopback.IpcClientTcpEndpoint in project ignite by apache.

the class JdbcThinTcpIo method connect.

/**
 * Connect to host.
 *
 * @param addr Address.
 * @param timeout Socket connection timeout in ms.
 * @throws IOException On IO error.
 * @throws SQLException On connection reject.
 */
private void connect(InetSocketAddress addr, int timeout) throws IOException, SQLException {
    Socket sock;
    if (ConnectionProperties.SSL_MODE_REQUIRE.equalsIgnoreCase(connProps.getSslMode()))
        sock = JdbcThinSSLUtil.createSSLSocket(addr, connProps);
    else if (ConnectionProperties.SSL_MODE_DISABLE.equalsIgnoreCase(connProps.getSslMode())) {
        sock = new Socket();
        try {
            sock.connect(addr, timeout);
        } catch (IOException e) {
            throw new SQLException("Failed to connect to server [host=" + addr.getHostName() + ", port=" + addr.getPort() + ']', SqlStateCode.CLIENT_CONNECTION_FAILED, e);
        }
    } else {
        throw new SQLException("Unknown sslMode. [sslMode=" + connProps.getSslMode() + ']', SqlStateCode.CLIENT_CONNECTION_FAILED);
    }
    if (connProps.getSocketSendBuffer() != 0)
        sock.setSendBufferSize(connProps.getSocketSendBuffer());
    if (connProps.getSocketReceiveBuffer() != 0)
        sock.setReceiveBufferSize(connProps.getSocketReceiveBuffer());
    sock.setTcpNoDelay(connProps.isTcpNoDelay());
    try {
        endpoint = new IpcClientTcpEndpoint(sock);
        out = new BufferedOutputStream(endpoint.outputStream());
        in = new BufferedInputStream(endpoint.inputStream());
    } catch (IgniteCheckedException e) {
        throw new SQLException("Failed to connect to server [url=" + connProps.getUrl() + ']', SqlStateCode.CLIENT_CONNECTION_FAILED, e);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SQLException(java.sql.SQLException) BufferedInputStream(java.io.BufferedInputStream) IpcClientTcpEndpoint(org.apache.ignite.internal.util.ipc.loopback.IpcClientTcpEndpoint) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) Socket(java.net.Socket)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)2 BufferedOutputStream (java.io.BufferedOutputStream)2 IOException (java.io.IOException)2 Socket (java.net.Socket)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IpcClientTcpEndpoint (org.apache.ignite.internal.util.ipc.loopback.IpcClientTcpEndpoint)2 InetSocketAddress (java.net.InetSocketAddress)1 SQLException (java.sql.SQLException)1