Search in sources :

Example 1 with ClientConnectionViewWalker

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);
        }
    }
}
Also used : GridNioFilter(org.apache.ignite.internal.util.nio.GridNioFilter) ClientConnectionView(org.apache.ignite.spi.systemview.view.ClientConnectionView) DistributedThinClientConfiguration(org.apache.ignite.internal.processors.configuration.distributed.DistributedThinClientConfiguration) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) JMException(javax.management.JMException) ClientConnectionViewWalker(org.apache.ignite.internal.managers.systemview.walker.ClientConnectionViewWalker) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ClientConnectorConfiguration(org.apache.ignite.configuration.ClientConnectorConfiguration) InetAddress(java.net.InetAddress)

Aggregations

InetAddress (java.net.InetAddress)1 JMException (javax.management.JMException)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 ClientConnectorConfiguration (org.apache.ignite.configuration.ClientConnectorConfiguration)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 ClientConnectionViewWalker (org.apache.ignite.internal.managers.systemview.walker.ClientConnectionViewWalker)1 DistributedThinClientConfiguration (org.apache.ignite.internal.processors.configuration.distributed.DistributedThinClientConfiguration)1 GridNioFilter (org.apache.ignite.internal.util.nio.GridNioFilter)1 ClientConnectionView (org.apache.ignite.spi.systemview.view.ClientConnectionView)1