use of org.apache.ignite.internal.util.HostAndPortRange in project ignite by apache.
the class SqlListenerProcessor method start.
/** {@inheritDoc} */
@Override
public void start(boolean activeOnStart) throws IgniteCheckedException {
IgniteConfiguration cfg = ctx.config();
OdbcConfiguration odbcCfg = cfg.getOdbcConfiguration();
if (odbcCfg != null) {
try {
HostAndPortRange hostPort;
if (F.isEmpty(odbcCfg.getEndpointAddress())) {
hostPort = new HostAndPortRange(OdbcConfiguration.DFLT_TCP_HOST, OdbcConfiguration.DFLT_TCP_PORT_FROM, OdbcConfiguration.DFLT_TCP_PORT_TO);
} else {
hostPort = HostAndPortRange.parse(odbcCfg.getEndpointAddress(), OdbcConfiguration.DFLT_TCP_PORT_FROM, OdbcConfiguration.DFLT_TCP_PORT_TO, "Failed to parse ODBC endpoint address");
}
assertParameter(odbcCfg.getThreadPoolSize() > 0, "threadPoolSize > 0");
odbcExecSvc = new IgniteThreadPoolExecutor("odbc", cfg.getIgniteInstanceName(), odbcCfg.getThreadPoolSize(), odbcCfg.getThreadPoolSize(), 0, new LinkedBlockingQueue<Runnable>());
InetAddress host;
try {
host = InetAddress.getByName(hostPort.host());
} catch (Exception e) {
throw new IgniteCheckedException("Failed to resolve ODBC host: " + hostPort.host(), e);
}
Exception lastErr = null;
for (int port = hostPort.portFrom(); port <= hostPort.portTo(); port++) {
try {
GridNioFilter[] filters = new GridNioFilter[] { new GridNioAsyncNotifyFilter(ctx.igniteInstanceName(), odbcExecSvc, log) {
@Override
public void onSessionOpened(GridNioSession ses) throws IgniteCheckedException {
proceedSessionOpened(ses);
}
}, new GridNioCodecFilter(new SqlListenerBufferedParser(), log, false) };
GridNioServer<byte[]> srv0 = GridNioServer.<byte[]>builder().address(host).port(port).listener(new SqlListenerNioListener(ctx, busyLock, odbcCfg.getMaxOpenCursors())).logger(log).selectorCount(DFLT_SELECTOR_CNT).igniteInstanceName(ctx.igniteInstanceName()).serverName("odbc").tcpNoDelay(DFLT_TCP_NODELAY).directBuffer(DFLT_TCP_DIRECT_BUF).byteOrder(ByteOrder.nativeOrder()).socketSendBufferSize(odbcCfg.getSocketSendBufferSize()).socketReceiveBufferSize(odbcCfg.getSocketReceiveBufferSize()).filters(filters).directMode(false).idleTimeout(Long.MAX_VALUE).build();
srv0.start();
srv = srv0;
ctx.ports().registerPort(port, IgnitePortProtocol.TCP, getClass());
log.info("ODBC processor has started on TCP port " + port);
lastErr = null;
break;
} catch (Exception e) {
lastErr = e;
}
}
assert (srv != null && lastErr == null) || (srv == null && lastErr != null);
if (lastErr != null)
throw new IgniteCheckedException("Failed to bind to any [host:port] from the range [" + "address=" + hostPort + ", lastErr=" + lastErr + ']');
} catch (Exception e) {
throw new IgniteCheckedException("Failed to start ODBC processor.", e);
}
}
}
Aggregations