use of org.apache.ignite.internal.managers.systemview.walker.ClientConnectionViewWalker in project ignite by apache.
the class ClientListenerProcessor method start.
/**
* {@inheritDoc}
*/
@Override
public void start() throws IgniteCheckedException {
IgniteConfiguration cfg = ctx.config();
// Daemon node should not open client port
if (cfg.isDaemon()) {
if (log.isDebugEnabled())
log.debug("Client connection configuration ignored for daemon node.");
return;
}
ClientConnectorConfiguration cliConnCfg = prepareConfiguration(cfg);
if (cliConnCfg != null) {
try {
validateConfiguration(cliConnCfg);
// Resolve host.
String host = cliConnCfg.getHost();
if (host == null)
host = cfg.getLocalHost();
InetAddress hostAddr;
try {
hostAddr = U.resolveLocalHost(host);
} catch (Exception e) {
throw new IgniteCheckedException("Failed to resolve client connector host: " + host, e);
}
execSvc = ctx.pools().getThinClientExecutorService();
Exception lastErr = null;
int portTo = cliConnCfg.getPort() + cliConnCfg.getPortRange();
if (// Handle int overflow.
portTo <= 0)
portTo = Integer.MAX_VALUE;
GridNioFilter[] filters = makeFilters(cliConnCfg);
long idleTimeout = cliConnCfg.getIdleTimeout();
int selectorCnt = cliConnCfg.getSelectorCount();
ctx.metric().registry(CLIENT_CONNECTOR_METRICS);
for (int port = cliConnCfg.getPort(); port <= portTo && port <= 65535; port++) {
try {
srv = GridNioServer.<ClientMessage>builder().address(hostAddr).port(port).listener(new ClientListenerNioListener(ctx, busyLock, cliConnCfg)).logger(log).selectorCount(selectorCnt).igniteInstanceName(ctx.igniteInstanceName()).serverName("client-listener").tcpNoDelay(cliConnCfg.isTcpNoDelay()).directBuffer(DFLT_TCP_DIRECT_BUF).byteOrder(ByteOrder.nativeOrder()).socketSendBufferSize(cliConnCfg.getSocketSendBufferSize()).socketReceiveBufferSize(cliConnCfg.getSocketReceiveBufferSize()).filters(filters).directMode(true).idleTimeout(idleTimeout > 0 ? idleTimeout : Long.MAX_VALUE).metricRegistry(ctx.metric().registry(CLIENT_CONNECTOR_METRICS)).build();
ctx.ports().registerPort(port, IgnitePortProtocol.TCP, getClass());
if (log.isInfoEnabled())
log.info("Client connector processor has started on TCP port " + port);
lastErr = null;
ctx.addNodeAttribute(CLIENT_LISTENER_PORT, port);
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 [" + "host=" + host + ", portFrom=" + cliConnCfg.getPort() + ", portTo=" + portTo + ", lastErr=" + lastErr + ']', lastErr);
if (!U.IGNITE_MBEANS_DISABLED)
registerMBean();
ctx.systemView().registerView(CLI_CONN_VIEW, CLI_CONN_VIEW_DESC, new ClientConnectionViewWalker(), srv.sessions(), ClientConnectionView::new);
distrThinCfg = new DistributedThinClientConfiguration(ctx);
} catch (Exception e) {
throw new IgniteCheckedException("Failed to start client connector processor.", e);
}
}
}
Aggregations