Search in sources :

Example 1 with ClientMessageDecoder

use of org.apache.ignite.internal.client.proto.ClientMessageDecoder in project ignite-3 by apache.

the class ClientHandlerModule method startEndpoint.

/**
 * Starts the endpoint.
 *
 * @return Channel future.
 * @throws InterruptedException If thread has been interrupted during the start.
 * @throws IgniteException      When startup has failed.
 */
private ChannelFuture startEndpoint() throws InterruptedException {
    var configuration = registry.getConfiguration(ClientConnectorConfiguration.KEY).value();
    int desiredPort = configuration.port();
    int portRange = configuration.portRange();
    int port = 0;
    Channel ch = null;
    ServerBootstrap bootstrap = bootstrapFactory.createServerBootstrap();
    bootstrap.childHandler(new ChannelInitializer<>() {

        @Override
        protected void initChannel(Channel ch) {
            ch.pipeline().addLast(new ClientMessageDecoder(), new ClientInboundMessageHandler(igniteTables, igniteTransactions, queryProcessor));
        }
    }).option(ChannelOption.CONNECT_TIMEOUT_MILLIS, configuration.connectTimeout());
    for (int portCandidate = desiredPort; portCandidate <= desiredPort + portRange; portCandidate++) {
        ChannelFuture bindRes = bootstrap.bind(portCandidate).await();
        if (bindRes.isSuccess()) {
            ch = bindRes.channel();
            port = portCandidate;
            break;
        } else if (!(bindRes.cause() instanceof BindException)) {
            throw new IgniteException(bindRes.cause());
        }
    }
    if (ch == null) {
        String msg = "Cannot start thin client connector endpoint. " + "All ports in range [" + desiredPort + ", " + (desiredPort + portRange) + "] are in use.";
        LOG.error(msg);
        throw new IgniteException(msg);
    }
    LOG.info("Thin client protocol started successfully on port " + port);
    return ch.closeFuture();
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) ClientMessageDecoder(org.apache.ignite.internal.client.proto.ClientMessageDecoder) IgniteException(org.apache.ignite.lang.IgniteException) Channel(io.netty.channel.Channel) BindException(java.net.BindException) ChannelInitializer(io.netty.channel.ChannelInitializer) ServerBootstrap(io.netty.bootstrap.ServerBootstrap)

Aggregations

ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1 Channel (io.netty.channel.Channel)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelInitializer (io.netty.channel.ChannelInitializer)1 BindException (java.net.BindException)1 ClientMessageDecoder (org.apache.ignite.internal.client.proto.ClientMessageDecoder)1 IgniteException (org.apache.ignite.lang.IgniteException)1