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();
}
Aggregations